Published on :
Statistical INTERNAL_CREATION

Analysis of Nonlinear Mixed Models (NLMIXED) for Binomial Data

This code is also available in: Deutsch Español Français
Awaiting validation
The script initializes a dataset named 'surgery' using `datalines` to simulate clinical study results ('y' successes out of 'n' trials). It creates auxiliary variables 'treat2' and 'no', and transforms the 'treat' variable. Subsequently, two `NLMIXED` procedures are executed. The first adjusts a binomial logistic model with an uncorrelated random effect ('a') by study ('subject=study'). The second performs a more complex adjustment, incorporating two correlated random effects ('a' and 'b') and an interaction between 'b' and 'treat', specifying a number of quadrature points (`qpoints=50`) and generating a prediction dataset 'new2'.
Data Analysis

Type : INTERNAL_CREATION


Data is created directly within the script via a DATA step and `datalines`, forming the 'surgery' dataset. Although a string resembling a JSON file path is present in the `input` statement, it is not interpreted as an external data source for this specific DATA step, as the data is provided directly after `cards;`.

1 Code Block
DATA STEP Data
Explanation :
This DATA STEP block creates the 'surgery' dataset using `datalines`. It reads the variables 'study', 'treat', 'y' (number of successes), and 'n' (total number of trials). The string ' @code_sas_json/hsdua2304@gmail.com_SAS_Assignment_1.json' is present in the `input` statement but is not standard syntax for reading external data in this context and is interpreted literally. The block then calculates 'no' (number of failures) and transforms the 'treat' variable from 1 to 0.5 and from 0 to -0.5, thus preparing the data for subsequent analyses.
Copied!
1DATA surgery;
2 INPUT study treat y n @code_sas_json/hsdua2304@gmail.com_SAS_Assignment_1.json ; * y successes out of n trials;
3 treat2 = treat;
4 no=n-y;
5 IF treat = 1 THEN treat = .5; ELSE treat = -.5;
6CARDS;
71 1 7 15 1 0 11 13
82 1 8 19 2 0 8 16
93 1 5 34 3 0 4 39
104 1 7 36 4 0 4 31
115 1 3 12 5 0 0 12
126 1 4 7 6 0 4 4
137 1 4 17 7 0 13 24
148 1 1 16 8 0 13 16
159 1 3 14 9 0 7 22
1610 1 2 38 10 0 12 32
1711 1 6 12 11 0 8 8
1812 1 2 7 12 0 7 9
1913 1 9 21 13 0 7 24
2014 1 7 21 14 0 5 25
2115 1 3 25 15 0 11 32
2216 1 4 11 16 0 6 10
2317 1 2 10 17 0 8 10
2418 1 1 31 18 0 4 27
2519 1 4 28 19 0 15 31
2620 1 7 43 20 0 16 43
2721 1 6 40 21 0 13 21
2822 1 4 18 22 0 5 39
2923 1 14 68 23 0 13 74
3024 1 6 21 24 0 8 21
3125 1 0 6 25 0 6 6
3226 1 1 10 26 0 5 15
3327 1 5 17 27 0 5 15
3428 1 0 10 28 0 12 14
3529 1 0 22 29 0 8 24
3630 1 2 18 30 0 10 21
3731 1 1 15 31 0 7 13
3832 1 8 24 32 0 15 27
3933 1 6 12 33 0 7 9
4034 1 0 20 34 0 5 23
4135 1 4 17 35 0 2 16
4236 1 10 40 36 0 12 20
4337 1 3 16 37 0 2 16
4438 1 4 34 38 0 5 19
4539 1 7 38 39 0 15 37
4640 1 0 34 40 0 34 34
4741 1 0 9 41 0 0 16
48;
2 Code Block
PROC NLMIXED
Explanation :
This first `PROC NLMIXED` block fits a nonlinear mixed model. It models the probability 'pi' of 'y' successes out of 'n' trials using a logistic function with a random effect 'a' for each 'study'. The random effect 'a' follows a normal distribution with mean 'alpha' and variance 'sig*sig', with no interaction specified with other variables.
Copied!
1/* (11.7) */
2PROC NLMIXED; * random effects, no interaction;
3pi = exp(a + beta*treat)/(1+exp(a + beta*treat)); * logistic formula for prob;
4model y ~ binomial(n, pi);
5random a ~ normal(alpha, sig*sig) subject=study;
3 Code Block
PROC NLMIXED Data
Explanation :
This second `PROC NLMIXED` block fits a more complex model with correlated random effects. It includes two random effects, 'a' and 'b', which are assumed to follow a correlated multivariate normal distribution. The probability 'pi' incorporates an interaction of 'b' with 'treat'. The `qpoints=50` option is used for quadrature integral calculation. Furthermore, the `predict` clause is used to predict the values of 'beta + b' and save them to a new dataset named 'new2'.
Copied!
1/* (11.8) */
2PROC NLMIXED qpoints=50; * correlated random effects, interaction;
3pi = exp(alpha + a + beta*treat + b*treat)/(1+exp(alpha + a + beta*treat + b*treat));
4model y ~ binomial(n, pi);
5random a b ~ normal([0,0], [sig_a*sig_a, rho ,sig_b*sig_b]) subject=study;
6predict beta + b out=new2;
7RUN;
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.