我想在t测试函数的输出中向摘要添加详细信息
这是的一个例子
library(fpp)
t.test(savings ~ single,
data = credit)
我想在95CI
的输出中添加重命名95 percent confidence interval:
我还想编辑var.test
输出
1(使用capture.output
:
out <- capture.output(t.test(savings ~ single, credit))
cat(sub("95 percent confidence interval:" , "95CI:", out), sep = "n")
给予:
Welch Two Sample t-test
data: savings by single
t = 1.4651, df = 164.99, p-value = 0.1448
alternative hypothesis: true difference in means is not equal to 0
95CI:
-0.341452 2.305789
sample estimates:
mean in group FALSE mean in group TRUE
2.761500 1.779332
2(这也可以,但会重新排列输出,将CI放在最后。
tt <- t.test(savings ~ single, credit)
replace(tt, "conf.int", NULL); cat("95CI:n", tt$conf.int, "n")
给予:
Welch Two Sample t-test
data: savings by single
t = 1.4651, df = 164.99, p-value = 0.1448
alternative hypothesis: true difference in means is not equal to 0
sample estimates:
mean in group FALSE mean in group TRUE
2.761500 1.779332
95CI:
-0.341452 2.305789