The NLMIXED Procedure

Example 83.6 Simulated Nested Linear Random-Effects Model

(View the complete code for this example.)

This simulation study example demonstrates how to fit a hierarchical model with PROC NLMIXED by using a simple two-level nested linear model. In this example, the data are generated from a simple two-level nested hierarchical normal model (Littell et al. 2006). Here the conditional distribution of the response variable, given the random effects, is normal. The mean of this conditional normal distribution is a linear function of a fixed parameter and the random effects. In this simulation, only the intercept is used as a fixed parameter. Also, the first-level random effects are assumed to follow a normal distribution. Similarly, the second-level random effects that are nested within the first level follow a normal distribution. The model can be represented as follows:

The simulation code is as follows:

%let na = 100;
%let nb = 5;
%let nr = 2;
data nested;
   do A = 1 to &na;
      err1 = 3*rannor(339205);
      do B = 1 to &nb;
         err2 = 2*rannor(0);
         do rep = 1 to &nr;
            err3 = 1*rannor(0);
            resp = 10 + err1 + err2 + err3;
            output;
         end;
      end;
   end;
run;

You can use PROC NLMIXED to fit the preceding nested model as follows by using two RANDOM statements:

proc nlmixed data = nested;
   bounds vara >=0, varb_a >=0;
   mean = intercept + aeffect + beffect;
   model resp ~ normal (mean, s2);
   random aeffect ~ normal(0,vara) subject = A;
   random beffect ~ normal(0,varb_a) subject = B(A);
run;

The MODEL statement specifies the response variable distribution as normal. The linear relationship between the mean of this normal distribution and the fixed and random effects is specified by using a SAS programming statement. The BOUNDS statement specifies the nonnegative constraints on the variance parameters.

PROC NLMIXED with multiple RANDOM statements is used to fit hierarchical (nested) models. In this example, two RANDOM statements are used to fit a two-level nested model. The first RANDOM statement identifies aeffect as the first-level random effect, , and it is followed by the subject variable A. The subject variable A indexes the number of distinct and independent subjects at the first level. Then the second RANDOM statement identifies the beffect, , as the second-level random effect, which is nested within the first level. The subject variable specification in the second RANDOM statement defines the nested structure. In this example, the subject variable B is nested within A.

The results from the analysis follow.

Output 83.6.1: Model Specifications for a Two-Level Nested Model

The NLMIXED Procedure

Specifications
Data SetWORK.NESTED
Dependent Variableresp
Distribution for Dependent VariableNormal
Random Effectsaeffect, beffect
Distribution for Random EffectsNormal, Normal
Subject VariablesA, B
Optimization TechniqueDual Quasi-Newton
Integration MethodAdaptive Gaussian Quadrature


The "Specifications" table (Output 83.6.1) lists the setup of the nested model. It lists all the random effects and their distribution along with the SUBJECT= variable in the nested sequence. Random effects that are listed in the specifications table are separated by a comma, indicating that aeffect is the first-level random effect, followed by the second-level random effect, beffect, which is nested within the first level. The same scheme applies to the distribution and subject items in the table. In this example, aeffect is the random effect for the first level and is specified using the subject variable A, which follows a normal distribution. Then beffect is the random effect for the second level, which is nested within the first level; it is specified using the subject variable B, which also follows a normal distribution.

The "Dimensions" table (Output 83.6.2) follows the same nested flow to exhibit the model dimensions. It indicates that 1,000 observations are used. There are 100 first-level subjects and 500 second-level subjects, because each first-level subject is contained by five nested second-level subjects. For this model, PROC NLMIXED selects one quadrature point to fit the model.

Output 83.6.2: Dimensions Table for a Two-Level Nested Model

Dimensions
Observations Used1000
Observations Not Used0
Total Observations1000
Subjects [A]100
Max Obs per Subject10
Subjects [B]500
Max Obs per Subject2
Parameters4
Quadrature Points1


A total of 15 steps are required to achieve convergence. They are shown in the "Iteration History" table (Output 83.6.3).

Output 83.6.3: Iteration History

Iteration History
IterationCallsNegative
Log
Likelihood
DifferenceMaximum
Gradient
Slope
1122982.01412695.598215.363-87641.4
2372462.0898519.9243518.335-346.648
3432144.0047318.085260.9954-2483.38
4492108.772035.2326756.3198-64.4603
5612098.562710.2093643.0728-7.79282
6672094.20914.35350234.1536-20.0831
7732090.28023.92894126.4378-5.86557
8802089.34430.93593715.0337-2.41721
9862088.11071.23361820.3762-0.59126
10982072.769915.34085.02630-1.53248
111052068.54244.22740828.6084-2.25950
121122066.44392.098589.01353-2.53321
131192065.81270.631183.73621-0.50717
141262065.75900.0536461.02924-0.07232
151332065.75500.004060.36114-0.00578
161392065.75020.0047980.27897-0.00171

NOTE: GCONV convergence criterion satisfied.


The "Parameter Estimates" table (Output 83.6.4) contains the maximum likelihood estimates of the parameters. You can see from this table that the intercept and the s2 variables are very close to the simulation parameters. Also, both variances are very close to the simulation parameters.

Output 83.6.4: Parameter Estimates for a Two-Level Nested Model

Parameter Estimates
ParameterEstimateStandard
Error
DFt ValuePr > |t|95% Confidence LimitsGradient
vara9.21981.42994986.45<.00016.410412.02920.022612
varb_a3.69970.297349812.44<.00013.11564.28390.008443
intercept10.15460.317149832.02<.00019.531510.7776-0.04079
s20.96610.0610249815.83<.00010.84621.0860-0.31590