Hello all,

The following (i.e. below the hash marks) is a reposting of something originally posted on the R forum. I was told by a helpful person there to redirect my question to this forum.

My question concerns what the correct expression is to specify two random factors for the lme function. So far I've tried:

	random = ~ 1|C + D

	random = ~ 1 + (1|C) + (1|D)

	random = ~ 1 + 1|C + 1|D

but all of these resulted in errors (mostly of the type "
Error in getGroups.data.frame(dataMix, groups) : Invalid formula for groups"). To be more specific, "C" refers to a subject factor, while "D" refers to a repetition factor (i.e. multiple evaluations of the same stimulus by the same subject). In this case, would the correct way to code this be:

	random = ~ 1|C/D

? Additionally, I would be grateful if someone could tell me whether I have to code the interactions in the "random" argument in the lme function, and if so how.

Thank you very much in advance for the help.

Best regards,

Daisuke

############################################################################

Hello,

I have a question regarding the syntax of the lme function in the nlme package. What I'm trying to do is to calculate an estimate of R^2 based on the likelihood ratio test. For this calculation, I need to determine the maximum log-likelihood of the intercept-only model and the model of interest (with the desired factors and interactions). 

My model has four independent factors (i.e. A, B, C and D). A and B are fixed factors, whilst C and D are random factors. 

Presently, I'm trying to code the lme function for the full ANOVA model, but am unsure how to code both random factors. Additionally, I'm unsure whether I coded the interactions correctly (i.e. I'm unsure whether the interactions which contain random factors also need to be specified in the "random" argument). I've skimmed through the Pinheiro and Bates book, "Mixed-Effects Models in S and S-PLUS", but could not find an answer. 

My R code for the lme function which includes all the main factors and interactions (2- and 3-way) so far is: 

	lme(Y ~	A + 
                B + 
                C + 
                D + 
                A : B + 
                A : C + 
                A : D + 
                B : C + 
                B : D + 
                C : D + 
                A : B : C + 
                A : B : D + 
                A : C : D + 
                B : C : D, 
                data = myData, 
                random = ~ 1|C, 
                method = "ML") 

Can someone help me with how to code the random factors and interactions which contain these random factors please? I apologise in advance, that I am self-taught in statistics, and just started using R. Hence I hope my question made sense. Thank you very much. 

Daisuke Koya 
Confused PhD student

	[[alternative HTML version deleted]]

