Published on :
Statistical CREATION_INTERNE

Random Coefficients Model with PROC MIXED

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by creating a dataset named 'rc' via a DATA step with in-line data (datalines). This data simulates a pharmaceutical stability study with batches (Batch) and measurements (Y) taken at different months (Month). Subsequently, two MIXED procedures are executed. The first fits a linear regression model with random coefficients (intercept and 'Month' slope) for each batch. The second explores a model variation by including an additional class variable 'Monthc'.
Data Analysis

Type : CREATION_INTERNE


The data is generated directly within the script using a DATA step and DATALINES statement. The 'rc' dataset is created in memory for the SAS session.

1 Code Block
DATA STEP Data
Explanation :
This DATA block creates the 'rc' table. It reads the 'Batch' and 'Month' variables, then uses a 'do' loop to read up to 6 'Y' values for each initial record. For each 'Y' value read, a new observation is generated. The 'Monthc' variable is created as a copy of 'Month'. Data is provided in-line via 'datalines'.
Copied!
1DATA rc;
2 INPUT Batch Month @;
3 Monthc = Month;
4 DO i = 1 to 6;
5 INPUT Y @;
6 OUTPUT;
7 END;
8 DATALINES;
9 1 0 101.2 103.3 103.3 102.1 104.4 102.4
10 1 1 98.8 99.4 99.7 99.5 . .
11 1 3 98.4 99.0 97.3 99.8 . .
12 1 6 101.5 100.2 101.7 102.7 . .
13 1 9 96.3 97.2 97.2 96.3 . .
14 1 12 97.3 97.9 96.8 97.7 97.7 96.7
15 2 0 102.6 102.7 102.4 102.1 102.9 102.6
16 2 1 99.1 99.0 99.9 100.6 . .
17 2 3 105.7 103.3 103.4 104.0 . .
18 2 6 101.3 101.5 100.9 101.4 . .
19 2 9 94.1 96.5 97.2 95.6 . .
20 2 12 93.1 92.8 95.4 92.2 92.2 93.0
21 3 0 105.1 103.9 106.1 104.1 103.7 104.6
22 3 1 102.2 102.0 100.8 99.8 . .
23 3 3 101.2 101.8 100.8 102.6 . .
24 3 6 101.1 102.0 100.1 100.2 . .
25 3 9 100.9 99.5 102.2 100.8 . .
26 3 12 97.8 98.3 96.9 98.4 96.9 96.5
27;
28 
2 Code Block
PROC MIXED
Explanation :
This procedure fits a mixed model to the 'rc' data. 'Batch' is defined as a classification variable. The 'model' statement specifies 'Y' as the dependent variable and 'Month' as a fixed effect. The 'random' statement defines random intercept ('Int') and slope ('Month') for each 'Batch' level, with an unstructured covariance structure ('type=un'). The 's' option requests the display of solutions for fixed and random effects.
Copied!
1PROC MIXED DATA=rc;
2 class Batch;
3 model Y = Month / s;
4 random Int Month / type=un sub=Batch s;
5RUN;
3 Code Block
PROC MIXED
Explanation :
A second PROC MIXED analysis is performed, adding 'Monthc' to the list of classification variables. The fixed model remains the same. The 'random' statement is modified to include 'Monthc' as a random effect in addition to the intercept and 'Month', still grouped by 'Batch'. This allows exploring a different random model structure.
Copied!
1PROC MIXED DATA=rc;
2 class Batch Monthc;
3 model Y = Month / s;
4 random Int Month Monthc / sub=Batch s;
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