Published on :
Statistical INTERNAL_CREATION

Documentation Example 19 for PROC GLIMMIX - Quadrature Method for Multilevel Models

This code is also available in: Deutsch Español Français
Awaiting validation
The script simulates academic performance data ('grade') for students ('student') grouped by class ('class') within schools ('school'). A program effect ('program') is also simulated. The GLIMMIX procedure is then used to fit a generalized mixed model with a binomial distribution and a logit link function, incorporating random effects for school and class nested within school. The script presents two similar runs, the second one fitting the model with a slight variation in data generation and the addition of the `fastquad` option.
Data Analysis

Type : INTERNAL_CREATION


The 'test' data is entirely created within the script using DATA steps, simulating a hierarchical structure (students in classes in schools) and random effects.

1 Code Block
DATA STEP Data
Explanation :
This DATA step block generates a dataset named 'test'. It simulates a hierarchical structure with 10 schools, 5 classes per school, and 10 students per class. Random effects 'schef' (school) and 'clsef' (class) are added. A binary 'program' variable is generated. The 'grade' variable is simulated according to a binomial distribution, depending on a probability 'p' calculated from a linear combination of fixed and random effects.
Copied!
1DATA test;
2 DO school = 1 to 10;
3 schef = rannor(1234)*4;
4 DO class = 1 to 5;
5 clsef = rannor(2345)*2;
6 program = ranbin(12345,1,.5);
7 DO student = 1 to 10;
8 eta = 3 + program + schef + clsef ;
9 p = 1/(1+exp(-eta));
10 grade = ranbin(23456,1,p);
11 OUTPUT;
12 END;
13 END;
14 END;
15RUN;
2 Code Block
PROC GLIMMIX
Explanation :
This GLIMMIX procedure fits a generalized mixed model to the 'test' data. The quadrature method (quad(qpoints=3)) is used. The variables 'school', 'class', and 'program' are declared as classification variables. The model specifies 'grade' as the dependent variable, 'program' as a fixed effect, with a binomial distribution and a logit link. Random effects ('random int') are included for 'school' and 'class' nested within 'school'.
Copied!
1PROC GLIMMIX DATA=test method = quad(qpoints=3);
2 class school class program;
3 model grade = program/s dist=binomial link=logit solution;
4 random int /subject = school;
5 random int /subject = class(school);
6RUN;
3 Code Block
DATA STEP Data
Explanation :
This second DATA step block is similar to the first but generates data with 10 classes per school (instead of 5). It again simulates a hierarchical structure with random effects and the 'grade' variable following the same principles as the first block.
Copied!
1DATA test;
2 DO school = 1 to 10;
3 schef = rannor(1234)*4;
4 DO class = 1 to 10;
5 clsef = rannor(2345)*2;
6 program = ranbin(12345,1,.5);
7 DO student = 1 to 10;
8 eta = 3 + program + schef + clsef ;
9 p = 1/(1+exp(-eta));
10 grade = ranbin(23456,1,p);
11 OUTPUT;
12 END;
13 END;
14 END;
15RUN;
4 Code Block
PROC GLIMMIX
Explanation :
This second GLIMMIX procedure fits a model identical to the first, but on the newly generated 'test' data. The 'fastquad' option is added to the quadrature method, which can potentially speed up calculation by using a different approximation for the integrals.
Copied!
1PROC GLIMMIX DATA=test method = quad(qpoints=3 fastquad);
2 class school class program;
3 model grade = program/s dist=binomial link=logit solution;
4 random int /subject = school;
5 random int /subject = class(school);
6RUN;
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