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.
title 'Nonlinear Poisson Regression Random-Effects Model';
2
DATA 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
594.3201115.7202562.8801
8
14125.760135.24021931.4401
9
11.048211.048242.0962
10
2210.4802
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!
ods graphics on;
proc mcmc data=pump outpost=postout seed=248601 nmc=10000
plots=trace stats=none diag=none;
ods select tracepanel;
array u[2] alpha beta;
array mu[2] (0 0);
parms s2;
prior s2 ~ igamma(0.01, scale=0.01);
random u ~ MVNAR(mu, sd=1e6, rho=0) subject=group monitor=(u);
random e ~ normal(0, var=s2) subject=pump monitor=(random(1));
w = alpha + beta * logtstd;
lambda = exp(w+e);
model y ~ poisson(lambda);
run;
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);
14
RUN;
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!
proc mcmc data=pump outpost=postout_c seed=248601 nmc=10000
plots=trace diag=none;
ods select tracepanel postsumint;
array u[2] alpha beta;
array mu[2] (0 0);
parms s2 1;
prior s2 ~ igamma(0.01, scale=0.01);
random u ~ MVNAR(mu, sd=1e6, rho=0) subject=group monitor=(u);
w = alpha + beta * logtstd;
random llambda ~ normal(w, var = s2) subject=pump monitor=(random(1));
lambda = exp(llambda);
model y ~ poisson(lambda);
run;
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
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.