# Formula symbols for mixed model using lme4

Edit Note: Since I posted this question, I have being suggested to read some of documents and I am still thinking on the subject. I have added some new understanding as marked between *** astriks, please do correct them if I am wrong and add remaining questions.*

I often confuse with four symbols, ":", "|", "/" and "*" in the formula, particularly while doing mixed model. Can somebody explain it clearly difference between them. I have following working example:

require(lme4)
mydata <- expand.grid(xvar1 =factor(1:10), xvar2 =factor(1:3),replication = factor(1:3))
mydata\$yvar <- rnorm(nrow(mydata), 10, 5)

fm1 <- lmer(yvar ~ 1 + (1|xvar1) + (1|xvar2) + (1|xvar1:xvar2), mydata)
***My understanding: Cross classification between xvar1, xvar2***

fm2 <- lmer(yvar ~ 1 + (1|xvar1) + (1|xvar2) + (1|xvar1/xvar2), mydata)
***is not correct model, should remove 1|xvar1, 1|xvar2***
***** has fixed intercept 1 , I do not know if it correct technically**
**fm2 <- lmer(yvar ~ 1 + (1|xvar1/xvar2), mydata)*****
*is xvar1 is nested in xvar2 and is essentially same as fm1*

fm3 <- lmer(yvar ~ 1 + (1|xvar1) + (1|xvar2) + (xvar1|xvar2), mydata)
Warning message:
In mer_finalize(ans) : singular convergence (7)
***I do not have idea on "|",***

fm4 <- lmer(yvar ~ 1 + (1|xvar1) + (1|xvar2) + xvar1:xvar2, mydata)
Error in mer_finalize(ans) : Downdated X'X is not positive definite, 31 ;
***xvar1:xvar2 interaction term, technically correct !***

fm5 <- lmer(yvar ~ 1 + (1|xvar1) + (1|xvar2) + (1|xvar1*xvar2), mydata)
Error in validObject(.Object) :
invalid class "ngTMatrix" object: all row indices must be between 0 and nrow-1
In Ops.factor(xvar1, xvar2) : * not meaningful for factors
**again (1|xvar1) and (1|xvar2) are not necessary**
***fm5 <- lmer(yvar ~  1 + (1|xvar1*xvar2), mydata) is equal to***
***fm5 <- lmer(yvar ~ 1 + (1|xvar1) + (1|xvar2)+ (1|xvar1*xvar2)***

fm6 <- lmer(yvar ~ 1 + (1|xvar1) + (1|xvar2) + (xvar1/xvar2), mydata)
***same as fm2***

fm7 <- lmer(yvar ~ 1 + (1|xvar1) + (1|xvar2) + (0 + xvar1|xvar2), mydata)
Warning message:
In mer_finalize(ans) : singular convergence (7)
***I have no idea on xvar1|xvar2, 0 means no intercept I believe***


Edits: Here is something I learned from R documentation on linear model formula

(1) yvar ~ xvar1 + xvar2 + xvar1:xvar2  - cross over classification
is same as yvar ~ xvar1 * xvar2

(2) yvar ~ xvar1 / xvar2  - nested classification (
however means xvar1 + xvar2 + xvar1:xvar2)
is same as yvar ~ xvar1 %in% xvar2


I am not sure these applicable to lm model holds true for mixed model.

I am still not on track on use of "|" which is I believe unique in mixed models.

-
Just to link to a related thread where Mike Lawrence provided a pretty nice overview of R's formula for mixed-effects models. – chl Nov 15 '11 at 21:19
thanks for the suggestion, I am trying to grasp something of it. – John Nov 16 '11 at 1:58
CAN SOMEBODY HELP TO MOVE THIS QUESTION TO STACKOVERFLOW ...It might be suitable question for there.. – John Nov 17 '11 at 2:14
John, I think this should stay here. You may have to wait some days before getting a response. – chl Nov 17 '11 at 8:22
ok..waiting for response – John Nov 18 '11 at 2:40

The | symbol indicates a grouping factor in mixed methods.

As per Pinheiro & Bates:

...The formula also designates a response and, when available, a primary covariate. It is given as

response ~ primary | grouping


where response is an expression for the response, primary is an expression for the primary covariate, and grouping is an expression for the grouping factor.

Depending on which method you use to perform mixed methods analysis in R, you may need to create a groupedData object to be able to use the grouping in the analysis (see the nlme package for details, lme4 doesn't seem to need this). I can't speak to the way you have specified your lmer model statements because I don't know your data. However, having multiple (1|foo) in the model line is unusual from what I have seen. What are you trying to model?

-