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

i_like_macs dkoya at mac.com
Mon May 21 15:03:22 CEST 2012


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

--
View this message in context: http://r.789695.n4.nabble.com/Syntax-for-lme-function-to-model-random-factors-and-interactions-tp4630744.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list