Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Statistical Methods: Lecture 10
Dennis Dobler
Vrije Universiteit Amsterdam
December 6, 2017
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Statistical Methods: Lecture 10 Dennis Dobler Vrije Universiteit - - PowerPoint PPT Presentation
Goodness-of-fit Test of independence Test of homogeneity Fishers Exact Test Statistical Methods: Lecture 10 Dennis Dobler Vrije Universiteit Amsterdam December 6, 2017 Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods:
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Vrije Universiteit Amsterdam
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
◮ Critical value method: reject H0 if χ2 > χ2
◮ P-value method: if P(X 2 ≥ χ2) < α reject H0. Use R for this. Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
10 20 30 40 0.00 0.05 0.10 0.15 0.20 0.25 density df=3 df=5 df=10 df=20
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
◮ 2 × 2: all Eij ≥ 5. ◮ larger tables: all Eij ≥ 1 and 80% of Eij larger than 5.
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
◮ row variable has r categories, column variable has c categories. ◮ H0: row and column variable are independent;
◮ Requirements (Eij is expected frequency count in cell (i, j) under H0) ◮ 2 × 2: all Eij ≥ 5. ◮ larger tables: all Eij ≥ 1 and 80% of Eij larger than 5. ◮ If the requirements are met, the test statistic X 2 = (O−E)2
◮ ◮ Critical value method: Reject H0 if observed value χ2 of test statistic is larger than
(r−1)(c−1),α ◮ P-value method: reject H0 if P-value=P(X 2 ≥ χ2) < α.
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
left=matrix(c(o11,o12,o21,o22),nrow=2,byrow=T); left ## [,1] [,2] ## [1,] 23 217 ## [2,] 65 455 e11=88*240/760; e12=672*240/760; e21=88*520/760; e22=672*520/760 expfreq=matrix(c(e11,e12,e21,e22),nrow=2,byrow=T); expfreq ## [,1] [,2] ## [1,] 27.79 212.2 ## [2,] 60.21 459.8 chi=(o11-e11)^2/e11+(o12-e12)^2/e12+(o21-e21)^2/e21+(o22-e22)^2/e22; chi ## [1] 1.364 #btw, a shorter way to compute the observed value is sum((left-expfreq)^2/expfreq) pvalue=1-pchisq(chi,df=1); pvalue ## [1] 0.2428 Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
left=matrix(c(o11,o12,o21,o22),nrow=2,byrow=T); left ## [,1] [,2] ## [1,] 23 217 ## [2,] 65 455 chisq.test(left) ## ## Pearson's Chi-squared test with Yates' continuity correction ## ## data: left ## X-squared = 1.1, df = 1, p-value = 0.3
chisq.test(left,correct=F) ## ## Pearson's Chi-squared test ## ## data: left ## X-squared = 1.4, df = 1, p-value = 0.2 Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
left=matrix(c(o11,o12,o21,o22),nrow=2,byrow=T); left ## [,1] [,2] ## [1,] 23 217 ## [2,] 65 455 chisq.test(left)$exp ## [,1] [,2] ## [1,] 27.79 212.2 ## [2,] 60.21 459.8
## Warning in chisq.test(matrix(c(5, 4, 8, 3), nrow = 2)): Chi-squared approximation may be incorrect ## ## Pearson's Chi-squared test with Yates' continuity correction ## ## data: matrix(c(5, 4, 8, 3), nrow = 2) ## X-squared = 0.11, df = 1, p-value = 0.7 Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
◮ r different populations and c different categories of some categorical variable. ◮ H0: Different populations have the same proportions of some characteristics;
◮ Requirements (Eij is expected frequency count in cell (i, j) under H0) ◮ 2 × 2: all Eij ≥ 5. ◮ larger tables: all Eij ≥ 1 and 80% of Eij larger than 5. ◮ If the requirements are met, the test statistic
◮ ◮ Critical value method: Reject H0 if observed value χ2 of test statistic is larger than
(r−1)(c−1),α ◮ P-value method: reject H0 if P-value=P(X 2 ≥ χ2) < α. Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
◮ The test statistic X 2 = (O − E)2/E has approximately a chi-square
◮ With chi-square tests the alternative hypothesis has to be undirected: Ha: the
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
> left=matrix(c(23,217,65,455),nrow=2,ncol=2,byrow=T) > fisher.test(left,alt="greater") Fisher's Exact Test for Count Data data: left p-value = 0.903 #ignore rest of output Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
◮ H0: row and column variables are independent;
◮ Test statistic: frequency count in cell (1, 1) has under H0 and given marginals a
◮ Compute p-value in R: use fisher.test(data,alt="greater") in this case. Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10
Goodness-of-fit Test of independence Test of homogeneity Fisher’s Exact Test
◮ Assignment 4 – will be on Canvas later today ◮ Four more meetings: ◮ Thursday, December 7: Exercise class ◮ Monday, December 11: Question session + overview Lectures 5–10 ◮ Tuesday, December 12: Computer session (Assignment 4) ◮ Thursday, December 14: Exercise class – exams from previous years ◮ Details about the final exam: soon on Canvas Dennis Dobler Vrije Universiteit Amsterdam Statistical Methods: Lecture 10