背景:
工作中的一个小组正在抽样 1,000 名客户进行联系,并从那时起确定这种努力是否值得。我想看看这个(几乎)任意样本大小值是否“足够好”。
如果我们假设总体中成功的真实比例是 0.016(1.6%),我需要多大的样本量才能获得 0.005(0.5%)的置信区间误差“半宽度”) ? 这是我在 R 中的方法:
install.packages("Hmisc")
library(Hmisc)
target.halfWidth <- 0.005
sims <- 25000 #number of draws from binomial to perform
p <- 0.016 #true proportion
n <- seq(from=500, to=5000, by=100) #number of samples
#hold results
results <- matrix(numeric(0), length(n),2)
#loop through desired sample size options
for (i in 1: length(n))
{
x <- rbinom(sims, n[i], p) #draws from binomial with p and n
ci <- binconf(x, n[i] ,method="asymptotic", alpha=0.1) #normal theory 90% CI
half_width <- ci[,3]-ci[, 1] #half width of CI
#need the number where the half width is within the target range
prob.halfWidth <- length(half_width[half_width<target.halfWidth])/sims
#store results
results[i, 1] <- n[i]
results[i, 2] <- prob.halfWidth
}
#plot
plot(results[, 2], results[, 1], type="b")
results
该模拟表明,我们需要 2,200 个样本才能有 95% 的置信度,即 90% CI 最多为 0.005。
问题:
这是一个合适的方法吗?
有没有更好的方法?
如果有一些亚群的有限样本,你能给出什么建议?假设我们想知道在没有“很多”客户可供选择的人群中抽取多少样本。或许某个群体只有5000人,比起一个有50000人可供选择的群体,我们难道不能少拿几个来做决定吗?
在 MansT 回答后添加:
这有意义吗,在我的模拟场景下,添加一个步骤:
prob.halfWidth <- 长度(half_width [half_width
仅当生成的 CI 还包含真实 p(即 0.016)时才增加分子?
在您的代码下,在处理有限样本时将有限总体校正器FPC添加到您的行中是否也合适:
halfWidth <- qnorm(0.95) sqrt(p.est (1-p.est)/n)
我不确定超几何的 CI 公式,但也许我可以替换我的代码行
ci <- binconf(x,n[i],method="asymptotic",alpha=0.1) #正常理论 90% CI
R中的Sprop函数?