r - Chi square goodness of fit without Yates correction -


i want conduct theoretical chi square goodness of fit test:

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

sample size n=100, alpha=0.05, df=1. gives critical chi value of 3.84. hand can calculate test statistic ((20-10)^2)/10 + ((80-90)^2)/90 = 100/9 > 3.84

however, above code yields

pearson's chi-squared test yates' continuity correction  data:  expected , actual  x-squared = 0, df = 1, p-value = 1 

where mistake?

i don't think you're testing intend on testing. @ ?chisq.test states, yates' continuity correction via correct= argument is: "a logical indicating whether apply continuity correction when computing test statistic 2 2 tables."

instead, try:

chisq.test(x=actual,p=prop.table(expected))  #        chi-squared test given probabilities #  #data:  actual #x-squared = 11.1111, df = 1, p-value = 0.0008581 

you use optim find right values give chi-square statistic above critical value:

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 

you can confirm case substituting 29, rounded-up whole number of 28.88:

chisq.test(actual, p=prop.table(c(29,100-29))) #x-squared = 3.9339, df = 1, p-value = 0.04732 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -