a simple question about mixed effects and interactions Suppose I have the following model written in lme4-like formula syntax:
Outcome = year + categorical_variable + year : categorical variable + (year | group), 
where categorical variable is a three level variable: 'x', 'y', and 'z'.
In this case, the coefficient for year in the output is for the baseline level of the categorical variable (in this case 'x'). 
Now my question is, would the random effect only be random effect in relation to the mean of 'x' or the mean of year with relation to 'x', 'y', and 'z'?
 A: Let's first write the model conditional on the random effects in a mathematical formulation, i.e., $$\begin{eqnarray}
\texttt{Outcome}_{ij} & = &\beta_0 + \beta_1 \texttt{year}_{ij} + \beta_2 \texttt{Dy}_i + \beta_3 \texttt{Dz}_i + \beta_4 \{\texttt{year}_{ij} \times \texttt{Dy}_i\} + \beta_5 \{\texttt{year}_{ij} \times \texttt{Dz}_i\} +\\
&&b_{i0} + b_{i1} \texttt{year}_{ij} + \varepsilon_{ij},
\end{eqnarray}$$ $\texttt{Dy}_i$ is the dummy variable for level 'y', $\texttt{Dz}_i$ the dummy variable for level 'z', $b_{i0}$ is the random intercepts, and $b_{i1}$ the random slopes for $\texttt{year}_{ij}$.
If you write the model for level 'x', you get:
$$\texttt{Outcome}_{ij} = (\beta_0 + b_{i0}) + (\beta_1 + b_{i1}) \texttt{year}_{ij} + \varepsilon_{ij},$$
and for level 'y' you get:
$$\texttt{Outcome}_{ij} = (\beta_0 + \beta_2 \texttt{Dy}_i + b_{i0}) + (\beta_1 + \beta_4 \texttt{Dy}_i + b_{i1}) \texttt{year}_{ij} + \varepsilon_{ij},$$
and similarly for level 'z'.
Hence, as you see, the random effects represent how subjects / sample units deviate from their group mean.
