2
$\begingroup$

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"?

$\endgroup$
  • $\begingroup$ More edits made. How can I further improve question? $\endgroup$ – luciano Jun 18 '13 at 10:35
  • 1
    $\begingroup$ As you press me, my personal view is that a good acceptable question will just cite the video as a reference and be focused on questions that other people might ask or difficulties others might express. This looks too much like "Here are some examples I have tried; are they correct?" There are many questions on mixed effects on this site; I can't see this being one of the most useful. Also, you are presupposing some acquaintance with a particular dataset, mtcars. $\endgroup$ – Nick Cox Jun 18 '13 at 10:41
  • $\begingroup$ Question further edited to remove any necessity of familiarity with mtcars dataset. $\endgroup$ – luciano Jun 18 '13 at 10:51
2
$\begingroup$

Your example models seem to be correct.

Your final question concerns varying condition effects. You can include a vayring slope of mt in the model with the following command:

lmer(drat ~ wt + (1 + wt|cyl), data=mtcars)

This model estimates an intercept and a slope for wt. These are the fixed effects. Additionally, the model estimates the deviations from these fixed effect for the levels of cyl. These are the random effects of the model. Furthermore, a parameter for the correlation between the two random effects is also estimated by the model. If you want to exclude this correlation parameter, you have to change the command to:

lmer(drat ~ wt + (1|cyl) + (0 + wt|cyl), data=mtcars)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.