[R] How to conctruct an inner grouping for nlme random statement?
Douglas Bates
bates at stat.wisc.edu
Wed Feb 23 19:28:12 CET 2005
JJ wrote:
> Hello. Im hoping someone can help with a grouping
> question related to the "random=" statement within the
> nlme function. How do you specify that some grouping
> levels are inner to others? I tried several things,
> given below.
>
> Lets say I have a data frame with five variables,
> resp, cov1, ran1, ran2, group1, and group 2. The
> formula is resp~cov1 + ran1 + ran2, where the ran are
> random variables. The data is of length 80, and there
> are 4 unique factors in group1 and 20 unique factors
> in group2. These are factors related to ran1 and
> ran2, respectively.
>
> The difficult part is that I want to estimate only 4
> random variables for ran1|group1 and the full 20 for
> ran2|group2. I have tried many ways, and I cannot
> find a way to do this. Is there a way? Can someone
> suggest a code snippet?
>
> First I tried making the data frame a groupedData
> object, so that group2 is inner to group1, as it
> should be. Then I used the statement: random =
> as.formula(ran1+ran2~1). But this produced 20
> estimates for both ran1 and ran2.
>
> I have also tried it without the data frame as a
> groupedData object, using the following:
> random = list(group1= c(ran1~1, group2=ran2~1)). But
> this gave only 4 estimates for ran2. I also tried:
> random = list(c(group1= ran1~1, group2=ran2~1)), but
> this just gave a parse error message.
>
> Any suggestions would be greatly appreciated. Is it
> even possible to do what I want to do? John
I think we will need a bit more information before we are able to help.
I'm not sure what you mean by ran1 and ran2 being random variables and
group1 and group2 being factors related to ran1 and ran2.
The lmer function in the lme4 package allows for specification of a
mixed-effects model using grouping factors and model matrices. The
model matrix determines the form of the random effects vector
corresponding to each of the groups. The grouping factor determines the
groups.
In this specification I'm not sure what your ran1 and ran2 variables
would be. It sounds as if you want a model that would be specified as
fm1 <- lmer(resp ~ cov1 + (1|group1) + (1|group2))
but I'm not sure.
Feel free to correspond directly with me if you wish.
More information about the R-help
mailing list