函数为什么返回值t = 13.214
,但是print(..., digits = 3)
返回t = 10
?
vals <- data.frame(a = c(4, 2, 4, 7, 3, 4, 8, 8, 3, 0, 1, 5, 4, 6, 4, 8, 7, 9, 6, 6, 3, 6, 7, 4),
b = c(5, 7, 6, 13, 12, 6, 14, 16, 4, 2, 7, 7, 4, 8, 9, 9, 11, 13, 12, 8, 3, 8, 7, 7))
stats::t.test(x = vals)
# One Sample t-test
# data: vals
# t = 13.214, df = 47, p-value < 2.2e-16
# alternative hypothesis: true mean is not equal to 0
# 95 percent confidence interval:
# 5.598761 7.609572
# sample estimates:
# mean of x
# 6.604167
print(stats::t.test(x = vals), digits = 3)
形式?print
:
digits:最小有效数字,请参阅print.default。
但这不应该将10更改为13吗?
软件包``stats''版本3.5.1
R.version
平台x86_64-w64-mingw32
arch x86_64
os mingw32
系统x86_64,mingw32
status
主要3
次要5.1
年2018年
07月02
日02
svn rev 74947
语言R
版本.string R版本3.5.1( 2018-07-02)绰号Feather Spray
回答这些问题的第一步始终是弄清楚我们正在处理哪种打印方法。中的通用帮助?print
不一定非常相关。t.test对象具有类htest
,因此我们来看一下print.htest
。
请注意,这?print.htest
会将您带到稍微更具体的文档页面。的文档digits
未说明任何具体内容,但是在“详细信息”部分中,我们看到:
传统上,这两种打印方法都没有正确地遵守digits参数。他们现在这样做了,htest方法主要在诸如max(1,digits-2)之类的表达式中进行。
(在R 3.5.2中)
例如,在功能代码中,我们看到以下内容:
out <- c(out, paste(names(x$statistic), "=", format(signif(x$statistic,
max(1L, digits - 2L)))))
的默认值digits
通常为7。它digits
用于打印样本估计值和置信区间,而其他数量的位数更少。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句