Published on :
Statistical CREATION_INTERNE

Example 6 of documentation for PROC NLMIXED

This code is also available in: Deutsch Español Français
Awaiting validation
The script initializes macro variables to control the size of the simulated data. It then generates a dataset named 'nested' with nested random effects (A, B(A)) and a response variable 'resp' based on a linear model with normally distributed errors. Finally, it uses PROC NLMIXED to fit a linear mixed model to this data, specifying bounds for the variances of the random effects and the nesting structure.
Data Analysis

Type : CREATION_INTERNE


The 'nested' dataset is entirely created and simulated within the SAS script using random number generation functions.

1 Code Block
DATA STEP Data
Explanation :
This DATA STEP block creates a 'nested' dataset by simulating observations. Three nested loops generate levels for variables 'A', 'B' (nested within 'A'), and 'rep'. Normally distributed random errors (err1, err2, err3) are generated using the RANNOR() function to simulate a random effects structure. The 'resp' variable is calculated as a sum of a constant and these random errors.
Copied!
1%let na = 100;
2%let nb = 5;
3%let nr = 2;
4DATA nested;
5 DO A = 1 to &na;
6 err1 = 3*rannor(339205);
7 DO B = 1 to &nb;
8 err2 = 2*rannor(0);
9 DO rep = 1 to &nr;
10 err3 = 1*rannor(0);
11 resp = 10 + err1 + err2 + err3;
12 OUTPUT;
13 END;
14 END;
15 END;
16RUN;
2 Code Block
PROC NLMIXED
Explanation :
This block uses PROC NLMIXED to fit a linear mixed model to the 'nested' dataset. Bounds are defined for the variances of the random effects (vara, varb_a) to ensure they are non-negative. The fixed part of the model is defined by 'mean', and the response variable 'resp' is modeled according to a normal distribution. Two random effects are specified: 'aeffect' for subject 'A' and 'beffect' for subject 'B' nested within 'A' (B(A)), each with a normal distribution with mean 0 and variances vara and varb_a respectively.
Copied!
1PROC NLMIXED DATA = nested;
2 bounds vara >=0, varb_a >=0;
3 mean = intercept + aeffect + beffect;
4 model resp ~ normal (mean, s2);
5 random aeffect ~ normal(0,vara) subject = A;
6 random beffect ~ normal(0,varb_a) subject = B(A);
7RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : S A S S A M P L E L I B R A R Y