lmer syntax for a two-way model with one fixed and one random factor Please could anyone tell me if my R code is correct?
I have a two-way model with one fixed factor, habitat, and one random factor, site.  The code I am using is:
lmer (x ~ habitat*site + (1|site))

This appears to be equivalent to: 
lmer x ~ habitat + (1|site) + (1|site:habitat)

Thanks,
Martine
 A: These are different models.  In the first case you are fitting habitat, site, and their interaction as fixed effects, and site also as a random effect (this is a redundant model specification and will cause trouble).  In the second case you are fitting a fixed effect of habitat, a random (intercept) effect of site and a random site $\times$ habitat interaction, or equivalently habitat nested within site; that model looks better posed.
http://glmm.wikidot.com/faq#modelspec might help.
lmer(x ~ habitat*site + (1|site))

corresponds to
$$
\begin{split}
x_{ijk} & \sim \textrm{N}(\mu_{ijk},\sigma_r^2) \\
\mu_{ijk} & = \beta_0 + \beta_h + \beta_s + \beta_{hs} + b \\
b & \sim \textrm{N}(0,\sigma_s^2)
\end{split}
$$
(the fixed-effect specification here is not stated precisely right; the model is really parameterized as an intercept plus a series of indicator/dummy variables $I(h=2), \dots, I(h=n_s)$ where $j$ represents sites not including the first, and similarly for habitats and interactions).
Your second model
lmer(x ~ habitat + (1|site) + (1|site:habitat))

$$
\begin{split}
x_{ijk} & \sim \textrm{N}(\mu_{ijk},\sigma_r^2) \\
\mu_{ijk} & = \beta_0 + \beta_h + b_s + b_{hs} \\
b_s & \sim \textrm{N}(0,\sigma_s^2) \\
b_{hs} & \sim \textrm{N}(0,\sigma_{sh}^2)
\end{split}
$$
The second model is equivalent to x ~ habitat + (1|site/habitat).
