Published on :
Statistical CREATION_INTERNE

Getting Started Example for PROC HPLMIXED

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by creating a 'SchoolSample' dataset. It simulates hierarchically structured data with 300 schools, each having 25 neighborhoods, and for each neighborhood, 2 observations at 4 different time points. The variables 'SchoolID', 'Neighborhood', 'bInt', 'bTime', 'bTime2' are generated. The dependent variable 'Math' is calculated with a random component. Then, PROC HPLMIXED is used to fit a linear mixed model to the data. The variables 'Neighborhood' and 'SchoolID' are declared as classification variables. The fixed model includes 'Time' and 'Time*Time'. Random effects include the intercept ('int'), 'Time', and 'Time*Time' nested within 'Neighborhood(SchoolID)', with an unstructured covariance structure (TYPE=UN).
Data Analysis

Type : CREATION_INTERNE


The 'SchoolSample' dataset is entirely created internally within the SAS script via a DATA step (DATA STEP). It does not use external data or default SAS libraries like SASHELP.

1 Code Block
DATA STEP Data
Explanation :
This DATA STEP block generates the 'SchoolSample' dataset. It uses nested loops to create 300 schools, each with 25 neighborhoods, and for each neighborhood, 2 observations at 4 different time points ('Time'). The variables 'bInt', 'bTime', 'bTime2' are randomly generated to simulate fixed effects. The dependent variable 'Math' is then calculated as a quadratic function of time with the addition of random noise ('rannor'). The 'output;' statement writes each observation to the dataset.
Copied!
1DATA SchoolSample;
2 DO SchoolID = 1 to 300;
3 DO nID = 1 to 25;
4 Neighborhood = (SchoolID-1)*5 + nId;
5 bInt = 5*ranuni(1);
6 bTime = 5*ranuni(1);
7 bTime2 = ranuni(1);
8 DO sID = 1 to 2;
9 DO Time = 1 to 4;
10 Math = bInt + bTime*Time + bTime2*Time*Time + rannor(2);
11 OUTPUT;
12 END;
13 END;
14 END;
15 END;
16RUN;
2 Code Block
PROC HPLMIXED
Explanation :
This block uses PROC HPLMIXED to fit a linear mixed model. The 'data=SchoolSample' option specifies the input dataset. The 'class' statement identifies 'Neighborhood' and 'SchoolID' as categorical variables. The 'model' statement defines the fixed effects structure, with 'Math' as the dependent variable and 'Time' and 'Time*Time' as predictors. The '/solution' option requests the display of fixed effects parameter estimates. The 'random' statement specifies the random effects: an intercept ('int'), 'Time', and 'Time*Time', which are nested within the 'Neighborhood(SchoolID)' unit. The 'type=un' option indicates an unstructured covariance matrix for the random effects.
Copied!
1PROC HPLMIXED DATA=SchoolSample;
2 class Neighborhood SchoolID;
3 model Math = Time Time*Time / solution;
4 random int Time Time*Time / sub=Neighborhood(SchoolID) type=un;
5RUN;
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 NAME: HPLMXGS TITLE: Getting Started Example for PROC HPLMIXED PRODUCT: STAT SYSTEM: ALL KEYS: Mixed Models, Analysis of Covariance PROCS: HPLMIXED