Published on :
Statistical CREATION_INTERNE

Random Effects Logistic Regression Model

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by creating a SAS© dataset named 'seeds' via a DATA step with embedded data (datalines). This dataset contains information on the number of successes 'r' out of 'n' trials, as well as explanatory factors 'seed' and 'extract'. Then, the MCMC procedure is invoked to perform a Bayesian analysis. The model specifies a logistic regression where the probability of success is influenced by the factors 'seed', 'extract', and their interaction. A random effect 'delta' is introduced at each observation level to capture unobserved variability. Prior distributions are defined for all model parameters (regression coefficients 'beta' and variance of the random effect 's2'). The MCMC simulation is run for 20000 iterations, and the results of the posterior distribution are stored in the 'postout' table.
Data Analysis

Type : CREATION_INTERNE


The data is entirely generated within the script via a 'DATA' step and 'datalines' statement, creating the 'seeds' table.

1 Code Block
DATA STEP Data
Explanation :
This code block creates a SAS dataset named 'seeds'. The data is read directly from the input stream (datalines). A variable 'ind' is added, serving as a unique identifier for each row (observation).
Copied!
1DATA seeds;
2 INPUT r n seed extract;
3 ind = _N_;
4 DATALINES;
510 39 0 0
623 62 0 0
723 81 0 0
826 51 0 0
917 39 0 0
10 5 6 0 1
1153 74 0 1
1255 72 0 1
1332 51 0 1
1446 79 0 1
1510 13 0 1
16 8 16 1 0
1710 30 1 0
18 8 28 1 0
1923 45 1 0
20 0 4 1 0
21 3 12 1 1
2222 41 1 1
2315 30 1 1
2432 51 1 1
25 3 7 1 1
26;
27RUN;
2 Code Block
PROC MCMC Data
Explanation :
This block performs a Bayesian analysis via the MCMC procedure. It defines the model parameters (beta0, beta1, beta2, beta3, s2) and their prior distributions. A hierarchical model is constructed with a random effect 'delta' following a normal distribution. The probability 'pi' is modeled by a logistic function of this random effect, and the response variable 'r' is assumed to follow a binomial distribution. The simulation generates 20000 samples from the posterior distribution, which are saved in the 'postout' table.
Copied!
1PROC MCMC DATA=seeds outpost=postout seed=332786 nmc=20000;
2 ods select PostSumInt;
3 parms beta0 0 beta1 0 beta2 0 beta3 0 s2 1;
4 prior s2 ~ igamma(0.01, s=0.01);
5 prior beta: ~ general(0);
6 w = beta0 + beta1*seed + beta2*extract + beta3*seed*extract;
7 random delta ~ normal(w, var=s2) subject=ind;
8 pi = logistic(delta);
9 model r ~ binomial(n = n, p = pi);
10RUN;
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