比较t检验和Chi-sqare检验的功效的图表

比较t检验和Chi-sqare检验的功效的图表,r,statistics,R,Statistics,我试图比较一个特定值的卡方检验和t检验的幂函数,我的总体目标是证明t检验更强大(因为它有一个关于分布的假设)。我使用pwr包计算每个函数的幂,然后编写两个函数并绘制结果。 然而,我没有发现t检验比卡方检验好,我对结果感到困惑。我花了好几个小时在这上面,所以我非常感谢你的帮助 代码是否错误,我是否对幂函数有错误的理解,或者包中是否有错误 library(pwr) #mu is the value for which the power is calculated #no is the numbe

我试图比较一个特定值的卡方检验和t检验的幂函数,我的总体目标是证明t检验更强大(因为它有一个关于分布的假设)。我使用pwr包计算每个函数的幂,然后编写两个函数并绘制结果。 然而,我没有发现t检验比卡方检验好,我对结果感到困惑。我花了好几个小时在这上面,所以我非常感谢你的帮助

代码是否错误,我是否对幂函数有错误的理解,或者包中是否有错误

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 <- function(mu, alpha, no) { #calculate the power of a particular value for the t-test with h0=.2
      p <- mu-.20
      sigma <- 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 <- function(mu, alpha, no, degree) {#calculate the power of a particular value for the chi squared test
      p01 <- .2 # these constructs the effect size (which is a bit different for the chi squared)
      p02 <- .8

      p11 <-mu
      p12 <- 1-p11

      effect.size <- 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))
库(pwr)
#mu是计算功率的值
#否是观察的数量
#h0为0.2的t检验的幂函数

g如果我正确理解了这个问题,你是在测试一个二项分布,在零下的平均值等于0.2,而另一个选择是零大于0.2?如果是这样,那么在函数
g
的第2行,它不应该是
sigma吗