繁体   English   中英

如何计算两个 50 个数据点向量之间的逐点 t 检验?

[英]How do I compute point-by-point t tests between two 50 data point vectors?

我有一个包含 3 个变量和 50 个实例(ID、pre 和 post)的数据框。有点像这样

ID<- c("1","2","3","4","5","6","7","8","9","10")
pre<- c("2.56802","2.6686","1.0145","0.2568","2.369","1.2365","0.6989","0.98745","1.09878","2.454658")
post<-c("3.3323","2.66989","1.565656","2.58989","5.96987","3.12145","1.23565","2.74741","2.54101","0.23568")

dfw1<-data.frame(ID,pre,post)

前后列是其他总体的平均值。 我想在前和后的第一个元素之间运行双尾 t 检验。(前对后)。 我希望它遍历所有 50 行。 我尝试编写如下所示的循环,

t<-0
for (i in 1:nrow(dfw$ID)) {
  t[i]<-t.test(dfw$pre,dfw$post,alternative = c("two.sided"), conf.level = 0.95)
  print(t)
}

它返回了一个错误,我想提取上面的统计信息,例如每行的 df、p 值、t 值等等。 我如何在 R 中编写此代码?

此代码显示您不能在传统的 5% 置信水平下拒绝 0 差异的原假设:

ID<- c("1","2","3","4","5","6","7","8","9","10")
pre<- as.numeric(c("2.56802","2.6686","1.0145","0.2568","2.369","1.2365","0.6989","0.98745","1.09878","2.454658"))
post<-as.numeric(c("3.3323","2.66989","1.565656","2.58989","5.96987","3.12145","1.23565","2.74741","2.54101","0.23568"))
dfw1<-data.frame(ID,pre,post)
t.test(dfw1$pre,dfw1$post,alternative = c("two.sided"), conf.level = 0.95, paired=TRUE)

输出(给你 df、t-stat 和 p 值):

Paired t-test

data:  dfw1$pre and dfw1$post
t = -2.1608, df = 9, p-value = 0.05899
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -2.18109315  0.04997355
sample estimates:
mean of the differences 
               -1.06556

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM