# SAS Mixed Model Procedures – PROC MIXED, PROC NLMIXED

In our previous article we have seenÂ Longitudinal Data Analysis Procedures, today we will discuss what is SAS mixed model. Moreover, we are going to explore procedures used in Mixed modeling in SAS/STAT.

In these SAS Mixed Model, we will focus on 6 different types of procedures:Â PROC MIXED, PROC NLMIXED, PROC PHREG, PROC GLIMMIX, PROC VARCOMP, and ROC HPMIXED with examples & syntax. At last, we also learn SASÂ mixed models with examples.

SAS Mixed Model Procedures – PROC MIXED, PROC NLMIXED

### Introduction to SAS Mixed Model

The termÂ mixed modelÂ in SAS/STAT refers to the use of both fixed and random effects in the same analysis. SAS mixed model are particularly useful in settings whereÂ repeated measurements are made on the sameÂ statistical units, or where measurements are made on clusters of related statistical units.

Because of their advantage in dealing with missing values, mixed effects models are often preferred over more traditional approaches such as repeated measuresÂ ANOVA.

In such SAS mixed modeling, the observations are not assumed to be independent. Random effects are fitted to the model accounting for additional sources of variation. A general linear mixed model looks like the one shown below.
Also, Learn 6 Bayesian Analysis ProceduresÂ

Sample – SAS Mixed Modeling

### Mixed Modelling Procedure in SAS/STAT

SAS/STAT uses the following 6 simple procedures to compute mixed models of a sample data. Each procedure has a different syntax and is used with different type of data in different contexts. Let us explore each one of these.

#### a. PROC HPMIXED

The HPMIXED procedure uses a number of techniques to fit linear mixed models. PROC HPMIXED procedure enables you to specify a linear mixed model with variance component structure, to estimate the covariance parameters by restricted maximum likelihood.

The HPMIXED procedure is similar to the PROC MIXED procedure and other SAS procedures for mixed modeling. SAS mixed modelÂ supported by the HPMIXED procedure are a subset of the models that you can fit with the MIXED procedure.
Let’s learn 16 Important Features ofÂ SAS/STAT Â
The syntax ofÂ PROC HPMIXED

PROC HPMIXEDÂ DATASET
CLASS <variable>;
MODEL response= effects <options>;

The PROC HPMIXED, MODEL statements are required
PROC HPMIXED Example-

proc hpmixed data=Sashelp.iris;
Â Â  class Species;
Â Â  model sepallength = Sepalwidth;
Â  run;

Â

SAS mixed model –Â Â PROC HPMIXED

SAS mixed modeling –Â PROC HPMIXED

#### b. PROC NLMIXED

The PROC NLMIXED fits nonlinear mixed modelsâ€”that is, models in which both fixed and random effects enter nonlinearly. PROC NLMIXED enables you to specify a conditional distribution for your data (given the random effects) having either a standard form (normal, binomial, Poisson) or a general distribution.

SAS PROC NLMIXED fits nonlinear mixed models by maximizing an approximation to the likelihood integrated over the random effects.
PROCÂ NLMIXEDÂ Syntax-

PROC NLMIXED dataset <

OPTIONS>; MODEL model-specification; PARMSÂ parameters-and-starting-values;
Â PROCÂ NLMIXEDÂ Example-

data CARS;
Â  input NUMBER LENGTH X;
Â  datalines;
1Â  118Â Â  30
1Â  484Â Â  58
1Â  664Â Â  87
2Â  118Â Â  33
2Â  484Â Â  69
2Â  664Â   111
3Â  118Â Â  30
3Â  484Â Â  51
3Â  664Â Â  75
4Â  118Â Â  32
4Â  484Â Â  62
4Â  664Â   112
4  1004Â  167
5Â  118Â Â  30
5Â  484Â Â  49
5Â  664Â Â  81
5 1004Â   125
;
proc nlmixed data=CARS;
Â Â  parms b1=220 b2=500 b3=310 s2u=100 s2e=60;
Â Â  num = b1+u1;
Â Â  exÂ  = exp(-(day-b2)/b3);
Â Â  den = 1 + ex;
Â Â  model X ~ normal(num/den,s2e);
Â Â  random u1 ~ normal(0,s2u) subject=NUMBER;
run;

In the above example, a nonlinear SAS mixed model has been created with different equations.
TheÂ PROC NLMIXEDÂ statement invokes the procedure and inputs the data set. TheÂ PARMS statement identifies the unknown parameters and their starting values. Here there are three fixed-effects parameters (b1,Â b2,Â b3) and two variance components (s2u,Â s2e).
The MIXED MODEL statement defines the dependent variable and its conditional distribution given the random effects. Here a normal (Gaussian) conditional distribution is specified.

TheÂ RANDOM statement defines the single random effect to beÂ u1, and specifies that it follow a normal distribution with mean 0 and varianceÂ s2u. TheÂ SUBJECT=Â argument in theÂ RANDOMÂ statement defines a variable indicating when the random effect obtains new realizations.Â

SAS mixed model –Â PROC NLMIXED

Statistical Mixed Modeling –Â PROC NLMIXED

Mixed Models in SAS/STAT –Â PROC NLMIXED

#### c. PROC VARCOMP

The VARCOMP procedure in SAS/STAT fits general linear models that have random effects. PROC VARCOMP estimates the contribution of each of the random effects to the variance of the dependent variable. You can specify four general methods of estimationÂ in the PROC VARCOMP statement by using theÂ METHOD=option. Let us see how it works-
PROC VARCOMPÂ Syntax-

PROC VARCOMP dataset OPTIONS;
CLASS <VARIABLES>;
Â Â Â Â  MODEL dependentÂ =Â <fixed-effects> </ options>;

TheÂ PROC MIXED andÂ MODEL statements are required, and theÂ MODELÂ statement must appear after theÂ CLASS statement if aÂ CLASS statement is included.
PROC VARCOMPÂ Example-

proc varcomp method=ml data=SASHELP.CARS;
Â Â  class MAKEÂ  ORIGIN;
Â Â  model MPG_HIGHWAY=ORIGIN;
run;

The MIXED MODEL statement first specifies the response (dependent) variable MPG_highway. The explanatory (independent) variables are then listed after the equal (=) sign.

SAS mixed model –Â PROC VARCOMP

#### d. PROC GLIMMIX

We have already discussed this procedure in detail in the Longitudinal data analysis tutorial. You can refer to the same for the complete tutorial.

#### e. PROC MIXED

We have already discussedÂ this procedure in detail in the Longitudinal data analysis tutorial with PROC MIXED example.

#### f. PROC PHREG

We have already discussed this procedure in detail. You can refer to the following link for the complete tutorial.
This was allÂ about SAS Mixed Model Tutorial. Hope you like our explanation.

### Conclusion

Hence, we have discussed the complete description of SAS mixed model. Along with this we also learned the 6 different procedures for mixed modeling in SAS/STAT. Moreover, we looked at the syntax and examples of PROC MIXED, PROC NLMIXED, PROC PHREG, PROC GLIMMIX, PROC VARCOMP, and PROC HPMIXED and how they can be used.

Hope you all enjoyed it. Stay tuned for more interesting topics in SAS/STAT, and for any doubts in SAS mixed model, post it in the comments section below.

For referenceÂ