Workshop 7.6b: Factorial ANOVA (Bayesian)

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 (\(\eta=\mu\))

XXX (\(\eta=\mu - \beta_2\))

XXX (\(\eta=\mu - \beta_3\))

High temp

XXX (\(\eta=\mu - \alpha_2\))

XXX (\(\eta=\mu - \alpha_2 - \beta_2 - \gamma_{2,2}\))

XXX (\(\eta=\mu - \alpha_2 - \beta_3 - \gamma_{2,3}\))

\[ \begin{align} y_{ijk} &\sim{} N(\eta_{ijk}, \sigma^2)\\ \eta_{ijk} &= \mu + \sum_{j=2}^J \alpha_j \textbf{T}_j + \sum_{k=2}^K \beta_k \textbf{N}_k \\ &+ \sum_{j=2,k=2}^{J\times K} \gamma_{jk} \textbf{TN}_{jk} \end{align} \]

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      

(Bayesian) linear model

Two-factor

  Low N Medium N High N

Low temp.

Low (\(\eta=\alpha\))

Low (\(\eta=\alpha - \beta_3\))

(\(\eta=\alpha - \beta_4\))

High temp

Low (\(\eta=\alpha - \beta_2\))

Low (\(\eta=\alpha - \beta_2 - \beta_3 - \beta_5\))

(\(\eta=\alpha - \beta_2 - \beta_4 - \beta_6\))

\[ y_{ij} \sim{} N(\eta_{ij}, \color{darkorange}{\sigma^2})\\ \eta_{ij} = \color{darkorange}{\alpha} + \color{darkorange}{\mathbf{\beta}} X \]

\[ \begin{align} \color{darkorange}{\alpha} &\sim{} N(0,1000)\\ \color{darkorange}{\beta_j} &\sim{} N(0,1000)\\ \color{darkorange}{\sigma^2} &\sim{} cauchy(0,4)\\ \end{align} \]

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_{ij} \sim{} N(\eta_{ij}, \color{darkorange}{\sigma^2})\\ \eta_{ij} = \color{darkorange}{\alpha} + \color{darkorange}{\mathbf{\beta}} X \]

\[ \begin{align} \color{darkorange}{\alpha} &\sim{} N(0,1000)\\ \color{darkorange}{\beta_j} &\sim{} N(0,1000)\\ \color{darkorange}{\sigma^2} &\sim{} cauchy(0,4)\\ \end{align} \]

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) \]