FAQ/subsrandom - CBU statistics Wiki
Self: FAQ/subsrandom

Using subjects as a random or fixed factor in an ANOVA

Any factor in an ANOVA can be either fixed or random. Repeated measures analysis is a mixed model because, firstly, we have a treatment factor, which is usually considered a fixed effect. Second, the subject factor is considered as a random effect. Models with fixed and random effects are mixed models.

One way to see that subjects are always treated as random effects is to fit a repeated measures analysis of variance with the repeated factor, time, treated as fixed.

For example we may wish to compare performance across 4 time points completed by each subject (in the data set here.) To fit a one-way repeated measures anova with one fixed factor, time and treating subjects as a fixed factor we can use the aov() procedure in R as below assuming the data is in a folder called data on the hard drive.

library(nlme)
library(lme4)
library(foreign)
dva <- read.spss("c:\\data\\DUMMY DATA 2.sav")
attach(dva)
t1 <- as.factor(time)
id1 <- as.factor(id)
aov.mod <- aov(y ~ t1 + Error(id1/t1), data=dva)
summary(aov.mod)

We can fit the same model, explicitly mentioning subjects are a random sample having random intercepts indicating a random set of abilities on a particular test. We can use lme() in R to fit this model using the same data as above and again treating the time factor as fixed.

library(nlme)
library(lme4)
library(foreign)
dva2 <- lme(y ~ t1, data=dva, random = ~ 1|id) 
summary(dva2)
anova(dva2)

These models are identical giving the same output and fits. It seems sensible to treat subjects a random since we cannot usually smaple all subjects from a population so usually wish to generalize from the sample in our study.

When all the factors are fixed we can use a fixed effects (the usual) analysis of variance and we are only interested in the groups in the study. When one or more factors are random we use an analysis of variance with random effects (also called a multilevel model) and wish to generalize from the groups comprising the random factor in the study.

We can fit both sets of models to fit random or fixed effects models. For example we may wish to compare performance across 4 time points completed by each subject (in the data set here.) To fit a one-way repeated measures anova with one fixed factor, time and treating subjects as a fixed factor we can use the aov() procedure as below assuming the data is in a folder called data on the hard drive.

Reference

Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer. S-PLUS is the forerunner of R and has a very similar syntax. Most of the analysis of variance procedures are common to both packages.

None: FAQ/subsrandom (last edited 2013-03-08 10:17:30 by localhost)