On 1/18/07, w jj <jiajiehere at hotmail.com> wrote:
> I have a question about the function lme() in R.
>
> I have a 2*2*3 layout with some missing data (labelled as *). These 3
> factors are labelled as A,B,C, the response is Score. The layout is as
> follows:-
>
> A B C Score
> 1 1 1 5
> 1 1 2 *
> 1 1 3 1
> 1 2 1 4
> 1 2 2 4
> 1 2 3 *
> 2 1 1 3
> 2 1 2 *
> 2 1 3 4
> 2 2 1 2
> 2 2 2 *
> 2 2 3 5
>
> Suppose these data are stored in a data frame called "test".
>
> If all these 3 factors are fixed, then I can fit a model without the 3-way
> interaction as:-
> fit1<-lm(Score~A*B+A*C+B*C,data=test)
>
> If one of these factors, say A, is a random effect variable, then I need to
> fit a mixed effect model using lme(). I have read the R documention on
> lme(), but I am still not clear how to specify the random argument. I tried
> to do:-
You could do it but you don't really want to try to fit a model with
several random effects generated by a factor with only two levels.
Estimating variances, which is what is done for a random effect, is
more difficult than estimating means or other linear combinations of
the responses, which is what fixed effects parameters end up being
expressed as. Trying to estimate a variance when observing a factor
at only two levels is overly optimistic.
Just for the record, the call to lmer in the lme4 package would be
fit2 <- lmer(Score ~ B*C+(1|A/B)+(1|C:A), data = test)
> fit2<-lme(Score~A*B+A*C+B*C,data=test,random=~A, na.action=na.pass)
I don't think you want to use na.pass here. The underlying C code for
fitting lme or lmer models doesn't take kindly to finding NA's in the
data.
>
> but the system give a message as follows:-
> Error in getGroups.data.frame(dataMix, groups) :
> Invalid formula for groups
>
> So how should I specify the arguments?
>
> Thank you very much for your help!
>
> Jiajie
>
>
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
>
>