[R] lmer with random slopes for 2 or more first-level factors?
ONKELINX, Thierry
Thierry.ONKELINX at inbo.be
Wed Aug 19 10:47:14 CEST 2009
Dear Jason,
Both models have a correct syntax. Although I would write the last model
rather as lmer(DV ~ IV1 + IV2 + (1|Subject) + (IV1 - 1| Subject) + (IV2
- 1| Subject))
The only difference is indeed the correlation between the random
effects. The random effects in the model I wrote are all independent
(not correlated). In your first model all random effects are correlated.
In your second model the first random intercept is correlated with the
random slope of IV1. The second random intercept with the random slope
of IV2.
Depending on if you want your interaction to be indepentend or not your
can use either
lmer(DV ~ IV1 + IV2 + (IV1 * IV2 | Subject))
lmer(DV ~ IV1 + IV2 + (1 | Subject) + (IV1 -1 | Subject) + (IV2 - 1|
Subject) + (IV1:IV2 - 1| Subject))
Note that IV1 * IV2 is equivalent to 1 + IV1 + IV2 + IV1:IV2
HTH,
Thierry
PS R-Sig-mixed-models is a better list for this kind of questions.
------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx at inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey
-----Oorspronkelijk bericht-----
Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
Namens Jason R. Finley
Verzonden: woensdag 19 augustus 2009 3:47
Aan: r-help at r-project.org
Onderwerp: [R] lmer with random slopes for 2 or more first-level
factors?
I have data from a design in which items are completely nested within
subjects. Subject is the only second-level factor, but I have multiple
first-level factors (IVs). Say there are 2 such independent variables
that I am interested in. What is the proper syntax to fit a
mixed-effects model with a by-subject random intercept, and by-subject
random slopes for both the 2 IVs?
I can think of at least two possibilities:
lmer(DV ~ IV1 + IV2 + (1 + IV1 + IV2 | Subject))
lmer(DV ~ IV1 + IV2 + (1 + IV1 | Subject) + (1 + IV2 | Subject))
Or maybe there is some other way to do it? Maybe the correct syntax
depends on whether the random effect of subjects on the intercept and
slopes are correlated or not? (If so, how do I proceed?)
Finally, what would be the syntax if I wanted to include a random
subject effect for the INTERACTION of IV1 and IV2?
Thanks very much,
~jason
PS: additional search terms: multi-level linear model, MLM,
hierarchical, repeated measures
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jason R. Finley
Department of Psychology
University of Illinois, Urbana-Champaign
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in this message
and any annex are purely those of the writer and may not be regarded as stating
an official position of INBO, as long as the message is not confirmed by a duly
signed document.
More information about the R-help
mailing list