Pastes: Three level Random-Intercepts Model

Pastes: Three Level Random-Intercepts Model

Pastes example included with lme4 involves a random-intercepts model of strength of pastes in different samples nested within batches. The three levels are

  1. response
  2. sample
  3. batch

\[ y_{i}^{1} =\nu^1 + \Lambda_{i,j}^{1,2} \times \eta_j^{2} + \Lambda_{i,j}^{1,3} \times \eta_j^{3}+ e_{i}, \]

\[ e^{1} \sim N(0, \theta^{1,1}_{1,1}) \] \[ \eta^{2} \sim N(0, \psi^{2,2}_{1,1}) \] \[ \eta^{3} \sim N(0, \psi^{3,3}_{1,1}) \]

xxM Model Matrices

Level-1 (Response): Within matrices

With a single dependent variable there are two parameters level-1: (a) residual variance \( (\theta_{1,1}) \), and (b) intercept \( \nu_{1} \)

Residual Covariance Matrix

\[
\Theta^{1,1} =
\begin{bmatrix}
\theta^{1,1}_{1,1}
\end{bmatrix}
\]

Observed interept

\[
\nu^{1} =
\begin{bmatrix}
\nu^{1}_{1}
\end{bmatrix}
\]

Level-2 (Sample): Within Matrices

At level-2, we have a single latent variable: random-intercept of strength, with a single parameter latent variance.

Latent Factor Covariance Matrix

The latent covariance matrix is a (1×1) matrix with single variance of the intercept:

\[
\Psi^{2,2}=
\begin{bmatrix}
\psi_{1,1}^{2,2}
\end{bmatrix}
\]

Level-3 (Batch): Within Matrices

Likewise, at level-3, we have a single latent variable: random-intercept of strength, with a single parameter latent variance.

Latent Factor Covariance Matrix

The latent covariance matrix is a (1×1) matrix with single variance of the intercept:

\[
\Psi^{3,3}=
\begin{bmatrix}
\psi_{1,1}^{3,3}
\end{bmatrix}
\]

Across level matrices: Sample to Response

Across-level factor-loading matrix

The factor-loading matrix \( (\Lambda^{1,2}) \) has a single element fixed to 1.0.

\[
\Lambda^{1,2} =
\begin{bmatrix}
1.0_{i,j}^{1,2}
\end{bmatrix}
\]

Across level matrices: Batch to Response

Across-level factor-loading matrix

The factor-loading matrix \( (\Lambda^{1,3}) \) has a single element fixed to 1.0.

\[
\Lambda^{1,3} =
\begin{bmatrix}
1.0_{i,j}^{1,3}
\end{bmatrix}
\]

Path Diagram

(insert diagram)

Code Listing

“xxM”“SAS:“R:

xxM

Load xxM

xxM library needs to be loaded first.

Prepare R datasets

For this analysis, we use data packaged with lme4.
For analysis with xxM separate response, batch and sample datasets are created as follows:

response dataset includes the following columns:

  • response Unique response IDs (integer)
  • sample IDs for the parent level (integer)
  • batch IDs for the parent level (integer)
  • strength the dependent varaible (numeric)

sample dataset includes the following columns:

  • sample Unique batch IDs (integer)

batch dataset includes the following columns:

  • batch Unique batch IDs (integer)

Construct R-matrices

For each parameter matrix, construct three related matrices:

  1. pattern matrix: A matrix indicating free or fixed parameters.
  2. value matrix: with start or fixed values for corresponding parameters.
  3. label matrix: with user friendly label for each parameter. label matrix is optional.

Construct model

xxmModel() is used to declare level names. The function returns a model object that is passed as a parameter to subsequent statements. Variable name for the return value can be anything.

Add submodels

For each declared level xxmSubmodel() is invoked to add corresponding submodel to the model object. The function adds three types of information to the model object:

  • parents declares a list of all parents of the current level.
    • Level with the independent variable is the parent level.
    • Level with the dependent variable is the child level.
  • variables declares names of observed dependent (ys), observed independent (xs) and latent variables (etas) for the level.
  • data R data object for the current level.

Add within-level matrices

For each declared level xxmWithinMatrix() is used to add within-level parameter matrices. For each parameter matrix, the function adds the three matrices constructed earlier:

  • pattern
  • value
  • label (optional)

Add across-level matrices

Pairs of levels that share parent-child relationship have regression relationships. xxmBetweenMatrix() is used to add corresponding rergession matrices connecting the two levels.

  • Level with the independent variable is the parent level.
  • Level with the dependent variable is the child level.

For each parameter matrix, the function adds the three matrices constructed earlier:

  • pattern
  • value
  • label (optional)

Estimate model parameters

Estimation process is initiated by xxmRun(). If all goes well, a q&d summary of the results is printed.

Estimate profile-likelihood confidence intervals

Once parameters are estimated, confidence intervals are estimated by invoking xxmCI(). Depending on the the number of observations and the complexity of the model, xxmCI() may take a long time to compute. xxmCI() also prints a summary of parameter estimates and CIS.

View results

A summary of results may be retrived as an R list by a call to xxmSummary(). The returned list has two elements:

  1. fit is a list with five elements:
    • deviance is \( -2 Log Likelihood \) for the maximum likelihood fit function.
    • nParameters is the total number of unique parameters.
    • nObservations is the total number of observations across all levels.
    • aic is Akaike’s Information Criterion or AIC computed as \( -2ll + 2*p \).
    • bic is Bayesian Information Criterion or BIC computed as \( -2ll + p*\log(n) \).
  2. estimates is a single table of free parameter estimates
    All xxM parameters have superscripts {child, parent} and subscripts {to, from}. xxM adds a descriptive parameter label if one is not already provided by the user.

Free model object

xxM model object may hog a significant amount of RAM outside of R’s workspace. This memory will automatically be released, when the workspace is cleared by a call to rm(list=ls()) or at the end of the R session. Alternatively, it is recommended that xxmFree() may be called to release the memory.

Proc Mixed

R: lmer