STAT 651 Lecture 10 Copyright (c) Bani Mallick 1 Topics in Lecture #10 Comparing two population means using rank tests Comparing two population variances using Levene’s test The effect of outliers Copyright (c) Bani Mallick 2 Book Sections Covered in Lecture #10 Chapter 6.3 (Wilcoxon Test) Page 368 (Levene’s test, although it is called Levine’s test): This is slightly different from what SPSS does The material on outliers is from my own notes Copyright (c) Bani Mallick 3 Lecture 9 Review: Comparing Two Populations X1 X 2 Difference of sample means The s.d. from repeated sampling is σ σ + n1 n 2 2 1 2 2 You need reasonably large samples from BOTH populations Copyright (c) Bani Mallick 4 Lecture 9 Review: Comparing Two Populations If you can reasonably believe that the population sd’s are nearly equal, it is customary to pick the equal variance assumption and estimate the common standard deviation by sp (n1 1)s (n 2 1)s n1 n 2 1 2 1 Copyright (c) Bani Mallick 2 2 5 Lecture 9 Review: Comparing Two Populations The standard error then of the value sp X1 X 2 is 1 1 n1 n 2 The number of degrees of freedom is n1 n 2 2 Copyright (c) Bani Mallick 6 Lecture 9 Review: Comparing Two Populations A (1a)100% CI for μ1 -μ 2 ± t (n +n -2)s α/2 1 2 p X1 X 2 is 1 1 + n1 n 2 Note how the sample sizes determine the CI length Copyright (c) Bani Mallick 7 Lecture 9 Review: Comparing Two Populations The CI can of course be used to test hypotheses H0 :μ1 =μ 2 vs Ha :μ1¹μ 2 This is the same as H0 :μ1 -μ 2 =0 vs Ha :μ1 -μ 2 ¹0 So we just need to check whether 0 is in the interval, just as we have done Copyright (c) Bani Mallick 8 Lecture 9 Review: Comparing Two Populations Generally, you should make your sample sizes nearly equal, or at least not wildly unequal. Consider a total sample size of 100 X1 X2 ta /2 (n1 +n 2 -2)s p 1 1 n1 n 2 1 1 n1 n 2 = 1 if n1 = 1, n2 = 99 = 0.20 if n1 = 50, n2 = 50 Thus, in the former case, your CI would be 5 times longer! Copyright (c) Bani Mallick 9 Lecture 9 Review: NHANES Comparison Mean(Healthy) – Mean(Cancer) The 95% CI is from 0.0065 to 0.5223 Confidence Interval 0= Hypothesized value 0.065 Copyright (c) Bani Mallick 0.5223 10 Arsenic and Squamous Cell Skin Cancer The question is whether arsenic ingestion is related to squamous call carcinoma We used the transformation X = log(0.005 + toe arsenic) Copyright (c) Bani Mallick 11 Arsenic and Squamous Cell Skin Cancer 0. 00 Healthy Percent 15% 10% 5% 0% 1. 00 Cancer Percent 15% 10% 5% 0% -5.00 -3.00 -1.00 1.00 log(0.005 + Toe Ar s e nic Le ve l) Copyright (c) Bani Mallick 12 Arsenic and Squamous Cell Skin Cancer 2 1 1 0 log(0.005 + Toe Arsenic) -1 3 5 7 12 13 14 18 20 2 4 6 9 8 10 11 15 16 17 19 21 806 807 804 805 808 -2 -3 -4 -5 N= 284 524 Cancer Healthy Squamous Cell Carcinoma Status Copyright (c) Bani Mallick 13 Arsenic and Squamous Cell Skin Cancer, Healthy Cases Normal Q-Q Plot of log(0.005 + Toe Arsenic) 0 -1 Expected Normal Value -2 -3 -4 -5 -5 -4 -3 -2 -1 0 Observed Value Copyright (c) Bani Mallick 14 Arsenic and Squamous Cell Skin Cancer: Cancer Cases Normal Q-Q Plot of log(0.005 + Toe Arsenic) 0 -1 Expected Normal Value -2 -3 -4 -5 -5 -4 -3 -2 -1 0 1 Observed Value Copyright (c) Bani Mallick 15 Arsenic and Squamous Cell Skin Cancer Healthy, s = 0.59, IQR = 0.69 Squamous, s = 0.62, IQR = 0.71 These statistics and box plots indicate that the two populations do not have vastly different variability. Copyright (c) Bani Mallick 16 Arsenic and Squamous Cell Skin Cancer Healthy: mean = -2.33, n = 215, se = 0.040 Squamous: mean = -2.3365, n = 140, se = 0.052 Mean difference = 0.020, se = 0.066 95% CI= [-0.109, 0.149] p = 0.76: what does this mean? Copyright (c) Bani Mallick 17 Arsenic and Squamous Cell Skin Cancer Graphs, statistics, CI, p-value, all tell us that not much seems to be going on! Copyright (c) Bani Mallick 18 Robust Inference via Rank Tests Because sample means and standard deviations are sensitive to outliers, so too are comparisons of populations based on them Rank tests form a robust alternative, that can be used to check the results of t-statistic inferences You are looking for major discrepancies, and then trying to explain them Copyright (c) Bani Mallick 19 Robust Inference via Rank Tests Rank tests are very easy to compute, and SPSS provides them. Typically called the Wilcoxon rank sum test The algorithm is to assign ranks to each observation in the pooled data set Then apply a t-test to these ranks Robust because ranks can never get wild Copyright (c) Bani Mallick 20 Robust Inference via Rank Tests Here is how data are ranked Data #1 #2 Ranks #1 1 #2 4 -3 7 28 44 22 50 45 55 81 56 2 3 6 10 5 7 8 9 Now run a t-test Copyright (c) Bani Mallick 21 Robust Inference via Rank Tests The rank tests give the same answer no matter whether you take the raw data, their logarithms or their square roots. If you have data (raw or transformed) that pass q-q plots tests, then Wilcoxon and t-test should have much the same p-values In this case, you can use the latter to get CI’s Copyright (c) Bani Mallick 22 Robust Inference via Rank Tests Differences between rank and t-tests occur for two reasons generally: outliers and very non-bell shaped histograms Copyright (c) Bani Mallick 23 Robust Inference via Rank Tests In SPSS, you can get Wilcoxon rank sum tests as follows (SPSS calls them Mann-Whitney U) “Analyze”, “Nonparametric Tests”, “2 independent samples” Copyright (c) Bani Mallick 24 Robust Inference via Rank Tests Toe Arsenic log(0.005 + Toe Arsenic) Note how p-values are the same (= 0.468) a Test Statistics Mann-Whitney U Wilcoxon W Z Asymp. Sig. (2-tailed) log(0.005 + Toe Arsenic) 14364.500 24234.500 -.725 .468 Toe Arsenic 14364.500 24234.500 -.725 .468 a. Grouping Variable: Squamous Cancer Status Copyright (c) Bani Mallick 25 Robust Inference via Rank Tests, NHANES Saturated Fat p-values: t-test = 0.057 , rank test = 0.014 Log(Saturated Fat): rank test = 0.014 t-test = 0.012, Note how the transform, which is more bellshaped, agrees more closely with the rank test! Copyright (c) Bani Mallick 26 Robust Inference via Rank Tests An SPSS peculiarity: to do rank tests, you need to have defined a numeric variable that categorizes the groups. The alternative is to convert the data to numbers and then give value labels. Copyright (c) Bani Mallick 27 Inference for Equality of Variances We have described situations that comparing variability of populations is desired. Ott and Longnecker (Chapter 7) give methods for comparing population variances NEVER USE THESE METHODS They are notoriously unreliable, affected by outliers, non-perfectly bell shaped, etc. Copyright (c) Bani Mallick 28 Inference for Equality of Variances SPSS uses what is called Levene’s test From the SPSS Help file (slightly edited) Levene Test For each case, it computes the absolute difference between the value of that case and its cell mean and performs a t-test on those absolute differences. Copyright (c) Bani Mallick 29 Inference for Equality of Variances Levene Test For each case, it computes the absolute difference between the value of that case and its cell mean and performs a t-test on those absolute differences. This is a reasonable test, although I prefer to use a rank test instead of the t-test Copyright (c) Bani Mallick 30 Inference for Equality of Variances I suggest that you supplement the Levene test with a look at the IQR in boxplots If you really need to understand scientifically the question of equality of variance, I suggest that you consult a bona-fide statistician I’ll now illustrate Levene’s test using NHANES (and this is the last time for these data) Copyright (c) Bani Mallick 31 Inference for Equality of Variances: Note the outlier 140 120 119 100 80 60 60 118 Saturated Fat 40 20 0 -20 N= 59 60 Cancer Healthy Health Status Copyright (c) Bani Mallick 32 Inference for Equality of Variances 6 5 119 4 3 2 1 N= 59 60 Cancer Healthy Health Status Copyright (c) Bani Mallick 33 Inference for Equality of Variances P-value of Levene’s test for Saturated Fat = 0.378 Same P-value, but without the outlier = 0.010 P-value for log(Saturated Fat) = .667 P-Value for Levene’s test for Saturated Fat when using the rank test instead of the t-test = 0.039 P-Value for Levene’s test for log(Saturated Fat) when using the rank test instead of the t-test = 0.665 Copyright (c) Bani Mallick 34 Inference for Equality of Variances As you can see, the rank test version of Levene’s test gives answers much more in keeping with the box plots The problem was clearly the outlier, so you can expect trouble with Levene’s test if there is a massive outlier Remember, t-tests have trouble with outliers Copyright (c) Bani Mallick 35 Inference for Equality of Variances As you can see, the rank test version of Levene’s test gives answers much more in keeping with the box plots The problem is that it’s a pain to compute the rank test version in SPSS However, theory says that the rank test version is the better, so in exams I’ll give it to you. Copyright (c) Bani Mallick 36 The Effect of an Outlier What will happen to the sample mean For cancer cases if I remove the outlier? 140 120 119 100 80 60 60 118 Saturated Fat 40 20 0 -20 N= 59 60 Cancer Healthy Health Status Copyright (c) Bani Mallick 37 The effect of anoutlier What will happen to the sample mean for the cancer cases if I remove the outlier? It will decrease 140 120 119 100 80 60 60 118 Saturated Fat 40 What will happen to the sample standard error for the cancer cases if I remove the outlier? 20 0 -20 N= 59 60 Cancer Healthy Health Status Copyright (c) Bani Mallick 38 The effect of anoutlier What will happen to the difference between the sample mean for healthy cases and the same mean for cancer cases, if I delete the outlier? 140 120 119 100 80 60 60 118 Saturated Fat 40 What will happen to the sample standard error for the cancer cases if I remove the outlier? It will decrease 20 0 -20 N= 59 60 Cancer Healthy Health Status Copyright (c) Bani Mallick 39 The effect of anoutlier What will happen to the difference between the sample mean for healthy cases and the same mean for cancer cases, if I delete the outlier? It will increase 140 120 119 100 80 60 60 118 Saturated Fat 40 What will happen to the sample standard error of this difference if I remove the outlier? 20 0 -20 N= 59 60 Cancer Healthy Health Status Copyright (c) Bani Mallick 40 The effect of anoutlier What will happen to the difference between the sample mean for healthy cases and the same mean for cancer cases, if I delete the outlier? It will increase 140 120 119 100 80 60 60 118 Saturated Fat 40 What will happen to the sample standard error of this difference if I remove the outlier? It will decrease 20 0 -20 N= 59 60 Cancer Healthy Health Status Therefore, what will happen to the p-value if I delete the outlier? Copyright (c) Bani Mallick 41 The effect of anoutlier What will happen to the difference between the sample mean for healthy cases and the same mean for cancer cases, if I delete the outlier? It will increase 140 120 119 100 80 60 60 118 Saturated Fat 40 What will happen to the sample standard error of this difference if I remove the outlier? It will decrease 20 0 -20 N= 59 60 Cancer Healthy Health Status Therefore, what will happen to the p-value if I delete the outlier? It will get smaller Copyright (c) Bani Mallick 42 The effect of anoutlier With the outlier, p = 0.057 140 120 119 100 80 60 60 118 Saturated Fat 40 I remove the outlier, p = 0.002 20 0 -20 N= 59 60 Cancer Healthy Health Status Therefore, what will happen to the p-value if I delete the outlier? It will get smaller Copyright (c) Bani Mallick 43