I've tried to create three models (using R): an intercept only linear regression, a simple mixed effects regression and a by-subject effects mixed effects regression.
An intercept only regression models the grand mean of a response variable plus error. In mtcars
, the variable drat
may be considered a response variable. In the model below, have I correctly modelled the grand mean of drat
, plus error?
interceptOnly <- lm(drat ~ 1, data=mtcars)
A simple mixed effects regression models the grand mean of a response variable, plus subject deviation, plus error. In mtcars
, drat
may be considered a response variable and cyl
a subject deviation. In the model below, have I correctly modelled the grand mean of drat
, plus the deviation of cyl
from drat
, plus error?
library(lme4)
simpleMixedEffects <- lmer(drat ~ (1|cyl), data=mtcars)
A by-subject effects mixed effects regression models the grand mean of a response variable, plus subject deviation, plus condition effect, plus error. In mtcars
, drat
may be considered a response variable, cyl
a subject deviation and wt
a condition effect. In the model below, have I correctly modelled the grand mean of drat
, plus the deviation of cyl
from drat
, plus the effect of wt
, plus error?
bySubjectMixedEffects <- lmer(drat ~ (1|cyl) + wt, data=mtcars)
I have one further question:
How can I model a by-subject varying condition effect model. This is a mixed effects model which models the grand mean of a response variable, plus group deviation from grand mean (random effect), plus condition effect (fixed effect), plus group deviation from condition effect (random effect), plus error. Could someone provide R code that outputs a "by-subject varying condition effect model"?
mtcars
. $\endgroup$ – Nick Cox Jun 18 '13 at 10:41mtcars
dataset. $\endgroup$ – luciano Jun 18 '13 at 10:51