> # Goodness of fit example (Sokal & Rohlf Box 17.1 Part 1 pp 699) > pheno <- c(63,31,28,12,39,16,40,12) > mendel <- c(18,6,6,2,12,4,12,4) > expected.prob <- mendel/sum(mendel) > g.test(pheno,p=expected.prob) Log likelihood ratio (G-test) goodness of fit test data: pheno Log likelihood ratio statistic (G) = 8.824, X-squared df = 7, p-value = 0.2655 > g.test(pheno,p=expected.prob,correct="williams") Log likelihood ratio (G-test) goodness of fit test data: pheno Log likelihood ratio statistic (G) = 8.7694, X-squared df = 7, p-value = 0.2696 > # 2cell Goodness of fit example (Sokal & Rohlf Box 17.1 Part 2 pp 700) > pheno <- c(130,46) > expected <- c(0.75,0.25) > g.test(pheno,p=expected) Log likelihood ratio (G-test) goodness of fit test data: pheno Log likelihood ratio statistic (G) = 0.12, X-squared df = 1, p-value = 0.729 > g.test(pheno,p=expected,correct="williams") Log likelihood ratio (G-test) goodness of fit test data: pheno Log likelihood ratio statistic (G) = 0.1197, X-squared df = 1, p-value = 0.7294 > g.test(pheno,p=expected,correct="yates") Log likelihood ratio (G-test) goodness of fit test data: pheno Log likelihood ratio statistic (G) = 0.0677, X-squared df = 1, p-value = 0.7948 > # 2x2 Test of independence example (Sokal & Rohlf Box 17.6 pp 731) > serp <- c(12,22) > non.serp <- c(16,50) > data.mat <- rbind(serp,non.serp) > data.mat [,1] [,2] serp 12 22 non.serp 16 50 > g.test(data.mat)$expected [,1] [,2] serp 9.52 24.48 non.serp 18.48 47.52 > g.test(data.mat) Log likelihood ratio (G-test) test of independence without correction data: data.mat Log likelihood ratio statistic (G) = 1.3325, X-squared df = 1, p-value = 0.2484 > g.test(data.mat,correct="williams") Log likelihood ratio (G-test) test of independence with Williams' correction data: data.mat Log likelihood ratio statistic (G) = 1.3028, X-squared df = 1, p-value = 0.2537 > g.test(data.mat,correct="yates") Log likelihood ratio (G-test) test of independence with Yates' correction data: data.mat Log likelihood ratio statistic (G) = 0.8521, X-squared df = 1, p-value = 0.356 > # RxC Test of independence example (Sokal & Rohlf Box 17.8 pp 738) > red <- c(29,273,8,64) > not.red <- c(11,191,31,64) > data.mat <- cbind(red,not.red) > data.mat red not.red [1,] 29 11 [2,] 273 191 [3,] 8 31 [4,] 64 64 > g.test(data.mat) Log likelihood ratio (G-test) test of independence without correction data: data.mat Log likelihood ratio statistic (G) = 28.5964, X-squared df = 3, p-value = 2.722e-06 > g.test(data.mat,correct="williams") Log likelihood ratio (G-test) test of independence with Williams' correction data: data.mat Log likelihood ratio statistic (G) = 28.3125, X-squared df = 3, p-value = 3.123e-06 >