Suppose there are $N$ subjects under study, with subject $i$ contribution $n_i$ observations, for $i =1,...,N$. And let $y_{ij}$ denote a response variable for subject $i$ at observation $j$. Let $x_{ij}$ denote a $p\times 1$ vector of predictors, and let $z_{ij}$ denote a $q\times 1$ vector of predictors. In general, the linear mixed effects model is $$y_i=X_i\alpha+Z_i\beta_i+\epsilon_i$$ where $y_i=(y_{i1},...,y_{in_i})^T$, $X_i=(x_{i1}^T,...,x_{in_i}^T)^T$, $Z_i=(z_{i1}^T,...,z_{in_i}^T)^T$, $\alpha$ is a $p \times 1$ vector of unknown population parameters, $\beta_i$ is a $q \times 1$ vector of unknown subject-specific random effects with $\beta_i \sim N(0, D)$ and the ellements of the residual vector, $\epsilon_i$, are $N(0, \sigma^2I)$.
I was trying to use the package lme4
in R
which allows we to deal with the hierarchical data and consider the variability between subjects. But in this case, the data usually looks like
And we can use like
lme4(frequency ~ attitude + (1|subject) + (1|scenario), data=politeness)
to specify which variable has fixed effect, attitude
, and which has a random effect, the subject
and scenario
are two variable with random effect.
But my questions are:
In our example, the variable which has a random effect is $Z_i$. But according to the error I got when I use
lme4
, the level of random effect variable should be more than 1 and smaller than the number of observations. How should we deal with it when our $Z_i$ here is continuous?We actually know the distribution of the random effect coefficients $\beta$, how should we using this information here? i.e. where to put the information in $D$?
Many thanks to any comments!