Published on :
Statistics CREATION_INTERNE

Nonlinear Poisson Regression Random-Effects Model (MCMCEX8)

This code is also available in: Deutsch Español Français
Awaiting validation
This script uses the MCMC procedure to perform a Bayesian analysis on pump failure data. It compares two model parameterizations (centered and non-centered) to estimate hyperparameters and random effects. The code internally generates the data and uses ODS Graphics for trace diagnostics.
Data Analysis

Type : CREATION_INTERNE


The 'pump' data is generated directly within the script via a Data Step using DATALINES.

1 Code Block
DATA STEP Data
Explanation :
Creation of the 'pump' dataset with variables y, t, and group. Note: The code contains a strange artifact ( @code_sas_json...) in the INPUT statement which appears to be an insertion error, but the data is present as datalines.
Copied!
1title 'Nonlinear Poisson Regression Random-Effects Model';
2DATA pump;
3 INPUT y t group @code_sas_json/hsdua2304@gmail.com_SAS_Assignment_2.json;
4 pump = _n_;
5 logtstd = log(t) - 2.4564900;
6 DATALINES;
7 5 94.320 1 1 15.720 2 5 62.880 1
814 125.760 1 3 5.240 2 19 31.440 1
9 1 1.048 2 1 1.048 2 4 2.096 2
1022 10.480 2
11;
2 Code Block
PROC MCMC
Explanation :
First execution of PROC MCMC to fit the Bayesian model. Uses an Inverse-Gamma prior for the variance and defines multivariate (u) and univariate (e) normal random effects.
Copied!
1ods graphics on;
2PROC MCMC DATA=pump outpost=postout seed=248601 nmc=10000
3 plots=trace stats=none diag=none;
4 ods select tracepanel;
5 array u[2] alpha beta;
6 array mu[2] (0 0);
7 parms s2;
8 prior s2 ~ igamma(0.01, scale=0.01);
9 random u ~ MVNAR(mu, sd=1e6, rho=0) subject=group monitor=(u);
10 random e ~ normal(0, var=s2) subject=pump monitor=(random(1));
11 w = alpha + beta * logtstd;
12 lambda = exp(w+e);
13 model y ~ poisson(lambda);
14RUN;
3 Code Block
PROC MCMC
Explanation :
Second execution of PROC MCMC with a different parameterization (hierarchical model centered on the latent variable 'llambda') to improve convergence or sampling efficiency.
Copied!
1PROC MCMC DATA=pump outpost=postout_c seed=248601 nmc=10000
2 plots=trace diag=none;
3 ods select tracepanel postsumint;
4 array u[2] alpha beta;
5 array mu[2] (0 0);
6 parms s2 1;
7 prior s2 ~ igamma(0.01, scale=0.01);
8 random u ~ MVNAR(mu, sd=1e6, rho=0) subject=group monitor=(u);
9 w = alpha + beta * logtstd;
10 random llambda ~ normal(w, var = s2) subject=pump monitor=(random(1));
11 lambda = exp(llambda);
12 model y ~ poisson(lambda);
13RUN;
4 Code Block
MACRO CALL
Explanation :
Call to a utility macro '%CATER' (likely to visualize caterpillar plots of random effects) and closing ODS graphics.
Copied!
1%CATER(
2DATA=postout_c, var=llambda_:);
3ods graphics off;
4 
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, PRODUCT: STAT