# Motivating Example

Data from the present example were drawn from a large-scale study in which indicators of verbal ability were measured for 1,141 students nested within 163 teachers. We will use xxM to fit unrestricted CFA models at the student and teacher levels in an effort to explain the common covariance among these indicators at each level.

In this case, each indicator of reading ability varies across students and teachers, and performance on these indicators is correlated within each level. Estimating a common latent factor at each level of analysis allows us to parsimoniously explain the common variance/covariance among the indicators.

# Path Diagram ## Scalar Representation

### Student Submodel (Level-1)

The measurement model for each indicator of reading ability at the student level can be presented as:

$y_{pij}^1= \nu_p^1 + \lambda_p^1 \times \eta_{1ij}^1 + e_{pij}^1$

$y_{pij}^1\ = \nu_p^1 + \lambda_p^1 \times \eta_{ij}^1 +e_{pij}^1$

where, $$y_{pij}$$ is $$p^{th}$$ observed indicator for student$$i$$, nested within teacher $$j$$. The superscript 1 is for the student level.
$\eta_{pij}^1 \sim N(0,\psi_{1, 1}^{1,1})$ $e_{pij}^1 \sim N(0,diag( \theta^{1,1} ) )$ The student submodel has the following parameters:

1. $$(p-1)$$ factor-loadings $$(\lambda_p^{1,1})$$ with the first factor loading being fixed to 1.0 for scale identification.
2. Residual variance for each of the p observed indicators $$(\theta_{p,p})$$
3. Single latent variance $$(\psi_{1,1}^{1,1})$$.
4. Measurement intercepts for each of the $$p$$ observed indicators $$(\nu_p)$$.

### Teacher Submodel (Level-2) AND across Levels

The teacher level has a single latent variable with zero mean and unknown residual variance $$(\psi_{1,1}^{2,2})$$. The superscript 2 is for the teacher level, and the generic teacher-level equation is nearly identical to the student equation:

$y_{pij}^1=\nu_p^1+\lambda_{p,1}^{1,2} \times \eta_{1j}^2+e_{pj}^1$

where, $$y_{pij}$$ is $$p^{th}$$ observed indicator for student $$i$$, nested within teacher $$j$$. It is important to note that the student level reading outcomes serve as indicators of the reading ability factor at the teacher level. As a result, the student level measurement intercepts and residual variances carry-over from the previous equation. Hence, we need only a single teacher level reading ability latent variable:

$\eta_{1j}^2 \sim N(0,\psi_{1,1}^{2,2} )$

Because we have already specified the mean structure and residual variances for the observed indicators at the student level, only two ‘types’ of parameter remain:

1. $$(p-1)$$ factor-loadings $$(\lambda_{p,1}^{1,2})$$ with the first factor-loading being fixed to 1.0 for scale identification.
2. Single latent variance $$(\psi_{1,1}^{2,2}).$$

## XXM Model Matrices

### Student Submodel (Level-1)

$\Lambda_{pattern}^{1,1} = \begin{bmatrix} \ 0 \\ \ 1 \\ \ 1 \\ \ 1 \end{bmatrix}$
$\Lambda_{value}^{1,1} = \begin{bmatrix} \ 1.0 \\ \ 1.1 \\ \ 0.9 \\ \ 0.8 \end{bmatrix}$
$\Lambda_{lable}^{1,1} = \begin{bmatrix} \lambda_{1,1}^{1,1} \\ \lambda_{2,1}^{1,1} \\ \lambda_{3,1}^{1,1} \\ \lambda_{4,1}^{1,1} \end{bmatrix}$

The first factor-loading is fixed to 1.0. Hence, we need to fix the first parameter in the pattern matrix. The value at which it being fixed is specified in the value matrix. In this case the first factor-loading is being fixed to a value of 1.0.

#### Observed Residual Covariance Matrix (Theta)

$\Theta_{pattern}^{1,1} = \begin{bmatrix} \ 1 & 0 & 0 & 0 \\ \ 0 & 1 & 0 & 0 \\ \ 0 & 0 & 1 & 0 \\ \ 0 & 0 & 0 & 1 \end{bmatrix}$
$\Theta_{value}^{1,1} = \begin{bmatrix} \ 1.1 & 0.0 & 0.0 & 0.0 \\ \ 0.0 & 2.1 & 0.0 & 0.0 \\ \ 0.0 & 0.0 & 1.3 & 0.0 \\ \ 0.0 & 0.0 & 0.0 & 1.5 \end{bmatrix}$

The residual covariance matrix is a diagonal matrix, meaning we are only estimating residual variances. Residual covariances are all fixed to 0.0. Again we use a pattern and a value matrix to fix all off-diagonal elements to 0.0

#### Latent Covariance Matrix (PSI)

$$\Psi_{pattern}^{1,1}=$$, $$\Psi_{value}^{1,1}=[1.1]$$

#### Observed Variablel Intercepts (nu)

$\nu_{pattern}^{1,1}= \begin{bmatrix} \ 1 \\ \ 1 \\ \ 1 \\ \ 1 \\ \end{bmatrix}$

,

$\nu_{value}^{1,1}= \begin{bmatrix} \ 1.1 \\ \ 2.1 \\ \ 1.3 \\ \ 7.1 \\ \end{bmatrix}$

### Teacher submodel (Level-2)

$\lambda_{pattern}^{1,2}= \begin{bmatrix} \ 0 \\ \ 1 \\ \ 1 \\ \ 1 \end{bmatrix}$

,

$\lambda_{value}^{1,2}= \begin{bmatrix} \ 1.0 \\ \ 1.1 \\ \ .9 \\ \ .8 \end{bmatrix}$

,

$\lambda_{label}^{1,2}= \begin{bmatrix} \lambda_{1,1}^{1,2}\\ \lambda_{2,1}^{1,2}\\ \lambda_{1,2}^{3,1}\\ \lambda_{1,2}^{4,1} \end{bmatrix}$

It is important to note that in the current specification $$\Lambda_{label}^{1,1}$$ $$\Lambda_{label}^{1,2}$$ suggesting that the factor-loadings at each level are to be uniquely estimated. Modifying these matrices so that elements corresponding to common indicators share the same label (e.g., $$\lambda_{1,1}^{2,1}$$, $$\lambda_{2,1}^{1,2}$$ -> $$\lambda _{2,1}$$ ) places equality constraints on loadings to the same indicator at the student and teacher level. The next example (hcfa) illustrates this concept in greater detail.

#### Latent Covariance Matrix (PSI)

$$\Psi_{pattern}^{2,2}=$$, $$\Psi_{value}^{2,2}=[0.05]$$

### Model Matrices Summary

The following table provides a complete summary of parameter matrices:

Type Matrix Pattern
level 1: $$\Theta$$
$\Theta^{1,1} = \begin{bmatrix} \theta_{1,1}^{1,1} & \\ \theta_{2,1}^{1,1} & \theta_{2,2}^{1,1} \\ \theta_{3,1}^{1,1} & \theta_{3,2}^{1,1} & \theta_{3,3}^{1,1} \\ \theta_{4,1}^{1,1} & \theta_{4,2}^{1,1} & \theta_{4,3}^{1,1} & \theta_{4,4}^{1,1} \\ \end{bmatrix}$
$\Theta^{1,1} = \begin{bmatrix} \ 1 \\ \ 0 & 1 \\ \ 0 & 0 & 1 \\ \ 0 & 0 & 0 & 1\\ \end{bmatrix}$
level 1: $$\nu$$
$\nu^{1} = \begin{bmatrix} \nu_1^1\\ \nu_2^1\\ \nu_3^1 \\ \nu_4^1 \end{bmatrix}$
$\nu^{1} = \begin{bmatrix} \ 1\\ \ 1\\ \ 1\\ \ 1 \end{bmatrix}$
level 1: $$\Lambda$$
$\Lambda^{1,1} = \begin{bmatrix} \lambda_{1,1}^{1,1}\\ \lambda_{2,1}^{1,1}\\ \lambda_{3,1}^{1,1}\\ \lambda_{4,1}^{1,1} \end{bmatrix}$
$\Lambda^{1,1} = \begin{bmatrix} \ 0\\ \ 1\\ \ 1\\ \ 1 \end{bmatrix}$
level1: $$\Psi$$
$\Psi^{1,1} = [\psi_{1,1}^{1,1}]$
$\Psi^{1,1} = $
Level 2 -> Level 1: $$\Lambda$$
$\Lambda^{1,2} = \begin{bmatrix} \lambda_{1,1}^{1,2}\\ \lambda_{2,1}^{1,2}\\ \lambda_{3,1}^{1,2}\\ \lambda_{4,1}^{1,2} \end{bmatrix}$
$\Lambda^{1,2} = \begin{bmatrix} \ 0\\ \ 1\\ \ 1\\ \ 1 \end{bmatrix}$
level 2: $$\Psi$$
$\Psi^{2,2} = [\psi_{1,1}^{2,2}]$
$\Psi^{2,2} =$

# Code Listing

“xxM”

## xxM

The complete listing of xxM code is as follows:

### 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 main model object

xxmModel() is used to declare level names. The function returns a model object that is passed as a parameter to subsequent stattements.

### Add submodels to the model objects

For each declared level xxmSubmodel() is invoked to add corresponding submodel to the model object. The function adds three pieces of information:
1. parents declares a list of parents of the current level.
2. variables declares names of observed dependent (ys), observed independent (xs) and latent variables (etas) for the level.
3. data R data object for the current level.

### Add Within-level parameter matrices for each submodel

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 parameter matrices to the model

Pairs of levels that share parent-child relationship have regression relationships. xxmBetweenMatrix() is used to add corresponding parameter 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 quick printed summary of results is produced.

### Estimate profile-likelihood confidence intervals

Once parameters are estimated, confidence inetrvals are estimated by invoking xxmCI() . Depending on the the number of observations and the complexity of the dependence structure xxmCI() may take very long. xxMCI() displays a table of parameter estimates and CIS.

### View results

A summary of results may be retrived as an R list by a call to xxmSummary()

### Free model object

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

For the current dataset, the parameter estimates are: 