An R Companion for the Handbook of Biological Statistics
Total Page:16
File Type:pdf, Size:1020Kb
AN R COMPANION FOR THE HANDBOOK OF BIOLOGICAL STATISTICS SALVATORE S. MANGIAFICO Rutgers Cooperative Extension New Brunswick, NJ VERSION 1.3.3 i ©2015 by Salvatore S. Mangiafico, except for organization of statistical tests and selection of examples for these tests ©2014 by John H. McDonald. Used with permission. Non-commercial reproduction of this content, with attribution, is permitted. For-profit reproduction without permission is prohibited. If you use the code or information in this site in a published work, please cite it as a source. Also, if you are an instructor and use this book in your course, please let me know. [email protected] Mangiafico, S.S. 2015. An R Companion for the Handbook of Biological Statistics, version 1.3.3. rcompanion.org/documents/RCompanionBioStatistics.pdf . (Web version: rcompanion.org/rcompanion/ ). ii Table of Chapter Introduction ............................................................................................................................... 1 Purpose of This Book.......................................................................................................................... 1 The Handbook for Biological Statistics ................................................................................................ 1 About the Author of this Companion .................................................................................................. 1 About R ............................................................................................................................................. 2 Obtaining R ........................................................................................................................................ 2 A Few Notes to Get Started with R ..................................................................................................... 3 Avoiding Pitfalls in R ........................................................................................................................ 10 Help with R ...................................................................................................................................... 11 R Tutorials ....................................................................................................................................... 12 Formal Statistics Books .................................................................................................................... 13 Tests for Nominal Variables ...................................................................................................... 14 Exact Test of Goodness-of-Fit ........................................................................................................... 14 Power Analysis ................................................................................................................................ 23 Chi-square Test of Goodness-of-Fit ................................................................................................... 24 G–test of Goodness-of-Fit ................................................................................................................ 32 Chi-square Test of Independence...................................................................................................... 35 G–test of Independence ................................................................................................................... 47 Fisher’s Exact Test of Independence ................................................................................................. 53 Small Numbers in Chi-square and G–tests ......................................................................................... 61 Repeated G–tests of Goodness-of-Fit ................................................................................................ 61 Cochran–Mantel–Haenszel Test for Repeated Tests of Independence ................................................ 66 Descriptive Statistics ................................................................................................................. 78 Statistics of Central Tendency ........................................................................................................... 78 Statistics of Dispersion ..................................................................................................................... 84 Standard Error of the Mean .............................................................................................................. 87 Confidence Limits............................................................................................................................. 88 Tests for One Measurement Variable ........................................................................................ 94 Student’s t–test for One Sample ....................................................................................................... 94 Student’s t–test for Two Samples ..................................................................................................... 97 Mann–Whitney and Two-sample Permutation Test ......................................................................... 101 iii Chapters Not Covered in This Book .................................................................................................. 103 Type I, II, and III Sums of Squares .................................................................................................... 104 One-way Anova .............................................................................................................................. 106 Kruskal–Wallis Test ......................................................................................................................... 118 One-way Analysis with Permutation Test ......................................................................................... 129 Nested Anova ................................................................................................................................. 133 Two-way Anova .............................................................................................................................. 143 Two-way Anova with Robust Estimation .......................................................................................... 161 Paired t–test ................................................................................................................................... 169 Wilcoxon Signed-rank Test .............................................................................................................. 178 Regressions ............................................................................................................................ 182 Correlation and Linear Regression ................................................................................................... 182 Spearman Rank Correlation ............................................................................................................. 190 Curvilinear Regression ..................................................................................................................... 193 Analysis of Covariance .................................................................................................................... 206 Multiple Regression ........................................................................................................................ 216 Simple Logistic Regression ............................................................................................................... 228 Multiple Logistic Regression ............................................................................................................ 242 Multiple tests ......................................................................................................................... 256 Multiple Comparisons ..................................................................................................................... 256 Miscellany .............................................................................................................................. 263 Chapters Not Covered in this Book .................................................................................................. 263 Other Analyses ....................................................................................................................... 264 Contrasts in Linear Models .............................................................................................................. 264 Cate–Nelson Analysis ...................................................................................................................... 275 Additional Helpful Tips ........................................................................................................... 282 Reading SAS Datalines in R .............................................................................................................. 282 iv Table of Contents Introduction ____________________________________________________________________ 1 Purpose of This Book __________________________________________________________________ 1 The Handbook for Biological Statistics ____________________________________________________ 1 About the Author of this Companion _____________________________________________________ 1 About R _____________________________________________________________________________ 2 Obtaining R __________________________________________________________________________ 2 Standard