# How to specify random effects in lme?

I have searched for this online for hours but none of online posts is what I am looking for. My question is very easy to implement in SAS Proc mixed procedure but I am not sure how to do it in lme and/or lmer packages. Assume, I have a model, $y = \mu + \alpha + \beta +\alpha\beta + e$, where $\alpha$ is fixed but $\beta$ and $\alpha\beta$ are random. My R code is

 f1 = lme(y ~ factor(a), data = mydata,
random = list(factor(b) = ~ 1, factor(a):factor(b) = ~ 1))


Error: unexpected = in:

 f1 = lme(y ~ factor(a), data = mydata,
random = list(factor(a) =


Could someone please tell me how to specify these random effects in lme? many thanks in advance

-
It helps to use dput to get the code needed to recreate your data. From the comment you left, the result is structure(list(method = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("1", "2"), class = "factor"), day = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L), .Label = c("1", "2", "3", "4"), class = "factor"), level = c(142.3, 144, 134.9, 146.3, 148.6, 156.5, 152, 151.4, 142.9, 147.4, 125.9, 127.6, 135.5, 138.9, 142.9, 142.3)), .Names = c("method", "day", "level"), row.names = c(NA, -16L), class = "data.frame") –  Aaron May 17 '11 at 20:11
Aaron, Thank you. –  Tu.2 May 17 '11 at 21:14

Try this, it's a standard way to do a split plot. The notation / means that method is nested in day.

lme(level~method, random=~1|day/method, data=d)

-
Hi Aaron, Thank you very much. Your R output is exactly the same with SAS output and the textbook. But Why we have to use "nested" in R syntax. Because in the textbook, it clearly states that $\alpha\beta$ is an random interaction term and I also use random interaction term in SAS. Could you please tell me why/how to specify an random interaction effect in lme, if it is possible? many many thanks Tu.2 –  Tu.2 May 17 '11 at 21:19
Your question isn't about R syntax, it's about what nesting means. Nesting B in A (with A/B) creates two variables, A and the interaction between A and B, which is exactly what you describe. –  Aaron May 18 '11 at 14:40
Hi, This is a great explanation. Thank you very much. –  Tu.2 May 18 '11 at 17:03
It would help a lot if you provided a data.frame. Now it is not clear what is a grouping factor. I judge that it is $\beta$. Then in lme notation your model should be written as follows:
lme(y~a,random=~a|b, data=mydata)