【问题标题】:prop.test display the confidence interval in percentage terms instead of decimal in R?prop.test 以百分比而不是 R 中的小数显示置信区间?
【发布时间】:2020-05-29 04:43:34
【问题描述】:

我想知道是否有一种方法可以更改 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%] 而不是小数?谢谢!

【问题讨论】:

  • 很容易编写自己的包装函数。

标签: r testing confidence-interval


【解决方案1】:

这可能会更简单:

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 

【讨论】:

  • 请注意,估计仍然是一个比例,因此您可能需要添加prp.out$estimate &lt;- prp.out$estimate * 100
【解决方案2】:

不容易。打印格式由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*100

【讨论】:

  • 我建议只编写一个包装器 myprop.test 与输出列表元素混淆,而不是冒险破坏原始函数代码中的重要内容。
  • 好吧,卡尔听起来是个好主意。谢谢!您如何建议设置该包装器?我试过这样的东西,但不确定.. my.prop.test
猜你喜欢
  • 2018-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-07
  • 2023-02-08
  • 2019-03-12
  • 1970-01-01
  • 2015-03-17
相关资源
最近更新 更多