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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何计算两个50个数据点向量之间的逐点t检验?相关的知识,希望对你有一定的参考价值。

我有一个包含3个变量和50个实例(ID,前置和后置)的数据框。有点像这样

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)

前后列是其他人口的平均值。我想在pre和post的第一个元素之间运行双尾t检验。(pre pre post)。我希望这循环遍历所有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

以上是关于如何计算两个50个数据点向量之间的逐点t检验?的主要内容,如果未能解决你的问题,请参考以下文章

如何获得 smooth.spline 的置信区间?

如何迭代计算 t 检验的 p 值

如何使用线性感知器中的权重向量绘制一条线? [关闭]

T统计量(T-statistic)和T检验(T-test)是一回事吗?如何不是,它们之间有啥关系?

t检验的原理是啥?有啥意义?谢谢

matlab做回归分析时,能做t检验吗?