我想知道是否有一种方法可以改变R中prop.test函数的输出设置,这样它就可以用百分比而不是十进制来显示置信区间了吗?例如,我正试图找出西方糖尿病移民比例95%的置信区间。下面是我的代码和输出:
sum(Immigrant_West$DIABETES)= 8, nrow(Immigrant_West)=144
prop.test(x=sum(Immigrant_West$DIABETES),n=nrow(Immigrant_West),conf.level = .95,correct=TRUE)
> 1-sample proportions test with continuity correction
data: sum(Immigrant_West$DIABETES) out of nrow(Immigrant_West), null probability 0.5
X-squared = 112, df = 1, p-value <2e-16
alternative hypothesis: true p is not equal to 0.5
95 percent confidence interval:
0.02606 0.11017
sample estimates:
p
0.05556 那么,是否有办法将置信区间输出改变为2.606%,11.017%,而不是小数?谢谢!
发布于 2020-05-28 20:01:19
这可能会更简单:
prp.out <- prop.test(x=8, n=144, conf.level=.95, correct=TRUE)
prp.out$conf.int <- prp.out$conf.int * 100
prp.out
#
# 1-sample proportions test with continuity correction
#
# data: 8 out of 144, null probability 0.5
# X-squared = 112.01, df = 1, p-value < 2.2e-16
# alternative hypothesis: true p is not equal to 0.5
# 95 percent confidence interval:
# 2.606172 11.016593
# sample estimates:
# p
# 0.05555556 发布于 2020-05-28 18:31:47
不容易。打印格式由print.htest()函数控制,该函数在?print.htest中有文档:它似乎不提供任何选项,只提供数字数和“方法”组件的前缀。
如果你愿意,你可以自己破解这个函数。(接下来可能会有更多的细节;将stats:::print.htest转储到一个文件中,然后编辑它,然后source()它)。
@CarlWitthoft建议:
p <- prop.test(x=8,n=144)
str(p) ## see what's there
p$estimate <- p$estimate*100
p$conf.int <- p$conf.int*100https://stackoverflow.com/questions/62071911
复制相似问题