【问题标题】:Chi square goodness of fit without Yates correction没有 Yates 校正的卡方拟合优度
【发布时间】:2014-03-02 16:00:39
【问题描述】:

我想进行理论上的卡方拟合优度检验:

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

我的错误在哪里?

【问题讨论】:

    标签: r chi-squared significance goodness-of-fit


    【解决方案1】:

    我不认为你在测试你想要测试的东西。正如 ?chisq.test 的帮助所述,Yates 通过 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
    

    【讨论】:

    • 谢谢!事实上,我的目标是找出分布显着不同所需的最小差异。也就是说,我想知道 'actual 3.84。我该怎么做?
    • @user3213255 - 请参阅我的编辑以获取 optim 解决方案以找到确切的位置。
    猜你喜欢
    • 1970-01-01
    • 2014-03-06
    • 1970-01-01
    • 1970-01-01
    • 2022-08-20
    • 2020-04-28
    • 2014-08-13
    • 1970-01-01
    • 2014-03-07
    相关资源
    最近更新 更多