# R notes # ================================= # index to these notes # Chi-square, Fisher's exact, and McNemar's tests # ================================= # Rosner, chapter 10 # ================================= # R : chisq.test() # http://www.r-tutor.com/elementary-statistics/goodness-fit/chi-squared-test-independence data <- rbind(c(a, b), c(c, d)); data chisq.test(data) # ================================= # R : Fisher's Exact Test # R-bloggers : Fisher's Exact Test # http://www.r-bloggers.com/contingency-tables-%E2%80%93-fisher%E2%80%99s-exact-test/ # Chi-square, Fisher's exact, and McNemar's test # http://yatani.jp/HCIstats/ChiSquare mat <- matrix(c(2, 5, 3, 1), nrow=2); mat fisher.test(mat) # ================================= # example 10.25 hypertension # Exact Test # McNemar's Test and Exact McNemar's Test # http://www.statsdirect.com/help/chi_square_tests/mat.htm # http://yatani.jp/HCIstats/ChiSquare # R : package exact2x2 # http://cran.r-project.org/web/packages/exact2x2/exact2x2.pdf mat <- matrix(c(3, 1, 7, 9), nrow=2, dimnames=list("computer"=c("hypertension +", "hypertension -"), "trained observer"=c("hypertension +", "hypertension -"))); mat n.A <- 7 n.D <- 8 # test appropriate? (for McNemar's Test) # not appropriate, so use Exact Test test.appropriate <- n.D >= 20; test.appropriate p <- 2 * sum(dbinom(x=n.A:n.D, size=n.D, prob=1/2)); p significance(p) # R : package exact2x2 with mcnemar.test() # first, install package exact2x2 (with its dependencies) library(exact2x2) mcnemar.exact(mat) # =================================