LMIXED Procedure
Getting Started: LMIXED Procedure
(View the complete code for this example.)
This example demonstrates how you can perform a mixed model analysis of covariance when you have many groups. Suppose you are an educational researcher who studies how student scores on math tests change over time. Students are tested four times, and you want to estimate the overall rise or fall, accounting for correlation between test response behaviors of students in the same neighborhood and school. One way to model this correlation is by using a random-effects analysis of covariance, where in addition to having a student-specific quadratic mean response function, the scores for students from the same neighborhood and school are all assumed to share the same quadratic mean test response function, whose parameters are random. The following statements simulate data that have this structure; these statements assume that your libref is named mylib, but you can substitute any appropriately defined libref.
Note: Input data must be in a table that is accessible in your session. You can refer to this table by using a two-level name. The first level is a libref, and the second level is the table name. For more information, see the section Using SAS Viya Workbench in Chapter 2, Shared Concepts.
data mylib.SchoolSample;
do SchoolID = 1 to 1000;
do nID = 1 to 50;
Neighborhood = (SchoolID-1)*15 + nId;
bInt = 15*ranuni(1);
bTime = 15*ranuni(1);
bTime2 = ranuni(1);
do sID = 1 to 2;
do Time = 1 to 4;
Math = bInt + bTime*Time + bTime2*Time*Time + rannor(2);
output;
end;
end;
end;
end;
run;
These data comes from 1,000 schools and about 15,035 neighborhoods; neighborhoods are associated with more than one school and vice versa. There are 400,000 observations and 50,000 levels of the subject effect.
The following statements use the LMIXED procedure to fit a linear mixed model to these data and produce Figure 1 through Figure 4:
proc lmixed data=mylib.SchoolSample;
class Neighborhood SchoolID;
model Math = Time Time*Time / solution;
random int Time Time*Time / sub=Neighborhood(SchoolID) type=un;
run;
This model fits a quadratic mean response model that has an unstructured covariance matrix to model the covariance between the random parameters of the response model. With 15,035 neighborhood/school combinations, this model can be computationally daunting to fit, but the LMIXED procedure finishes quickly by multithreaded computing.
Figure 1 displays the "Model Information," "Optimization Information," "Class Level Information," "Number of Observations Information," and "Dimensions" tables.
Figure 1: Mixed Model Analysis of Covariance
| Model Information | |
|---|---|
| Data Source | SCHOOLSAMPLE |
| Response Variable | Math |
| Estimation Method | Restricted Maximum Likelihood (REML) |
| Degrees of Freedom Method | Residual |
| Design Matrix Method | Dense |
| Optimization Information | |
|---|---|
| Optimization Technique | Newton-Raphson with Ridging |
| Hessian in Optimization | Exact |
| Parameters in Optimization | 6 |
| Lower Boundaries | 3 |
| Upper Boundaries | 0 |
| Residual Variance | Profiled |
| Starting Values From | Data |
| Class Level Information | ||
|---|---|---|
| Class | Levels | Values |
| Neighborhood | 15035 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ... |
| SchoolID | 1000 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ... |
| Number of Observations Read | 400000 |
|---|---|
| Number of Observations Used | 400000 |
| Dimensions | |
|---|---|
| G-side Covariance Parameters | 6 |
| R-side Covariance Parameters | 1 |
| Columns in X | 3 |
| Columns in Z per Subject | 3 |
| Subjects (Blocks in V) | 50000 |
Figure 2 displays the convergence status and the "Covariance Parameter Estimates" table.
Figure 2: Mixed Model Analysis of Covariance
| Convergence criterion (ABSGCONV=0.00001) satisfied. |
| Covariance Parameter Estimates | ||
|---|---|---|
| Cov Parm | Subject | Estimate |
| UN(1,1) | Neighborhood(SchoolID) | 18.7964 |
| UN(2,1) | Neighborhood(SchoolID) | -0.1215 |
| UN(2,2) | Neighborhood(SchoolID) | 18.9874 |
| UN(3,1) | Neighborhood(SchoolID) | -0.00044 |
| UN(3,2) | Neighborhood(SchoolID) | -0.00805 |
| UN(3,3) | Neighborhood(SchoolID) | 0.08394 |
| Residual | 0.9998 | |
Figure 3 displays the "Fit Statistics" table.
Figure 3: Mixed Model Analysis of Covariance
| Fit Statistics | |
|---|---|
| -2 Res Log Likelihood | 1681870 |
| AIC (smaller is better) | 1681884 |
| AICC (smaller is better) | 1681884 |
| BIC (smaller is better) | 1681945 |
| CAIC (smaller is better) | 1681952 |
| HQIC (smaller is better) | 1681903 |
Figure 4 displays the "Solution for Fixed Effects" table.
Figure 4: Mixed Model Analysis of Covariance
| Solution for Fixed Effects | |||||
|---|---|---|---|---|---|
| Effect | Estimate | Standard Error | DF | t Value | Pr > |t| |
| Intercept | 7.4961 | 0.02129 | 4E5 | 352.04 | <.0001 |
| Time | 7.4939 | 0.02108 | 4E5 | 355.55 | <.0001 |
| Time*Time | 0.5009 | 0.002044 | 4E5 | 245.03 | <.0001 |
These estimates are very close to the quadratic coefficients that are used in the DATA step multiplied by 1/2, which is the expected value of a uniform random variable on [0,1].