如何估算功率函数之间的最大差异? (CLT测试的功效和二项式测试的功效,n = 40)
power.z = function(mu,n) {
power = 1 - pnorm( 1.645 - (mu - 75)/(2.5/sqrt(n)) , 0, 1)
return(power)
}
power.bin = function(mu,n) {
p = 1 - pnorm(75, mu, 2.5)
power = 1 - pnorm( 1.645*sqrt(.25/(p*(1-p))) - (p-.5)/sqrt(p*(1-p)/n), 0, 1)
return(power)
}
power.z(75.8, 40) ## 0.6476032
power.bin(75.8, 40) ## 0.4763833
答案 0 :(得分:2)
以下是基于@Khashaa建议的解决方案:
power.z = function(mu,n) {
power = 1 - pnorm( 1.645 - (mu - 75)/(2.5/sqrt(n)) , 0, 1)
return(power)
}
power.bin = function(mu,n) {
p = 1 - pnorm(75, mu, 2.5)
power = 1 - pnorm( 1.645*sqrt(.25/(p*(1-p))) - (p-.5)/sqrt(p*(1-p)/n), 0, 1)
return(power)
}
fnDiffZBin = function(mu, n) abs(power.z(mu, n) - power.bin(mu, n))
optimize(fnDiffZBin, interval = c(75, 80), n = 40, maximum = TRUE)
给出:
> optimize(fnDiffZBin, interval = c(75, 80), n = 40, maximum = TRUE)
$maximum
[1] 75.68248
$objective
[1] 0.1755956