# sta305 lecture 7 2016.7.22.pdf - STA305/1004 Class 7 I...

• Notes
• 69
• 100% (1) 1 out of 1 people found this document helpful

This preview shows page 1 - 12 out of 69 pages.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . STA305/1004 - Class 7 July 22, 2016
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . I Start: 6:10 pm I Answers to Questions A and B (Unit 6 notes, Section 6) I ANOVA continued I Estimating treatment effects in ANOVA using regression I Coding qualitative predictors in regression models I Estimating treatment effects using least squares I Multiple comparisons I Sample size for ANOVA I In-class work I Post-midterm tutorial The break today will be perhaps 7:15-7:30 pm
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ANOVA Demonstration - Cancelled owing to confectionery deficit I The plan was: I Count the total number of each colour I Eat the Smarties (Sorry!)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ANOVA Data Setup I How would the data have been set up? I
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Historical Smarties data, from three boxes count <- c ( 4 , 3 , 4 , 3 , 1 , 4 , 2 , 5 , 1 , 1 , 2 , 4 ) colour <- as.factor ( c ( rep ( "Yellow" , 3 ), rep ( "Purple" , 3 ), rep ( "Green" , 3 ), rep ( "Pink" , 3 ))) #Get means for each flavour sapply ( split (count,colour),mean) ## Green Pink Purple Yellow ## 2.666667 2.333333 2.666667 3.666667
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Estimating Treatment Effects in ANOVA using Regression I y ij is the j th observation under the i th treatment I The model for Smarties: y ij = μ + τ i + ϵ ij , ϵ ij ∼ N ( 0 , σ 2 ) I This can be written in terms of the dummy variables { X 1 , X 2 , X 3 } , as: y ij = μ + τ 1 X 1 j + τ 2 X 2 j + τ 3 X 3 j + ϵ ij I What are y ij , μ, τ i , X ij , ϵ ij ?
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Review: ANOVA Assumptions 1. Additive model y ij = μ + τ i + ϵ ij 2. Errors are iid with common variance I The errors ϵ ij are independent and identically distributed (iid) I Common variance Var ( ϵ ij ) = σ 2 , for all i , j 3. Errors are normally distributed ϵ ij ∼ N ( 0 , σ 2 )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The ANOVA Table I In the previous lecture, we used aov to construct the ANOVA table I The alternative function anova has different syntax and different scope in what it can do, but for present purposes will compute the same values I A third way is to use lm directly; all are adequate #ANOVA table anova ( lm (count~colour)) ## Analysis of Variance Table ## ## Response: count ## Df Sum Sq Mean Sq F value Pr(>F) ## colour 3 3.000 1.0000 0.4286 0.7381 ## Residuals 8 18.667 2.3333
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Dummy Coding I Dummy coding compares each level to the reference level. The intercept is the mean of the reference group. I Dummy coding is the default in R and the most common coding scheme. It compares each level of the categorical variable to a fixed reference level. contrasts (colour) <- contr.treatment ( 4 ) #Treatment contrast contrasts (colour) # print dummy coding, ie a contrast matrix ## 2 3 4 ## Green 0 0 0 ## Pink 1 0 0 ## Purple 0 1 0 ## Yellow 0 0 1 lm (count~colour) ## ## Call: ## lm(formula = count ~ colour) ## ## Coefficients: ## (Intercept) colour2 colour3 colour4 ## 2.667e+00 -3.333e-01 4.710e-16 1.000e+00
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Deviation coding I This coding system compares the mean of the dependent variable for a given level to the overall mean of the dependent variable contrasts (colour) <- contr.sum ( 4 ) # Deviation contrast contrasts (colour) # print deviation coding, again a contrast matrix ## [,1] [,2] [,3] ## Green 1 0 0 ## Pink 0 1 0 ## Purple 0 0 1 ## Yellow -1 -1 -1 lm (count~colour) ## ## Call: ## lm(formula = count ~ colour) ## ## Coefficients: ## (Intercept) colour1 colour2 colour3 ## 2.8333 -0.1667 -0.5000 -0.1667
.