三:两独立样本 t t t检验
前文介绍了有关
t
t
t检验的相关知识。
在实际运用中,两独立样本的
t
t
t检验是运用较为广泛的。
1、数据准备
这里使用iris3数据集,这是一个三位数组,我们将使用iris3[,1,1]和iris3[,2,1]进行分析。
2、 t t t检验要求
总的来说, t t t检验要求两组数据满足:
- 正态性
> shapiro.test(iris3[,1,1])
Shapiro-Wilk normality test
data: iris3[, 1, 1]
W = 0.9777, p-value = 0.4595
> shapiro.test(iris3[,2,1])
Shapiro-Wilk normality test
data: iris3[, 2, 1]
W = 0.97172, p-value = 0.2715 #p值大于0.05,服从正态分布
-
独立性
两样本满足独立性 -
方差齐性
数据满足正态分布,我们可以选用var方差齐性检验
> var.test(iris3[,1,1],iris3[,2,1])
F test to compare two variances
data: iris3[, 1, 1] and iris3[, 2, 1]
F = 0.8647, num df = 49, denom df = 49, p-value = 0.6129
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.4906983 1.5237695
sample estimates:
ratio of variances
0.8647029
p值大于0.05,表明方差齐性
3、 t t t检验
使用t.test()
进行
t
t
t检验:
> t.test(iris3[,1,1],iris3[,2,1])
Welch Two Sample t-test
data: iris3[, 1, 1] and iris3[, 2, 1]
t = 21.556, df = 97.487, p-value < 2.2e-16
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
1.43272 1.72328
sample estimates:
mean of x mean of y
5.006 3.428
p值小于0.05,拒绝原假设,两样本存在差异
(结果毋庸置疑,花萼的长度和宽度肯定不一样)