[英]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.