我需要比较 Wilcoxon 检验和零假设的符号检验之间的功效:Theta=0 和替代假设:Theta>0。数据来自随机正态分布,n=20 和 mu=0。
我尝试了以下代码来完成我的任务,但我不知道它是否正确,因为我获得的情节有点奇怪。
### NULL HYPOTHESIS: Theta=0 ###
n_x=200 # Sample size under Null Hypothesis
mu_x=0 # Sample mean under Null Hypothesis
sigma_x=3 # Sample deviation under Null Hypotesis
### ALTERNATIVE HYPOTHESIS: Theta>0 ###
tmu_y=100 # Number of means under Alternative Hypothesis
mu_y=seq(-2, 2, length=tmu_y) # Means under Alternative Hypothesis
sigma_y=3 # Deviation under Alternative Hypothesis
prob_rechazo_wilcoxon=NULL # Power of Wilcoxon Test
prob_rechazo_stest=NULL # Power of Sign Test
tsim=1000 # Simulation size
for (j in 1: tmu_y)
{
valorP_stest=NULL # P value Sign Test
valorP_wilcoxon=NULL # P value Wilcoxon Test
for (i in 1:tsim)
{
x=rnorm(n_x, mu_x, sigma_x)
stest=SIGN.test(x, y=NULL, alternative = "less", md = 0, conf.level = 0.95)
valorP_stest[i]=stest$p.value
wtest=wilcox.test(x, y=NULL, alternative = "less", mu = 0, conf.level = 0.95)
valorP_wilcoxon[i]=wtest$p.value
}
prob_rechazo_stest[j]=sum(ifelse(valorP_stest<0.05,1,0))/tsim
prob_rechazo_wilcoxon[j]=sum(ifelse(valorP_wilcoxon<0.05,1,0))/tsim
}
cbind(prob_rechazo_stest, prob_rechazo_wilcoxon)
plot (mu_y,prob_rechazo_stest, type="l", col=2, main="Power",ylab="",xlab="")
lines(mu_y,prob_rechazo_wilcoxon, type="l", col=4)
有谁知道我是否使用此代码正确计算了两个测试的功率?有谁知道更好的方法来比较(和绘制)两种测试的力量以查看它们之间的差异?
谢谢你们 :)