0

我想进行理论上的卡方拟合优度测试:

actual <- c(20,80)
expected <- c(10,90)
chisq.test(expected,actual) 

样本量 n=100,alpha=0.05,df=1。这给出了 3.84 的临界 chi 值。我可以手动计算测试统计为 ((20-10)^2)/10 + ((80-90)^2)/90 = 100/9 > 3.84

但是,上面的代码只是产生

Pearson's Chi-squared test with Yates' continuity correction

data:  expected and actual 
X-squared = 0, df = 1, p-value = 1

我的错误在哪里?

4

1 回答 1

0

我不认为您正在测试您打算测试的内容。正如在?chisq.test 状态的帮助,耶茨通过correct=参数的连续性校正是:“在计算2 x 2 表的测试统计量时是否应用连续性校正的逻辑指示。”

相反,请尝试:

chisq.test(x=actual,p=prop.table(expected))

#        Chi-squared test for given probabilities
# 
#data:  actual
#X-squared = 11.1111, df = 1, p-value = 0.0008581

您可以使用optim来找到正确的值,这些值只会为您提供高于临界值的卡方统计量:

critchi <- function(par,actual=c(20,80),crit=3.84) {
  res <- chisq.test(actual,p=prop.table(c(par,100-par)))
  abs(crit - res$statistic)
}
optim(par = c(1), critchi, method="Brent", lower=1,upper=100)$par
#[1] 28.88106

您可以通过将 29 替换为 28.88 的四舍五入整数来确认这种情况:

chisq.test(actual, p=prop.table(c(29,100-29)))
#X-squared = 3.9339, df = 1, p-value = 0.04732
于 2014-02-05T23:21:04.157 回答