11
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ 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") $\endgroup$ Commented May 17, 2011 at 20:11
  • $\begingroup$ it's a really old post but if someone else like me end up here he/she might like this one too rpsychologist.com/… $\endgroup$
    – Lefty
    Commented Sep 17, 2020 at 12:31

2 Answers 2

13
$\begingroup$

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)
$\endgroup$
3
  • $\begingroup$ 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 $\endgroup$
    – Tu.2
    Commented May 17, 2011 at 21:19
  • 4
    $\begingroup$ 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. $\endgroup$ Commented May 18, 2011 at 14:40
  • $\begingroup$ Hi, This is a great explanation. Thank you very much. $\endgroup$
    – Tu.2
    Commented May 18, 2011 at 17:03
2
$\begingroup$

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)
$\endgroup$
1
  • $\begingroup$ Hi mpiktas, thank you for your response but the R result is very different from SAS proc mixed procedure. The SAS output is the same with the answer in a textbook(Kuehk RO. 1999. Design of experiments: statistical principles of research design and analysis, 2nd edition). The dataset is method day level 1 1 142.3 1 1 144.0 1 2 134.9 1 2 146.3 1 3 148.6 1 3 156.5 1 4 152.0 1 4 151.4 2 1 142.9 2 1 147.4 2 2 125.9 2 2 127.6 2 3 135.5 2 3 138.9 2 4 142.9 2 4 142.3 $\endgroup$
    – Tu.2
    Commented May 17, 2011 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.