繁体   English   中英

通过 binom.test 或 prop.test 获得相同答案的方法

[英]The way to get the same answer by binom.test or prop.test

对于以下问题,我想通过 R 中的 binom.test 或 prop.test 得到相同的答案。 如何获得与手动计算相同的答案(0.009903076)?

n=475, H0:p=0.05, H1:p>0.05 phat>0.0733的概率是多少?

n <- 475
p0 <- 0.05
p <- 0.0733
(z <- (p - p0)/sqrt(p0*(1 - p0)/n))
# [1] 2.33
(ans <- 1 - pnorm(z))
# [1] 0.009903076

你可以从prop.test()得到这个:

prop.test(n*p, n, p0, alternative="greater", correct=FALSE)
# data:  n * p out of n, null probability p0
# X-squared = 5.4289, df = 1, p-value = 0.009903
# alternative hypothesis: true p is greater than 0.05
# 95 percent confidence interval:
# 0.05595424 1.00000000
# sample estimates:
#     p 
# 0.0733 
# 

据我所知,您无法从binom.test()获得结果,因为n*p不是 integer,而是 34.8175。 The binom.test() function only takes an integer values number of successes, so when you convert this to 35 by rounding, p effectively becomes 0.07368421, which makes the rest of your results not match. 即使您遇到n*p是 integer 的情况, binom.test()仍然不会产生相同的答案,因为它没有像原始代码那样使用正态近似值 - 它使用二项式分布来计算p0以上的概率.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM