Saving the X and Z matrices from the MIXED or GLIMMIX Procedures


There is no option in PROC MIXED to save design matrices to SAS data sets. However, the OUTDESIGN= option in the PROC GLIMMIX statement creates a SAS data set that contains the contents of the X and/or the Z matrix. If the data are processed by subjects as shown in the "Dimensions" table, then the Z matrix saved to the data set corresponds to a single subject. In other words, if the data are processed by subjects, then the OUTDESIGN= data set contains a stacking of the subject level Z matrices rather than a block diagonal structure. By default, the GLIMMIX procedure includes in the OUTDESIGN= data set the X and Z matrices (if present) and the variables in the input data set. The order of the observations in the OUTDESIGN= data set is the same as the order of the input data set. You can use the OUTDESIGN= option in combination with the NOFIT option if you want to produce X and/or Z matrices without fitting the model. The following example writes the X and Z matrices to the OUTDESIGN= data set.

data heights;
   input Family Gender$ Height @@;
   datalines;
1 F 67   1 F 66   1 F 64   1 M 71   1 M 72   2 F 63
2 F 63   2 F 67   2 M 69   2 M 68   2 M 70   3 F 63
3 M 64   4 F 67   4 F 66   4 M 67   4 M 67   4 M 69
;
run;

Not Processed by Subjects - Block Diagonal Z Matrix 


proc glimmix data=heights outdesign(z)=zmatrix;
   class Family Gender;
   model Height = Gender;
   random Family Family*Gender;
run;

proc print data=zmatrix;
run;

The OUTDESIGN(Z)= option specifies the Z matrix being created and saved. This model is not processed by subjects. The output below shows a block diagonal Z matrix for the two random effects.



Processed by Subjects - Stacked Z Matrix 

proc glimmix data=heights outdesign(z)=zmatstack;
   class Family Gender;
   model Height = Gender;
   random int Gender/subject=family;
   run;

proc print data=zmatstack;
   run;

The model is processed by subjects due to the SUBJECT= option in the RANDOM statement. The output below shows a stacked Z matrix of Family for Intercept and Gender effects.

Not Processed by Subjects -- Both X and Z Matrices

proc glimmix data=heights outdesign=xzmatrix nofit;
   class Family Gender;
   model Height = Gender;
   random Family Family*Gender;
   run;

proc print data=xzmatrix;
   run;

The OUTDESIGN= option saves both X and Z matrices to a SAS data set. The NOFIT option allows the producing of this data set without fitting the model. Because this model is not processed by subjects, the output below shows a block diagonal design matrix for the random effects. The design matrix for the fixed effects, the X matrix, is also saved to this data set.

Processed by Subjects -- Both X and Z Matrices 

proc glimmix data=heights outdesign=xzstackmat nofit;
   class Family Gender;
   model Height = Gender;
   random int Gender/subject=family;
   run;

proc print data=xzstackmat;
   run;
This model is processed by subjects due to the SUBJECT= option in the RANDOM statement. The output below shows the X matrix and the stacked Z matrix of Family for Intercept and Gender effects.