【发布时间】:2022-10-17 02:28:04
【问题描述】:
我想在第 2 列和第 3 列、第 4 列和第 5 列、第 6 列和第 7 列之间执行自动配对 t 检验,依此类推。当我使用下面的代码时,我可以执行 t 检验,但不能执行未配对的 t 检验。
数据:
patient weight_1 weight_2 BMI_1 BMI_2 chol_1 chol_2 gly_1 gly_2
1 A 86.0 97.0 34.44961 30.61482 86.0 97.0 34.44961 30.61482
2 B 111.0 55.5 33.51045 22.80572 111.0 55.5 33.51045 22.80572
3 C 92.4 70.0 28.51852 25.71166 92.4 70.0 28.51852 25.71166
代码:
names <- colnames(dataframe)
for(i in seq(from = 2, to = 8, by = 2)){
print(names[i])
print(names[i+1])
print(t.test(dataframe[i], dataframe[i+1]))
}
输出:
[1]“重量_1” [1]“重量_2”
Welch Two Sample t-test
data: dataframe[i] and dataframe[i + 1]
t = 1.3183, df = 75.892, p-value = 0.1914
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-2.459965 12.090735
sample estimates:
mean of x mean of y
91.50256 86.68718
[1] "BMI_1"
[1] "BMI_2"
Welch Two Sample t-test
data: dataframe[i] and dataframe[i + 1]
t = 1.5851, df = 75.866, p-value = 0.1171
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.3817027 3.3571650
sample estimates:
mean of x mean of y
30.45167 28.96394
等等。当我将paired=TRUE 添加到数据中时:
names <- colnames(dataframe)
for(i in seq(from = 2, to = 8, by = 2)){
print(names[i])
print(names[i+1])
print(t.test(dataframe[i], dataframe[i+1]), paired=TRUE)
}
结果完全一样,好像不包括配对函数一样。有人可以帮我解决这个问题吗?提前谢谢了。
【问题讨论】: