Workshop 7.6a: Factorial ANOVA

Murray Logan

19 Jul 2017

Background

Factorial ANOVA

Factorial ANOVA

The linear model

Two-factor

  Low N Medium N High N

Low temp.

XXX

XXX

XXX

High temp

XXX

XXX

XXX

\[ y_{ijk} = \mu + \alpha_i + \beta_j + \alpha_i\beta_j + \varepsilon_{ijk} \]

The linear model

Two-factor

  Low N Medium N High N

Low temp.

XXX

XXX

XXX

High temp

XXX

XXX

XXX



 Temp   Nitrogen 
------ ----------
 Low      Low    
 Low      Low    
 Low      Low    
 Low     Medium  
 Low     Medium  
 Low     Medium  
 Low      High   
 Low      High   
 Low      High   
 High     Low    
 High     Low    
 High     Low    
 High    Medium  
 High    Medium  
 High    Medium  
 High     High   
 High     High   
 High     High   
\[ y_{i} = \beta_{0i} + \beta_{1i} + \beta_{2i} + \beta_{3i} + \beta_{4i} + \beta_{5i} + \beta_{6i} + \varepsilon{i} \]

The linear model

Two-factor



 T     N     NA   (Intercept)   THigh   NMedium   NHigh   THigh:NMedium   THigh:NHigh 
---- ------ ---- ------------- ------- --------- ------- --------------- -------------
Low   Low    NA        1          0        0        0           0              0      
Low   Low    NA        1          0        0        0           0              0      
Low   Low    NA        1          0        0        0           0              0      
Low  Medium  NA        1          0        1        0           0              0      
Low  Medium  NA        1          0        1        0           0              0      
Low  Medium  NA        1          0        1        0           0              0      
Low   High   NA        1          0        0        1           0              0      
Low   High   NA        1          0        0        1           0              0      
Low   High   NA        1          0        0        1           0              0      
High  Low    NA        1          1        0        0           0              0      
High  Low    NA        1          1        0        0           0              0      
High  Low    NA        1          1        0        0           0              0      
High Medium  NA        1          1        1        0           1              0      
High Medium  NA        1          1        1        0           1              0      
High Medium  NA        1          1        1        0           1              0      
High  High   NA        1          1        0        1           0              1      
High  High   NA        1          1        0        1           0              1      
High  High   NA        1          1        0        1           0              1      

The linear model

Two-factor

  Low N Medium N High N

Low temp.

XXX

XXX

XXX

High temp

XXX

XXX

XXX

\[ y_{i} = \beta_{0i} + \beta_{1i} + \beta_{2i} + \beta_{3i} + \beta_{4i} + \beta_{5i} + \beta_{6i} + \varepsilon{i} \]

The linear model

Two-factor

  Low N Medium N High N

Low temp.

XXX

XXX

XXX

High temp

XXX

XXX

XXX

\[ y_{ijk} = \mu + \alpha_i + \beta_j + \alpha_i\beta_j + \varepsilon_{ijk} \]

Factorial ANOVA

Factor MS F-ratio (both fixed) F-ratio (A fixed, B random) F-ratio (both random)
A \(MS_A\) \(MS_A/MS_{Resid}\) \(MS_A/MS_{A:B}\) \(MS_A/MS_{A:B}\)
B \(MS_B\) \(MS_B/MS_{Resid}\) \(MS_B/MS_{Resid}\) \(MS_B/MS_{A:B}\)
A:B \(MS_{A:B}\) \(MS_{A:B}/MS_{Resid}\) \(MS_{A:B}/MS_{Resid}\) \(MS_{A:B}/MS_{Resid}\)

Design Balance

Balance

When balanced

\[SS_{TOTAL} = SS_{A} + SS_{B} + SS_{A:B} + SS_{Resid}\]

Factoral ANOVA

Design balance

Factorial ANOVA

Factoral ANOVA

Design balance

Factorial ANOVA

Factorial ANOVA

Assumptions

Worked examples

Worked examples

Format of starling.csv data files
SITUATION MONTH MASS GROUP
S1 November 78 S1Nov
.. .. .. ..
S2 November 78 S2Nov
.. .. .. ..
S3 November 79 S3Nov
.. .. .. ..
S4 November 77 S4Nov
.. .. .. ..
S1 January 85 S1Jan
.. .. .. ..
SITUATION Categorical listing of roosting situations
MONTH Categorical listing of the month of sampling.
MASS Mass (g) of starlings.
GROUP Categorical listing of situation/month combinations - used for checking ANOVA assumptions
Starlings

> starling <- read.csv('../data/starling.csv',strip.white=T)
Error in file(file, "rt"): cannot open the connection
> head(starling)
Error in head(starling): object 'starling' not found

Worked Examples

Question: what effects do roosting situations and season have on the mass of starlings

Linear model:
\[ Mass_{ijk} = \mu + \alpha_i + \beta_j + \alpha_i\beta_j +\varepsilon_{ijk} \hspace{1cm} \varepsilon \sim{} \mathcal{N}(0, \sigma^2) \]

Worked Examples

Format of stehman.csv data files
PH HEALTH GROUP BRATING
3 D D3 0.0
.. .. .. ..
3 H H3 0.8
.. .. .. ..
5.5 D D5.5 0.0
.. .. .. ..
5.5 H H5.5 0.0
.. .. .. ..
7 D D7 0.2
.. .. .. ..

PH Categorical listing of pH (not however that the levels are numbers and thus by default the variable is treated as a numeric variable rather than a factor - we need to correct for this)
HEALTH Categorical listing of the health status of the seedlings, D = diseased, H = healthy
GROUP Categorical listing of pH/health combinations - used for checking ANOVA assumptions
BRATING Average bud emergence rating per seedling
Starlings

> #Worked examples
> stehman <- read.csv('../data/stehman.csv', strip.white=T)
Error in file(file, "rt"): cannot open the connection
> head(stehman)
Error in head(stehman): object 'stehman' not found

Worked Examples

Question: what effects do pH and health have on the bud emergence rating of spruce seedlings

Linear model:
\[ Buds_{ijk} = \mu + \alpha_i + \beta_j + \alpha_i\beta_j +\varepsilon_{ijk} \hspace{1cm} \varepsilon \sim{} \mathcal{N}(0, \sigma^2) \]

Worked Examples

Format of quinn.csv data files
SEASON DENSITY RECRUITS SQRTRECRUITS GROUP
Spring Low 15 3.87 SpringLow
.. .. .. .. ..
Spring High 11 3.32 SpringHigh
.. .. .. .. ..
Summer Low 21 4.58 SummerLow
.. .. .. .. ..
Summer High 34 5.83 SummerHigh
.. .. .. .. ..
Autumn Low 14 3.74 AutumnLow
.. .. .. .. ..
SEASON Categorical listing of Season in which mussel clumps were collected ­ independent variable
DENSITY Categorical listing of the density of mussels within mussel clump ­ independent variable
RECRUITS The number of mussel recruits ­ response variable
SQRTRECRUITS Square root transformation of RECRUITS - needed to meet the test assumptions
GROUPS Categorical listing of Season/Density combinations - used for checking ANOVA assumptions
Mussel

Error in file(file, "rt"): cannot open the connection
Error in head(quinn): object 'quinn' not found

Worked Examples

Question: what effects do season and density have on barnacle recruitment

Linear model:
\[ Recruits_{ijk} = \mu + \alpha_i + \beta_j + \alpha_i\beta_j +\varepsilon_{ijk} \hspace{1cm} \varepsilon \sim{} \mathcal{N}(0, \sigma^2) \]