### Name: chisq.test ### Title: Pearson's Chi-squared Test for Count Data ### Aliases: chisq.test ### Keywords: htest distribution ### ** Examples ## Not really a good example chisq.test(InsectSprays$count > 7, InsectSprays$spray) # Prints test summary chisq.test(InsectSprays$count > 7, InsectSprays$spray)$observed # Counts observed chisq.test(InsectSprays$count > 7, InsectSprays$spray)$expected # Counts expected under the null ## Effect of simulating p-values x <- matrix(c(12, 5, 7, 7), ncol = 2) chisq.test(x)$p.value # 0.4233 chisq.test(x, simulate.p.value = TRUE, B = 10000)$p.value # around 0.29! ## Testing for population probabilities ## Case A. Tabulated data x <- c(A = 20, B = 15, C = 25) chisq.test(x) chisq.test(as.table(x)) # the same x <- c(89,37,30,28,2) p <- c(40,20,20,15,5) try( chisq.test(x, p = p) # gives an error ) chisq.test(x, p = p, rescale.p = TRUE) # works p <- c(0.40,0.20,0.20,0.19,0.01) # Expected count in category 5 # is 1.86 < 5 ==> chi square approx. chisq.test(x, p = p) # maybe doubtful, but is ok! chisq.test(x, p = p,simulate.p.value = TRUE) ## Case B. Raw data x <- trunc(5 * runif(100)) chisq.test(table(x)) # NOT 'chisq.test(x)'!