## 3x2 Factorial, fixed effects

This is a first attempt at an R version of the 3-by-2 fixed effects Factorial model.

See the SAS Factorial example.

Consider that we have 2 factors (s and t), with factor s having 3 levels, and factor t having
2 levels. For each combination of s and t (6 combinations [3*2]) we have multiple independent
experimental units, with one measurement per experimental unit. We see that there are 2 or 3
experimental units per st combination; this allows us to consider, and fit, a factorial model.

R source code for 3*2 Factorial
We make use of several packages: car provides us with Marginal Sums of Squares for our ANOVA;
doBy provides the esticon function which allows us to estimate estimable values; lsmeans which
will provide us with least squares means.

Output from the model fit:

>
> lm2 <- lm(y~s + t + s:t,data=ds)
> anova(lm2) # Type I Sums of Squares
Analysis of Variance Table
Response: y
Df Sum Sq Mean Sq F value Pr(>F)
s 2 0.39067 0.19533 0.9932 0.4042
t 1 1.02564 1.02564 5.2151 0.0455 *
s:t 2 0.73703 0.36851 1.8738 0.2036
Residuals 10 1.96667 0.19667
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> Anova(lm2) # Type II Sums of Squares, ie s and t
Anova Table (Type II tests)
Response: y
Sum Sq Df F value Pr(>F)
s 0.34901 2 0.8873 0.4418
t 1.02564 1 5.2151 0.0455 *
s:t 0.73703 2 1.8738 0.2036
Residuals 1.96667 10
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> # are NOT corrected for the interaction, OK

We consider the Type II Sums of Squares (and ANOVA) provided by the car package
and the Anova(lm2) function to be most appropriate. It is interesting to note that these
Type II Sums of Squares and slightly different from the Type III Sums of Squares
produced by SAS; this is a philosophical issue. There is also the issue of when it
is appropriate to consider the main effects of s and t. The reader should note
that we demonstrate several packages and useages, without a full statistical exposition.

R.I. Cue ©

Department of Animal Science, McGill University

last updated : 2017 July 29^{th}