簡體   English   中英

該圖將t檢驗的功效與卡方檢驗的功效進行了比較

[英]Diagram that compares the power of the t-Test with the power of the Chi-sqare-Test

我嘗試將卡方檢驗和t檢驗的冪函數比較一個特定值,我的總體目標是證明t檢驗更強大(因為它對分布有假設)。 我將pwr軟件包用於R計算每個函數的功效,然后編寫了兩個函數並繪制了結果。 但是,我發現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))

在此先多謝!

如果我理解正確的問題,那么您正在測試二項分布,其零值下的均值等於0.2,而替代值的零值大於0.2? 如果是這樣,那么在函數g第2行上,它不是sigma <- sqrt(.2*(1-.2))而不是sigma <- sqrt(.5*(1-.5))嗎? 這樣,您的標准偏差將更小,從而導致更大的測試統計量,從而使p值更小,從而獲得更高的功效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM