[R] Syntax for lme function to model random factors and interactions

Peter Ehlers ehlers at ucalgary.ca
Tue May 22 00:37:04 CEST 2012


Inline:

On 2012-05-21 11:17, i_like_macs wrote:
> Hello Joshua,
>
> Many thanks for your help, especially from a fellow Bruin (I went there as
> an undergrad!).
>
> I understand that there is another forum for mixed models. If my problem
> can't be solved within this thread, I'll have to go there. I do understand
> some theory about mixed models, but obviously am far from an expert.
>
> My question is not so much statistical advice, as it concerns the correct
> syntax to include random factors and interactions (which include these
> random factors) for the lme function. Maybe it's because I'm used to SPSS,
> but I find R very difficult to use, even after looking up its built-in help.

Just a small comment, since you're interested in correct syntax:
you apparently consider A*B to represent the (A,B)
interaction term; in R, it's A:B and this *is* clearly documented
in the help pages.

Peter Ehlers

>
> I could run your neat code suggestion:
>
> lme(Y ~ (A + B + C + D)^3, data = myData, random = ~ 1 | C, method = "ML")
>
> but would like to know how to also include "D" as a random factor. My
> understanding is that the "random" argument for the lme function is coded
> as:
>
> ~ x1 + ... + xn | g1 / ... / gm
>
> where the left side describes the model for random effects, and the right
> side describes the grouping structure. Reading other posts, I learned that I
> need both sides for the code to run without errors. However, it's not clear
> to me what both sides represent. The left side appears to be where the
> random factors are specified, perhaps like this:
>
> random = ~ C + D
>
> But then this results in errors. Does this mean I have to somehow join the
> two following lines of code to specify both random factors?
>
> random = ~ 1 | C
> random = ~ 1 | D
>
> It's not clear what the "~ 1" represents here, as I would have guessed that
> this is where the random factors would be specified. Is this related to an
> intercept-only model?
>
> I'm sorry for sounding so lost. This is because I am. Perhaps I need to know
> more theory of mixed models, but this seems to be possible only if I
> understand what parts of the lme function are.
>
> Thank you very much again,
>
> Daisuke
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Syntax-for-lme-function-to-model-random-factors-and-interactions-tp4630744p4630789.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.



More information about the R-help mailing list