Hypothesis Testing
Total Page:16
File Type:pdf, Size:1020Kb
Public Health & Intelligence Hypothesis Testing Document Control Version 0.4 Date Issued 29/11/2018 Authors David Carr, Nicole Jarvie Comments to [email protected] or [email protected] Version Date Comment Authors 0.1 24/08/2018 1st draft David Carr, Nicole Jarvie 0.2 11/09/2018 1st draft with formatting David Carr, Nicole Jarvie 0.3 17/10/2018 Final draft with changes from David Carr, Nicole Jarvie Statistical Advisory Group 0.4 29/11/2018 Final version David Carr, Nicole Jarvie Acknowledgements The authors would like to acknowledge Prof. Chris Robertson and colleagues at the University of Strathclyde for allowing the use of the data for the examples in this paper. The simulated HAI data sets used in the worked examples were originally created by the Health Protection Scotland SHAIPI team in collaboration with the University of Strathclyde. i Table of Contents 1 Introduction .............................................................................................................. 1 2 Constructing a Hypothesis Test .................................................................................. 3 2.1 Defining the Hypotheses ............................................................................................. 3 2.1.1 Null and Alternative Hypotheses .................................................................................... 3 2.1.2 One-Sided and Two-Sided Tests ..................................................................................... 4 2.2 Significance Level and Statistical Power ..................................................................... 6 2.2.1 Significance Level ............................................................................................................ 6 2.2.2 Statistical Power .............................................................................................................. 6 2.2.3 Type I and Type II Error ................................................................................................... 7 2.3 Test Statistic ................................................................................................................ 7 2.4 Rejection Region ......................................................................................................... 8 2.5 Determining Statistical Significance ............................................................................ 8 2.5.1 P-values ........................................................................................................................... 8 2.5.2 Confidence Intervals ....................................................................................................... 9 2.5.3 Comparing Results from One and Two-Sided Tests ...................................................... 11 2.6 Multiple Comparisons ............................................................................................... 11 2.6.1 The Bonferroni Correction ............................................................................................ 12 2.7 General Framework for Hypothesis Testing ............................................................. 12 3 T-tests ..................................................................................................................... 14 3.1 One Sample t-test...................................................................................................... 14 3.1.1 Example ......................................................................................................................... 16 3.2 Two Sample t-test ..................................................................................................... 19 3.2.1 Example ......................................................................................................................... 20 3.3 Paired t-test ............................................................................................................... 22 4 Non-Parametric Tests .............................................................................................. 23 4.1 Wilcoxon Signed Ranks Test ...................................................................................... 23 4.1.1 Example ......................................................................................................................... 24 4.2 Mann-Whitney U-test ............................................................................................... 25 4.2.1 Example ......................................................................................................................... 25 ii 5 Chi-Squared Tests .................................................................................................... 27 5.1 Goodness-of-Fit Test ................................................................................................. 27 5.1.1 Example ......................................................................................................................... 28 5.2 Test of Independence ................................................................................................ 29 5.2.1 Example ......................................................................................................................... 30 6 Proportion Tests ...................................................................................................... 33 6.1 One-Sample Test ....................................................................................................... 33 6.1.1 Example ......................................................................................................................... 35 6.2 Two-Sample Test ....................................................................................................... 36 6.2.1 Example ......................................................................................................................... 38 7 F-tests ..................................................................................................................... 40 7.1 F-test for Equality of Variances ................................................................................. 40 7.1.1 Example ......................................................................................................................... 41 7.2 F-test for Comparing Linear Regression Models ....................................................... 42 7.2.1 Example ......................................................................................................................... 43 Bibliography ................................................................................................................... 47 Appendices .................................................................................................................... 48 A Further Detail on Hypothesis Testing ........................................................................... 48 B Further Detail on F-test for Comparing Linear Regression Models .............................. 50 C R Code for Examples ..................................................................................................... 52 D SPSS Syntax for Examples ............................................................................................. 57 E SPSS Output for Examples ............................................................................................ 63 iii 1 Introduction The purpose of this paper is to outline the theory behind hypothesis testing and to demonstrate how hypothesis testing can be used as part of a range of statistical methods. The paper will address the following statistical methods in the context of hypothesis testing: t-tests, non-parametric tests (the Wilcoxon Signed-Ranks test and the Mann-Whitney U- test), chi-squared tests, proportion tests and F-tests. Some preliminary mathematical and statistical knowledge is assumed. Statistical hypothesis testing is about comparing two contradictory statements about one or more datasets and deciding which one is ‘correct’. For example, if an analyst was investigating if there was a difference in the average A&E waiting time between the Glasgow Royal Infirmary and the Royal Infirmary of Edinburgh, there are only two possible outcomes: either there is statistical evidence of a difference or there is not. Statistical tests that are based in hypothesis testing usually involve comparing one dataset to another. The objective is often to see if there is any statistically-significant difference between the datasets based on a statistic of interest (e.g. mean, median). Hypothesis testing theory is relevant here as the analyst is essentially investigating whether there is evidence of a difference and, if not, then concluding that there is no evidence of a difference. Most of the tests discussed in this paper are examples of ‘univariate’ analysis, where only one variable of interest can be considered. If a multivariate analysis is required, where multiple contributing factors are taken into consideration, then Regression Modelling is usually more appropriate. Table 1 summarises the tests that will be discussed in this paper. The theory behind hypothesis testing will be addressed first, before going on to discuss how the hypothesis- based tests in Table 1 can be used in practice, including showing examples in R (the equivalent SPSS syntax and output are shown in Appendices D and E, respectively). 1 Table 1: Summary of hypothesis tests Test When to Use Major Restrictions on Use One-sample t-test Comparing whether the mean of a Data must be normally-distributed (Chapter