Published on :
Statistical CREATION_INTERNE

Example 3 PROC NLMIXED Documentation: Probit-Normal Model

This code is also available in: Deutsch Español Français
Awaiting validation
This script is Example 3 from the SAS© documentation for PROC NLMIXED. It analyzes inhaler data (Ezzet and Whitehead, 1991) by fitting a proportional odds model with random effects. It defines bounds for threshold parameters and uses the `probnorm` function to manually construct the log-likelihood function.
Data Analysis

Type : CREATION_INTERNE


The 'inhaler' data is created via a DATA step with DATALINES. The original syntax suggests using ' @@' to read multiple observations per line.

1 Code Block
DATA STEP Data
Explanation :
Creation of the 'inhaler' dataset. The INPUT statement uses the ' @@' modifier to read data continuously (multiple observations per physical line). Variables 'gt' (interaction) and 'sub' (subject identifier) are calculated.
Copied!
1DATA inhaler;
2 INPUT clarity group time freq @@;
3 gt = group*time;
4 sub = floor((_n_+1)/2);
5 DATALINES;
61 0 0 59 1 0 1 59 1 0 0 35 2 0 1 35 1 0 0 3 3 0 1 3 1 0 0 2
74 0 1 2 2 0 0 11 1 0 1 11 2 0 0 27 2 0 1 27 2 0 0 2 3 0 1 2
82 0 0 1 4 0 1 1 4 0 0 1 1 0 1 1 4 0 0 1 2 0 1 1 1 1 0 63
91 1 1 63 1 1 0 13 2 1 1 13 2 1 0 40 1 1 1 40 2 1 0 15 2 1 1 15
103 1 0 7 1 1 1 7 3 1 0 2 2 1 1 2 3 1 0 1 3 1 1 1 4 1 0 2
111 1 1 2 4 1 0 1 3 1 1 1
12;
2 Code Block
PROC NLMIXED
Explanation :
Estimation of the nonlinear mixed model. The 'general' distribution is used to specify a custom log-likelihood ('ll') based on the cumulative normal distribution function (probnorm). The model includes a random effect 'u' normally distributed at the subject level 'sub'. 'REPLICATE' accounts for the frequency variable.
Copied!
1PROC NLMIXED DATA=inhaler corr ecorr;
2 parms b0=0 b1=0 b2=0 b3=0 sd=1 i1=1 i2=1;
3 bounds i1 > 0, i2 > 0;
4 eta = b0 + b1*group + b2*time + b3*gt + u;
5 IF (clarity=1) THEN p = probnorm(-eta);
6 ELSE IF (clarity=2) THEN
7 p = probnorm(i1-eta) - probnorm(-eta);
8 ELSE IF (clarity=3) THEN
9 p = probnorm(i1+i2-eta) - probnorm(i1-eta);
10 ELSE p = 1 - probnorm(i1+i2-eta);
11 IF (p > 1e-8) THEN ll = log(p);
12 ELSE ll = -1e20;
13 model clarity ~ general(ll);
14 random u ~ normal(0,sd*sd) subject=sub;
15 replicate freq;
16 estimate 'thresh2' i1;
17 estimate 'thresh3' i1 + i2;
18 estimate 'icc' sd*sd/(1+sd*sd);
19RUN;
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 : SAS SAMPLE LIBRARY