我有一张这样的表:
1 2 3 4 5
10 22 15 14 3
15 44 22 26 9
...more rows
我想在单行测试中运行,看看它的平均值是否小于3似乎是合理的。使用t.test(table [x,])不起作用,因为它假设我感兴趣在行中的值的平均值,我不是:值只是表示每个值的响应数,范围为1-5。
怎么办?
答案 0 :(得分:1)
您可以使用以下方法:
apply(data, 1, function(data) {t.test( rep(1:5, times = data), alternative = "less", mu = 3)})
将返回每行的t检验,例如:
[[1]]
One Sample t-test
data: rep(1:5, times = data)
t = -2.4337, df = 63, p-value = 0.008896
alternative hypothesis: true mean is less than 3
95 percent confidence interval:
-Inf 2.892043
sample estimates:
mean of x
2.65625
[[2]]
One Sample t-test
data: rep(1:5, times = data)
t = -2.3745, df = 115, p-value = 0.009613
alternative hypothesis: true mean is less than 3
95 percent confidence interval:
-Inf 2.921981
sample estimates:
mean of x
2.741379
如果您只想要p值,请添加$p.value
:
apply(data, 1, function(data) {t.test( rep(1:5, times = data), alternative = "less", mu = 3)$p.value})
[1] 0.008895887 0.009613075