t.test中的自由度

时间:2017-10-28 15:07:39

标签: r

计算公式(n-1)中的自由度与t.test中执行的自由度之间有什么区别?

例如: 我有两个小组1.(1.7,1,1)2.(1.5,1,1)

df = 4 (n-1)
-----------------
df in t.test = 2.9186
t = -9.1357, df = 2.9186, p-value = 0.003092
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -6.611410 -3.154978
sample estimates:
mean of x mean of y 
 1.236430  6.119624 

为什么他们不同?

1 个答案:

答案 0 :(得分:0)

这取决于方差是否相等的假设

t.test(v1, v2, var.equal = TRUE)
 Two Sample t-test

data:  v1 and v2
t = 0.2325, df = 4, p-value = 0.8276
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -0.7294628  0.8627961
sample estimates:
mean of x mean of y 
 1.233333  1.166667 

默认情况下,它使用var.equal = FALSE

t.test(v1, v2)
 Welch Two Sample t-test

data:  v1 and v2
t = 0.2325, df = 3.6193, p-value = 0.8287
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -0.7636018  0.8969351
sample estimates:
mean of x mean of y 
 1.233333  1.166667 

并使用'Welch'调整来计算自由度数

数据

v1 <- c(1.7, 1, 1)
v2 <- c(1.5, 1, 1)