22s:152 Applied Linear Regression. 1-way ANOVA visual:

Similar documents
22s:152 Applied Linear Regression. Chapter 8: 1-Way Analysis of Variance (ANOVA) 2-Way Analysis of Variance (ANOVA)

22s:152 Applied Linear Regression. Take random samples from each of m populations.

22s:152 Applied Linear Regression. There are a couple commonly used models for a one-way ANOVA with m groups. Chapter 8: ANOVA

Example: Poisondata. 22s:152 Applied Linear Regression. Chapter 8: ANOVA

22s:152 Applied Linear Regression

Multiple comparisons - subsequent inferences for two-way ANOVA

Linear Regression. In this lecture we will study a particular type of regression model: the linear regression model

Categorical Predictor Variables

1-Way ANOVA MATH 143. Spring Department of Mathematics and Statistics Calvin College

BIOL Biometry LAB 6 - SINGLE FACTOR ANOVA and MULTIPLE COMPARISON PROCEDURES

WELCOME! Lecture 13 Thommy Perlinger

Regression and the 2-Sample t

Statistics for EES Factorial analysis of variance

ST430 Exam 2 Solutions

Inferences for Regression

Analysis of Variance

T.I.H.E. IT 233 Statistics and Probability: Sem. 1: 2013 ESTIMATION AND HYPOTHESIS TESTING OF TWO POPULATIONS

Multiple Linear Regression

Variance Decomposition and Goodness of Fit

Inference for Regression

Example: Four levels of herbicide strength in an experiment on dry weight of treated plants.

610 - R1A "Make friends" with your data Psychology 610, University of Wisconsin-Madison

Dr. Junchao Xia Center of Biophysics and Computational Biology. Fall /8/2016 1/38

Workshop 7.4a: Single factor ANOVA

Review of Statistics 101

ANOVA: Analysis of Variance

One-Way ANOVA. Some examples of when ANOVA would be appropriate include:

Lecture 6 Multiple Linear Regression, cont.

ANOVA. Testing more than 2 conditions

ANOVA Analysis of Variance

y ˆ i = ˆ " T u i ( i th fitted value or i th fit)

One-Way ANOVA Cohen Chapter 12 EDUC/PSY 6600

ANOVA: Comparing More Than Two Means

Lecture 4 Multiple linear regression

Multiple Regression: Example

ANOVA Situation The F Statistic Multiple Comparisons. 1-Way ANOVA MATH 143. Department of Mathematics and Statistics Calvin College

Regression: Main Ideas Setting: Quantitative outcome with a quantitative explanatory variable. Example, cont.

Figure 1: The fitted line using the shipment route-number of ampules data. STAT5044: Regression and ANOVA The Solution of Homework #2 Inyoung Kim

Lab 3 A Quick Introduction to Multiple Linear Regression Psychology The Multiple Linear Regression Model

36-309/749 Experimental Design for Behavioral and Social Sciences. Sep. 22, 2015 Lecture 4: Linear Regression

1.) Fit the full model, i.e., allow for separate regression lines (different slopes and intercepts) for each species

STA 101 Final Review

ANOVA: Analysis of Variance

Variance Decomposition in Regression James M. Murray, Ph.D. University of Wisconsin - La Crosse Updated: October 04, 2017

Ch 2: Simple Linear Regression

MS&E 226: Small Data

Example. Multiple Regression. Review of ANOVA & Simple Regression /749 Experimental Design for Behavioral and Social Sciences

R 2 and F -Tests and ANOVA

Exam Applied Statistical Regression. Good Luck!

Sociology 6Z03 Review II

Cuckoo Birds. Analysis of Variance. Display of Cuckoo Bird Egg Lengths

Lecture 18: Simple Linear Regression

COMPARING SEVERAL MEANS: ANOVA

Wolf River. Lecture 19 - ANOVA. Exploratory analysis. Wolf River - Data. Sta 111. June 11, 2014

Example of treatment contrasts used by R in estimating ANOVA coefficients

Business Statistics. Lecture 10: Course Review

Introductory Statistics with R: Linear models for continuous response (Chapters 6, 7, and 11)

Inference. ME104: Linear Regression Analysis Kenneth Benoit. August 15, August 15, 2012 Lecture 3 Multiple linear regression 1 1 / 58

1. (Rao example 11.15) A study measures oxygen demand (y) (on a log scale) and five explanatory variables (see below). Data are available as

22s:152 Applied Linear Regression. Returning to a continuous response variable Y...

Contrasts and Multiple Comparisons Supplement for Pages

Introduction to the Analysis of Variance (ANOVA)

ST430 Exam 1 with Answers

A discussion on multiple regression models

22s:152 Applied Linear Regression. In matrix notation, we can write this model: Generalized Least Squares. Y = Xβ + ɛ with ɛ N n (0, Σ)

Oct Simple linear regression. Minimum mean square error prediction. Univariate. regression. Calculating intercept and slope

22s:152 Applied Linear Regression. Chapter 5: Ordinary Least Squares Regression. Part 1: Simple Linear Regression Introduction and Estimation

Analysis of Variance. Contents. 1 Analysis of Variance. 1.1 Review. Anthony Tanbakuchi Department of Mathematics Pima Community College

Analysis of Covariance. The following example illustrates a case where the covariate is affected by the treatments.

36-707: Regression Analysis Homework Solutions. Homework 3

Nature vs. nurture? Lecture 18 - Regression: Inference, Outliers, and Intervals. Regression Output. Conditions for inference.

Regression models. Categorical covariate, Quantitative outcome. Examples of categorical covariates. Group characteristics. Faculty of Health Sciences

MATH 644: Regression Analysis Methods

Introduction to Analysis of Variance. Chapter 11

Introduction to the Analysis of Variance (ANOVA) Computing One-Way Independent Measures (Between Subjects) ANOVAs

Comparing Nested Models

STAT 215 Confidence and Prediction Intervals in Regression

Regression, Part I. - In correlation, it would be irrelevant if we changed the axes on our graph.

STAT763: Applied Regression Analysis. Multiple linear regression. 4.4 Hypothesis testing

Lecture 5: Clustering, Linear Regression

Correlation 1. December 4, HMS, 2017, v1.1

Solutions to Final STAT 421, Fall 2008

1 Use of indicator random variables. (Chapter 8)

Section 4.6 Simple Linear Regression

STAT 525 Fall Final exam. Tuesday December 14, 2010

Lecture 5: ANOVA and Correlation

UNIVERSITY OF TORONTO Faculty of Arts and Science

Hypothesis testing, part 2. With some material from Howard Seltman, Blase Ur, Bilge Mutlu, Vibha Sazawal

Statistics 203 Introduction to Regression Models and ANOVA Practice Exam

Specific Differences. Lukas Meier, Seminar für Statistik

Activity #12: More regression topics: LOWESS; polynomial, nonlinear, robust, quantile; ANOVA as regression

Difference in two or more average scores in different groups

22s:152 Applied Linear Regression. Example: Study on lead levels in children. Ch. 14 (sec. 1) and Ch. 15 (sec. 1 & 4): Logistic Regression

ANOVA: Analysis of Variation

Hypothesis Testing hypothesis testing approach

Lecture 5: Clustering, Linear Regression

Unbalanced Data in Factorials Types I, II, III SS Part 1

Density Temp vs Ratio. temp

Statistical methods for comparing multiple groups. Lecture 7: ANOVA. ANOVA: Definition. ANOVA: Concepts

Week 7.1--IES 612-STA STA doc

Transcription:

22s:152 Applied Linear Regression 1-way ANOVA visual: Chapter 8: 1-Way Analysis of Variance (ANOVA) 2-Way Analysis of Variance (ANOVA) 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 Y We now consider an analysis with only categorical predictors (i.e. all predictors are factors). Predicting height from sex (M/F) Predicting white blood cell count from treatment group (A,B,C) If only 1 categorical predictor of a continuous response One-Way ANOVA µ 1 µ 2 µ 3 For example, µ dem µ rep µ ind In a 1-way ANOVA, we re interested in finding differences between population group means, if they exist. If two categorical predictors of a continuous response Two-Way ANOVA Factor 2 yes no µ 11 µ 12 µ 13 µ 21 µ 22 µ 23 For example, Factor 1 low med high 1 2 1-way ANOVA (only one factor) Consider the cell means model notation: (It uses 1 parameter to represent each cell mean) Y ij = µ i + ij where µ i is the group i mean. If there s only 2 levels, like in sex, then we can use a two-sample t-test H 0 : µ 1 = µ 2. If we have more than 2 levels, we extend this t-test idea to do a 1-way ANOVA. A two-sample t-test is essentially a 1-way ANOVA (it s the simplest one, there s only 2 levels to the factor) Suppose we have three populations (or 3 levels of a categorical variable) to compare... Example: Doesthepresenceofpetsorfriends affect the response to stress? n =45women(alldoglovers) Each woman randomly assigned to one of three treatment groups as: 1) alone 2) with friend 3) with pet Their heart rate is taken and recorded during astressfultask. Allen, Blascovich, Tomaka, Kelsey, 1988, Journal of Personality and Social Psychology. 3 4

> pets=read.csv("pets.csv") > head(pets) group rate 1 P 69.169 2 F 99.692 3 P 70.169 4 C 80.369 5 C 87.446 6 P 75.985 > attach(pets) > is.factor(group) [1] TRUE The treatment groups are: C for control group or alone. F for with friend. P for with pet. Consider the distribution of heart rate by treatment group... > boxplot(rate~group) 60 70 80 90 100 > table(group) group 15 15 15 This is a balanced 1-way ANOVA since all groups have the same number of subjects. 5 6 Get the mean of each group. > tapply(rate,group,mean) 82.52407 91.32513 73.48307 If we consider µ 1 as the population mean heart rate of the control group, µ 2 as the population mean heart rate of the friends group, µ 3 as the population mean heart rate of the pet group, then, to test if any of the groups have a different heart rate, we would consider the overall null hypothesis H 0 : µ 1 = µ 2 = µ 3 H A :atleastoneµ i is different for i=1,2,3 Why not just do 3 pairwise comparisons? H 0 : µ 1 = µ 2 H 0 : µ 1 = µ 3 H 0 : µ 2 = µ 3 Problems: 3separatep-valuesfor3different tests don t tell us how likely it is that three sample means (Ȳ1, Ȳ2, Ȳ3) arespreadapartasfarasthese by chance (i.e. when µ 1 = µ 2 = µ 3 ). It might be that Ȳ1 =73.48 and Ȳ2 =91.32 are significantly different when only looking at 2 populations, but not significantly different if we look at 3 populations as more and more groups are added, we expect the gap between smallest and largest sample means to get larger (even if the population means are the same). 7 8

The probability of a Type I error (rejecting H 0 when it was true) for the whole set of three t-tests will be larger than α. For example, Set the chance of making a Type I error on an individual t-test at α =0.05 The chance of NOT making a mistake on an individual t-test is (1 α) =0.95 These t-tests are not independent, but the general idea of doing multiple tests at a certain controlled error rate still stands. This is a multiple comparison issue. How do we control the error rate on a group of tests? What is the probability of not making a mistake on any of the three tests? Well, if the tests were independent, (1 α)(1 α)(1 α) =(0.95) 3 =0.8574 Thus, there s a 0.1426 chance of making at least 1 mistake (definitely larger than α =0.05forthewholesetofthreetests) 9 10 Multiple comparisons procedures in statistics How do we do numerous comparisons of interest simultaneously while maintaining a certain overall error rate (like α =0.05)? Two steps start with an overall test to see if anything is interesting... i.e. test if any of the means are significantly different using an overall F -test if so, do a follow up analysis to decide which groups differ and to estimate the size of differences 11 Step one: 1-Way ANOVA F-test We perform the overall F-test: H 0 : µ 1 = µ 2 = µ 3 H A :atleastoneµ i is different for i=1,2,3 Though we can do coding of two dummy variables to represent group, R will do this for us. > group [1] P F P C C P F F P F C C C F F P C P C C F F C P P [26] F F C C P P P C C C F F F P P F P Levels: > is.factor(group) [1] TRUE ## See how R has coded the dummy variables for ## the factor variable group using contrasts(): > contrasts(group) F P C 0 0 F 1 0 P 0 1 So, C is the baseline group (because both dummy variables are 0). 12

The regression model with dummy variables: Y i = β 0 + β F D 1i + β P D 2i + i The model for each group (3 separate means): Control group: Y i = β 0 + i Friend group: Y i =(β 0 + β F )+ i Pet group: Y i =(β 0 + β P )+ i The expected value of Y is the same for all i within a group. 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 Written another way... E[Y i group i = C] =µ C = β 0 E[Y i group i = F ]=µ F = β 0 + β F E[Y i group i = P ]=µ P = β 0 + β P Y 13 What do we get when we fit the model in R. > is.factor(group) [1] TRUE > lm.out=lm(rate ~ group) > coefficients(lm.out) (Intercept) groupf groupp 82.524067 8.801067-9.041000 ˆβ 0 ˆβF ˆβP The group means: > tapply(rate,group,mean) 82.52407 91.32513 73.48307 The distributions: 60 70 80 90 100 14 The dummy variable parameters represent the difference between the respective group and the baseline group. ˆβ F =Friendgroupmean-Baselinegroupmean ˆβ P =Petgroupmean-Baselinegroupmean Here, baseline was the Control group. We can use the anova function to get the sums of squares for the model (or the group variable), the residual sums of squares, and the overal F- test. > anova(lm.out) ## Only 1 factor used in this model Analysis of Variance Table Response: rate Df Sum Sq Mean Sq F value Pr(>F) group 2 2387.7 1193.8 14.079 2.092e-05 *** Residuals 42 3561.3 84.8 --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05. 0.1 1 15 The summary statement also gives us the overall F -test, AND the tests for β F =0,andβ P =0. > summary(lm.out) Coefficients: Estimate Std. Error t value Pr(> t ) (Intercept) 82.524 2.378 34.709 <2e-16 *** groupf 8.801 3.362 2.617 0.0123 * groupp -9.041 3.362-2.689 0.0102 * --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05. 0.1 1 Residual standard error: 9.208 on 42 degrees of freedom Multiple R-Squared: 0.4014,Adjusted R-squared: 0.3729 F-statistic: 14.08 on 2 and 42 DF, p-value: 2.092e-05 Rejection of H 0 : β F =0saysthereisevidence that the Friend group is different than the baseline group. Rejection of H 0 : β P =0saysthereisevidence that the Pet group is different than the baseline group. The overall F-test tests H 0 : β F = β P =0, which is the same as H 0 : µ C = µ F = µ P. 16

General concept of 1-Way ANOVA What matters is how far apart the sample means are relative to variability. Roughly speaking, we ll consider an F -statistic where... F = variation among the sample means variation among individuals in the same sample 0.00 0.10 0.20 0.30 When there is a lot of spread between the group sample means and very little spread within agroup,we willhave alarge F -statistic. Compare F to an F -distribution for decision 0.0 0.4 0.8 1.2 Notation: m =numberofdifferent populations whose means we are studying The means of the three groups above is the same in both pictures, but the variability is quite different. n i =numberofobservationsinsample from ith population N =total#ofobservations,n = m i=1 n i 17 18 F-distribution for 1-way ANOVA F -test H 0 : µ 1 = µ 2 =...= µ m H A :noth 0 m 1numeratordegreesoffreedom N m denominator degrees of freedom (N data points, m parameters estimated) Assumptions for One-way ANOVA m independent simple random samples, one from each of m populations Each population i is normally disributed about its unknown mean µ i If sample size is large enough, the Central Limit Theorem will kick-in and inferences based on sample means will be OK even if the populations distributions are not exactly normal. If you don t have normality, youcoulduse anon-parametrictest,suchthekruskall- Wallis test which is based on the ranks of the y-values rather than the y-values themselves. The populations have the same variance, σ 2 You can use Levene s Test (in the car library) to test for non-constant variance. 19 20

H 0 : σ 1 = σ 2 = σ 3 Step two: individual t-tests with correction for multiple comparisons > levenetest(rate, group) Levene s Test for Homogeneity of Variance Df F value Pr(>F) group 2 0.0028 0.9973 42 Since the p-value is not less than 0.05, we do not reject. Constant variance is reasonable. 60 70 80 90 100 21 If we reject the overall F -test, we proceed to further analysis. The most common tests of interest are all pairwise comparisons (µ 1 vs. µ 2, µ 1 vs. µ 3,..., µ m 1 vs. µ m,). We can use the Bonferroni correction to m make sure the set of all tests is done 2 at an overall α level error rate. For this correction, we can multiply each regular pairwise t-test p-value by the number of tests to get the adjusted p-value. Then, compare each adjusted p-value to α. 22 In R, wecanusethe pairwise.t.test function to do all pairwise comparisons. ## R Documentation: pairwise.t.test ## Calculate pairwise comparisons between group levels ## with corrections for multiple testing > pairwise.t.test(rate,group,p.adjust.method="bonferroni") Pairwise comparisons using t tests with pooled SD data: rate and group C F F 0.037 - P 0.031 1.2e-05 P value adjustment method: bonferroni All three p-values are compared against α =0.05, and in this case, ALL groups are significantly different from each other. The probability that we have falsely rejected H 0 for 1 or more of these 3 tests is 0.05. 23 Looking back at the individual t-tests comparing F and P to the baseline group C: > summary(lm.out) Coefficients: Estimate Std. Error t value Pr(> t ) (Intercept) 82.524 2.378 34.709 <2e-16 *** groupf 8.801 3.362 2.617 0.0123 * groupp -9.041 3.362-2.689 0.0102 * We see that the adjusted p-values (below) are just 3 times the individual test-wise p-values above. > pairwise.t.test(rate,group,p.adjust.method="bonferroni") Pairwise comparisons using t tests with pooled SD data: rate and group C F F 0.037 - P 0.031 1.2e-05 Plus, we get the comparison of Friends vs. Pet in the all-pairwise-comparisons statement. 24

You can change which group level is the baseline if this is useful to you. Here s the original, in alphabetical order: > contrasts(group) F P C 0 0 F 1 0 P 0 1 > levels(group) [1] "C" "F" "P" Here s commands to switch Pet to the baseline: ## Reassign baseline as the third level: > contrasts(group)=contr.treatment(levels(group),base=3) > contrasts(group) C F C 1 0 F 0 1 P 0 0 There are also other multiple comparison adjustments available in pairwise.t.test(). > pairwise.t.test(rate,group,p.adjust.method="bonferroni") Other options: holm hochberg hommel bonferroni BH BY fdr none 25 26