如何将行追加到t.test()的公式摘要的输出中

  • 本文关键字:输出 追加 test r
  • 更新时间 :
  • 英文 :


我想在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 

最新更新