0

I need to compare the power between the Wilcoxon Test and Sign Test for Null Hypothesis: Theta=0 and Alternative Hypothesis: Theta>0. The data comes from a random normal distribution with n=20 and mu=0.

I tried the following code to accomplish my task, but I don't know if it is correct because the plot that I obtained is a kind weird.

 ### 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)

Does anyone know if I calculated the Power of both tests correctly with this code? Does anyone know a better way to compare (and plot) the power of both tests to see the difference between them?

Thank you all :)

Aragorn64
  • 149
  • 7

0 Answers0