title: Diagram that compares the power of the t-Test with the power of the Chi-sqare-Test
body: <p>I try to compare the power functions of the Chi-square-Test and the t-Test for one particular value and my overall goal was to show that the t-Test is more powerful (because it has an assumption about the distribution). I used the pwr package for R for calculating the power of each function and then wrote two functions and plotted the results. 
  However, I do not find that the t-test is better than the Chi-square-test, and I am puzzled by the result. I spend hours on it so every help is so much appreciated. </p>
  
  <p><a href="https://i.stack.imgur.com/nw5BG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nw5BG.png" alt="enter image description here"></a></p>
  
  <p>Is the code wrong, do I have a wrong understanding of the power functions, or is there something wrong in the package?</p>
  
  <pre><code>library(pwr)
  #mu is the value for which the power is calculated
  #no is the number of observations
  #function of the power of the t-test with a h0 of .2
  g &lt;- function(mu, alpha, no) { #calculate the power of a particular value for the t-test with h0=.2
        p &lt;- mu-.20
        sigma &lt;- sqrt(.5*(1-.5)) 
        pwr.t.test(n = no, d = p/sigma, sig.level = alpha, type = "one.sample", alternative="greater")$power # d is the effect size p/sigma
  }
  #chi squared test
  h &lt;- function(mu, alpha, no, degree) {#calculate the power of a particular value for the chi squared test
        p01 &lt;- .2 # these constructs the effect size (which is a bit different for the chi squared)
        p02 &lt;- .8
  
        p11 &lt;-mu
        p12 &lt;- 1-p11
  
        effect.size &lt;- sqrt(((p01-p11)^2/p01)+((p02-p12)^2/p02)) # effect size
  
        pwr.chisq.test(N=no, df=degree, sig.level = alpha, w=effect.size)$power
  }
  
  
  
  #create a diagram
  plot(1, 1, type = "n", 
       xlab = expression(mu), 
       xlim = c(.00, .75), 
       ylim = c(0, 1.1), 
       ylab = expression(1-beta), 
       axes=T, main="Power function t-Test and Chi-squared-Test")
        axis(side = 2, at = c(0.05), labels = c(expression(alpha)), las = 3)
        axis(side = 1, at = 3, labels = expression(mu[0]))
        abline(h = c(0.05, 1), lty = 2)
  
  legend(.5,.5, # places a legend at the appropriate place 
  c("t-Test","Chi-square-Test"), # puts text in the legend 
  lwd=c(2.5,2.5),col=c("black","red"))
  
  curve(h(x, alpha = 0.05, no = 100, degree=1), from = .00, to = .75, add = TRUE, col="red",lwd=c(2.5,2.5) )
  curve(g(x, alpha = 0.05, no = 100), from = .00, to = .75, add = TRUE, lwd=c(2.5,2.5))
  </code></pre>
  
  <p>Thanks a lot in advance!</p>