The two-way treatment effects model assumes \[
Y_{ijk} = \mu + \tau_i + \gamma_j + (\tau\gamma)_{ij} + \varepsilon_{ijk}
\] for \(i = 1,\dots,a\), \(j = 1,\dots,b\), and \(k = 1,\dots,n_{ij}\), where
\(Y_{ijk}\) is the response for EU \(k\) under level \(i\) of A and level \(j\) of B.
\(\mu\) represents a baseline or overall mean.
The \(\tau_i\) are the main effects for Factor A.
The \(\gamma_j\) are the main effects for Factor B.
The \((\tau\gamma)_{ij}\) are the interaction effects between A and B.
The \(\varepsilon_{ijk}\) are \(\mathcal{N}(0,\sigma^2)\) error terms.
Now suppose \(n_{ij}\) are not all the same, so the design is unbalanced.
Mice
In the mice example \(a = b = 2\). We want parameter estimates \(\hat \mu\), \(\hat \tau_i\), \(\hat \gamma_j\), and \(\hat{(\tau\gamma)}_{ij}\) which satisfy
We have the decomposition \(\operatorname{SS}_{\operatorname{Tot}}= \operatorname{SS}_{\operatorname{Trt}}+ \operatorname{SS}_{\operatorname{Error}}\).
The Analysis of Variance (ANOVA) table
Obtain the MS values by dividing the SS values by the Df values.
Reject \(H_0\): \(\mu_{ij}\) all the same if \(F_{\operatorname{stat}}> F_{ab-1,N-ab,\alpha}\).
In the unbalanced case we have \(N = \sum_{i=1}^a\sum_{j=1}^b n_{ij}\) in place of \(abn\).
Note that \(\hat \sigma^2 = \operatorname{MS}_{\operatorname{Error}}\).
Main effect sums of squares under unbalancedness
In the balanced case, we decomposed \(\operatorname{SS}_{\operatorname{Trt}}\) as \(\operatorname{SS}_{\operatorname{A}}+ \operatorname{SS}_{\operatorname{B}}+ \operatorname{SS}_{\operatorname{AB}}\).
No such “clean” decomposition of \(\operatorname{SS}_{\operatorname{Trt}}\) under unbalancedness.
Specifically, it is not obvious how to define \(\operatorname{SS}_{\operatorname{A}}\) and \(\operatorname{SS}_{\operatorname{B}}\).
Three versions of \(\operatorname{SS}_{\operatorname{A}}\) and \(\operatorname{SS}_{\operatorname{B}}\) measure main effect importance:
Sequentially
After other main effect in the absence of interaction
After other main effect in the presence of interaction
These are called Type I, Type II, and Type III sums of squares.
Type I/II/III SS for main effects
Each is a full/reduced model difference in SS.
To define them, we introduce the notation: Let
\(\operatorname{SS}_{\operatorname{Error}}(A)\) denote \(\operatorname{SS}_{\operatorname{Error}}\) from model with only A main effects.
\(\operatorname{SS}_{\operatorname{Error}}(B)\) denote \(\operatorname{SS}_{\operatorname{Error}}\) from model with only B main effects.
\(\operatorname{SS}_{\operatorname{Error}}(A,B)\) denote \(\operatorname{SS}_{\operatorname{Error}}\) from model with A,B main effects .
\(\operatorname{SS}_{\operatorname{Error}}(A,B,AB)\) denote \(\operatorname{SS}_{\operatorname{Error}}\) from full model.
Note that \(\operatorname{SS}_{\operatorname{Tot}}\) is \(\operatorname{SS}_{\operatorname{Error}}\) from the model with no effects.
Type I SS
Type I SS values are meaningless for unbalanced designs!
The Type I sums of squares \(\operatorname{SS}_{\operatorname{A}}^{\operatorname{I}}\) and \(\operatorname{SS}_{\operatorname{B}}^{\operatorname{I}}\) are defined as follows:
If \(A\) enters first and then \(B\), then \[\begin{align*}
\operatorname{SS}_{\operatorname{A}}^{\operatorname{I}} &= \operatorname{SS}_{\operatorname{Tot}}- \operatorname{SS}_{\operatorname{Error}}(A) \\
\operatorname{SS}_{\operatorname{B}}^{\operatorname{I}} &= \operatorname{SS}_{\operatorname{Error}}(A) - \operatorname{SS}_{\operatorname{Error}}(A,B)
\end{align*}\]
If \(B\) enters first and then \(A\), then \[\begin{align*}
\operatorname{SS}_{\operatorname{B}}^{\operatorname{I}} &= \operatorname{SS}_{\operatorname{Tot}}- \operatorname{SS}_{\operatorname{Error}}(B) \\
\operatorname{SS}_{\operatorname{A}}^{\operatorname{I}} &= \operatorname{SS}_{\operatorname{Error}}(B) - \operatorname{SS}_{\operatorname{Error}}(A,B)
\end{align*}\]
When the design is balanced the order of entrance does not matter.
Mice
Obtain the Type I SS when Gene is added and then Diet.
Fit model with no effects:
lm_none <-lm(Response ~1, data = adipoer)SST <-sum(lm_none$residuals^2)
Fit model with just Gene:
lm_Gene <-lm(Response ~ Gene, data = adipoer)SSE_Gene <-sum(lm_Gene$residuals^2)SS_Gene <- SST - SSE_Gene # take difference in SSE
The total SS is reduced by \(1.273\times 10^{5}\).
Fit model with Gene and Diet:
lm_Gene_Diet <-lm(Response ~ Gene + Diet, data = adipoer)SSE_Gene_Diet <-sum(lm_Gene_Diet$residuals^2)SS_Diet <- SSE_Gene - SSE_Gene_Diet # take difference in SSE
The error SS is reduced by \(1.253\times 10^{6}\).
Mice
Obtain the Type I SS when Diet is added and then Gene.
Fit model with no effects:
lm_none <-lm(Response ~1, data = adipoer)SST <-sum(lm_none$residuals^2)
Fit model with just Diet:
lm_Diet <-lm(Response ~ Diet, data = adipoer)SSE_Diet <-sum(lm_Diet$residuals^2)SS_Diet <- SST - SSE_Diet # take difference in SSE
The total SS is reduced by \(1.27\times 10^{6}\).
Fit model with Diet and Gene:
lm_Gene_Diet <-lm(Response ~ Gene + Diet, data = adipoer)SSE_Gene_Diet <-sum(lm_Gene_Diet$residuals^2)SS_Gene <- SSE_Diet - SSE_Gene_Diet # take difference in SSE
The error SS is reduced by \(1.107\times 10^{5}\).
Mice
Obtain the Type I SS on the mice data using anova() function.
anova(lm(Response ~ Gene + Diet + Gene:Diet, data = adipoer))
Measures contribution of each main effect in absence of interaction.
The Type II sums of squares \(\operatorname{SS}_{\operatorname{A}}^{\operatorname{II}}\) and \(\operatorname{SS}_{\operatorname{B}}^{\operatorname{II}}\) are given by \[\begin{align*}
\operatorname{SS}_{\operatorname{A}}^{\operatorname{II}} &= \operatorname{SS}_{\operatorname{Error}}(B) - \operatorname{SS}_{\operatorname{Error}}(A,B)\\
\operatorname{SS}_{\operatorname{B}}^{\operatorname{II}} &= \operatorname{SS}_{\operatorname{Error}}(A) - \operatorname{SS}_{\operatorname{Error}}(A,B)
\end{align*}\]
Mice
Obtain the Type II SS on the mice data.
Fit a one-way model for each factor:
lm_Diet <-lm(Response ~ Diet, data = adipoer)SSE_Diet <-sum(lm_Diet$residuals^2)lm_Gene <-lm(Response ~ Gene, data = adipoer)SSE_Gene <-sum(lm_Gene$residuals^2)
Fit a model with both main effects (but no interaction):
lm_Diet_Gene <-lm(Response ~ Diet + Gene, data = adipoer)SSE_Diet_Gene <-sum(lm_Diet_Gene$residuals^2)SS_Diet <- SSE_Gene - SSE_Diet_Gene # take difference in SSESS_Gene <- SSE_Diet - SSE_Diet_Gene # take difference in SSE
Including Diet after Gene reduces error SS by \(1.253\times 10^{6}\).
Including Gene after Diet reduces error SS by \(1.107\times 10^{5}\).
Mice
Obtain Type II SS with Anova() function from R package car.
In the unbalanced case we should use the so-called Type III SS.
Measures contribution of each main effect in presence of interaction.
The Type III sums of squares \(\operatorname{SS}_{\operatorname{A}}^{\operatorname{III}}\) and \(\operatorname{SS}_{\operatorname{B}}^{\operatorname{III}}\) are given by \[\begin{align*}
\operatorname{SS}_{\operatorname{A}}^{\operatorname{III}} &= \operatorname{SS}_{\operatorname{Error}}(B,AB) - \operatorname{SS}_{\operatorname{Error}}(A,B,AB)\\
\operatorname{SS}_{\operatorname{B}}^{\operatorname{III}} &= \operatorname{SS}_{\operatorname{Error}}(A,AB) - \operatorname{SS}_{\operatorname{Error}}(A,B,AB)
\end{align*}\]
Type III SS (cont)
Type III SS are tedious to obtain in the unbalanced case; they are like full-reduced model differences in the error sum of squares, where the reduced model is the model without the main effect in question.
The anova() or aov() functions in R give sequential SS, which are not meaningful in the unbalanced case; however, the Type III SS are equal to the sequential (i.e. Type I) SS when \(n_{ij} = n ~\forall ij\).
Under unbalancedness \(\operatorname{SS}_{\operatorname{Trt}}\neq \operatorname{SS}_{\operatorname{A}}^{\operatorname{III}} + \operatorname{SS}_{\operatorname{B}}^{\operatorname{III}} + \operatorname{SS}_{\operatorname{AB}}\).
Single term deletions
Model:
Response ~ Diet + Gene + Diet:Gene
Df Sum of Sq RSS AIC F value Pr(>F)
<none> 4653342 632
Gene 1 105749 4759091 631 1.16 0.29
Drop main effect of Diet from the model:
drop1(lm_full,~Diet,test="F",data = adipoer)
Single term deletions
Model:
Response ~ Diet + Gene + Diet:Gene
Df Sum of Sq RSS AIC F value Pr(>F)
<none> 4653342 632
Diet 1 1253698 5907040 643 13.7 0.00052 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Mice
Obtain Type III SS with Anova() from the R package car.