2014-02-05 21 views
0

欲進行配合測試的理論卡方優度:配合的卡方優度而不耶茨校正

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

樣品大小n = 100,α= 0.05,DF = 1。這給出了3.84的關鍵氣味值。 (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 

我的錯誤在哪裏?

回答

0

我不認爲你正在測試你打算進行測試。在?chisq.test狀態的幫助中,Yates通過correct=參數的連續性校正爲:「邏輯指示在計算2乘以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 
+0

謝謝!實際上,我的目標是找出分佈差異所必需的最小差異。也就是說,我想知道x的實際值< - c(x,100-x),X平方> 3.84。我該怎麼做呢? – user3213255

+0

@ user3213255 - 查看我編輯的'optim'解決方案以找到確切位置。 – thelatemail