Published on :
Statistical CREATION_INTERNE

Probit-Normal Model with PROC NLMIXED for Binomial Data

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by creating a SAS© dataset named 'rats' using a DATA step and internal data (datalines). This data comes from an experiment comparing a treatment group ('t') to a control group ('c'). Indicator variables (x1, x2) are created to differentiate the two groups. Then, the NLMIXED procedure is applied to model the number of successes 'x' out of 'm' trials. The model defines a linear predictor 'eta' which incorporates fixed effects (t1, t2) and a random effect 'alpha' specific to each litter ('litter'). The probability of success 'p' is modeled via the standard normal distribution function (probit model). The script also estimates a composite parameter 'gamma2' and generates an output dataset containing the predicted probabilities.
Data Analysis

Type : CREATION_INTERNE


The data is created directly within the script via a DATA step and a 'datalines' statement. It does not come from SASHELP or an external source.

1 Code Block
DATA STEP Data
Explanation :
This block creates the SAS table 'rats'. It reads the variables 'trt' (treatment), 'm' (number of trials), and 'x' (number of successes) from embedded data (datalines). It generates indicator variables 'x1' and 'x2' for the control and treatment groups respectively. A litter identifier ('litter') is created using the observation number (_n_).
Copied!
1DATA rats;
2 INPUT trt $ m x @;
3 IF (trt='c') THEN DO;
4 x1 = 1;
5 x2 = 0;
6 END;
7 ELSE DO;
8 x1 = 0;
9 x2 = 1;
10 END;
11 litter = _n_;
12 DATALINES;
13c 13 13 c 12 12 c 9 9 c 9 9 c 8 8 c 8 8 c 13 12 c 12 11
14c 10 9 c 10 9 c 9 8 c 13 11 c 5 4 c 7 5 c 10 7 c 10 7
15t 12 12 t 11 11 t 10 10 t 9 9 t 11 10 t 10 9 t 10 9 t 9 8
16t 9 8 t 5 4 t 9 7 t 7 4 t 10 5 t 6 3 t 10 3 t 7 0
17;
18 
2 Code Block
PROC NLMIXED Data
Explanation :
This block fits a nonlinear mixed model to the 'rats' table. It defines the initial parameters (parms), the linear predictor 'eta', and the probability 'p' via the probit function (probnorm). The model specifies a binomial distribution for the response 'x'. A random effect 'alpha' with a different variance per treatment group is included and grouped by 'litter'. An estimate of a ratio is calculated with 'estimate', and the predicted probabilities are saved in a new table 'p' with 'predict'.
Copied!
1PROC NLMIXED DATA=rats;
2 parms t1=1 t2=1 s1=.05 s2=1;
3 eta = x1*t1 + x2*t2 + alpha;
4 p = probnorm(eta);
5 model x ~ binomial(m,p);
6 random alpha ~ normal(0,x1*s1*s1+x2*s2*s2) subject=litter;
7 estimate 'gamma2' t2/sqrt(1+s2*s2);
8 predict p out=p;
9RUN;
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