我有一个31个值的样本数据集。我使用R进行了两尾t检验,以检验真实均值是否等于10:
t.test(x=data, mu=10, conf.level=0.95)
输出:
t = 11.244, df = 30, p-value = 2.786e-12
alternative hypothesis: true mean is not equal to 10
95 percent confidence interval:
19.18980 23.26907
sample estimates:
mean of x
21.22944
现在,我正在尝试手动执行相同的操作:
t.value = (mean(data) - 10) / (sd(data) / sqrt(length(data)))
p.value = dt(t.value, df=length(lengths-1))
使用此方法计算的t值与t检验R函数的输出相同。但是,p值为3.025803e-12。
有什么想法我做错了吗?
谢谢!
编辑
这是完整的R代码,包括我的数据集:
# Raw dataset -- 32 observations
data = c(21.75, 18.0875, 18.75, 23.5, 14.125, 16.75, 11.125, 11.125, 14.875, 15.5, 20.875,
17.125, 19.075, 25.125, 27.75, 29.825, 17.825, 28.375, 22.625, 28.75, 27, 12.825,
26, 32.825, 25.375, 24.825, 25.825, 15.625, 26.825, 24.625, 26.625, 19.625)
# Student t-Test
t.test(x=data, mu=10, conf.level=0.95)
# Manually calculate p-value
t.value = (mean(data) - 10) / (sd(data) / sqrt(length(data)))
p.value = dt(t.value, df=length(data) - 1)