t检验与方差分析的区别

一、同:

1.原理:

自变量不同产生的差异/随机因素产生的差异,来检验这个自变量不同产生的差异是否足够大到,可以结论说这个自变量对因变量有显著影响。

2.检验显著性

t^2 = F

二、异:

t.test F.test
1.indication 2组的均值比较 2组及以上的比较
方差齐(组内差异相等) 组内差异&组间差异
小样本(n<30)
当比较方差齐的两组均值时,P(t.test)=P(F.test)
2. methods (组1均值-组2均值)/ 方差 求和(每组均值-总均值)/求和(每个值-组内均值)
1.独立样本T检验,2.配对样本T检验,3.单样本T检验 1.单因素(一组多变量),2.多因素

知乎大佬说

三、一个例子

当比较方差齐的两组时,P(t.test)=P(F.test) CSDN

#1.两组数据,方差齐
weight<-scan()
16.68 20.67 18.42 18 17.44 15.95 18.68 23.22 21.42 19 18.92 NA
V<-rep(c('LY1','DXY'),rep(6,2))
df<-data.frame(V,weight)
a<-subset(df$weight,V=='LY1')
b<-subset(df$weight,V=='DXY')

var.test(a,b) #检验是否方差齐
#p-value =0.6653,,接受H0,方差齐
#{

    F test to compare two variances

data:  a and b
F = 0.6729, num df = 5, denom df = 4, p-value =
0.6653
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 0.07185621 4.97127448
sample estimates:
ratio of variances 
         0.6728954 
         }


t.test(a,b,var.equal=T,paired = F)
#p-value = 0.0571
#{  Two Sample t-test

data:  a and b
t = -2.1808, df = 9, p-value = 0.0571
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -4.86513222  0.08913222
sample estimates:
mean of x mean of y 
   17.860    20.248 
}

fit<-aov(weight~V,data=df)
summary(fit)
#p-value = 0.0571
#t^2=(-2.1808)^2 = F=4.756
#{
                Df Sum Sq Mean Sq F value Pr(>F)  
V            1  15.55   15.55   4.756 0.0571 .
Residuals    9  29.43    3.27                 
---
Signif. codes:  
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
1 observation deleted due to missingness
}


#2.两组数据,方差不齐
weight<-scan()
16.68 20.67 18.42 18 17.44 30 18.68 23.22 21.42 19 18.92 82
V<-rep(c('LY1','DXY'),rep(6,2))
df<-data.frame(V,weight)
a<-subset(df$weight,V=='LY1')
b<-subset(df$weight,V=='DXY')

var.test(a,b) 
#p-value= 0.002832,方差不齐
#{
        F test to compare two variances

data:  a and b
F = 0.038913, num df = 5, denom df = 5, p-value
= 0.002832
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 0.005445095 0.278085194
sample estimates:
ratio of variances 
        0.03891273 
}

t.test(a,b,var.equal=T,paired = F)
#p-value = 0.3488
#{
    Two Sample t-test

data:  a and b
t = -0.98304, df = 10, p-value = 0.3488
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -33.77097  13.09431
sample estimates:
mean of x mean of y 
 20.20167  30.54000 
}

t.test(a,b,var.equal=F,paired = F) #Welch法,校正方差不齐
#p-value = 0.3676
#{
Welch Two Sample t-test

data:  a and b
t = -0.98304, df = 5.3885, p-value = 0.3676
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -36.79643  16.11976
sample estimates:
mean of x mean of y 
 20.20167  30.54000 
}

fit<-aov(weight~V,data=df)
summary(fit)
#p-value = 0.349
#{
                Df Sum Sq Mean Sq F value Pr(>F)
V            1    321   320.6   0.966  0.349
Residuals   10   3318   331.8      
}


你可能感兴趣的:(t检验与方差分析的区别)