【问题标题】:Diagram that compares the power of the t-Test with the power of the Chi-sqare-Test将 t 检验的功效与卡方检验的功效进行比较的图表
【发布时间】:2016-02-02 06:29:56
【问题描述】:

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

是不是代码错了,是我对power函数的理解有误,还是封装有问题?

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

提前非常感谢!

【问题讨论】:

    标签: r statistics


    【解决方案1】:

    如果我正确理解了这个问题,您正在测试一个二项分布,其 null 下的均值等于 0.2,而 null 大于 0.2?如果是这样,那么在你的第 2 行函数 g,不应该是 sigma &lt;- sqrt(.2*(1-.2)) 而不是 sigma &lt;- sqrt(.5*(1-.5)) 吗?这样,您的标准差会更小,从而产生更大的检验统计量,因此更小的 p 值会导致更高的功效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-12
      • 2013-04-22
      • 2018-02-28
      • 2023-03-07
      • 2023-03-13
      • 2023-03-23
      • 2015-01-08
      • 1970-01-01
      相关资源
      最近更新 更多