Published on :
Statistical CREATION_INTERNE

Caterpillar Plot with PROC MCMC

This code is also available in: Deutsch Español Français
Awaiting validation
The script first generates a 'seeds' dataset containing germination results. It then uses the `PROC MCMC` procedure to fit a binomial model with a logit link function and random effects ('delta'). The posterior distribution samples are saved in the 'postout' table. A `%CATER` macro is called to create the Caterpillar plot of the random effects. Finally, a `PROC TEMPLATE` step is used to view the source of the associated graph template.
Data Analysis

Type : CREATION_INTERNE


The data used ('seeds') is created directly in the script via a DATA step using the DATALINES statement.

1 Code Block
DATA STEP Data
Explanation :
Creates the 'seeds' dataset containing variables r, n, seed, extract and an observation identifier 'ind'. The data is included directly in the code.
Copied!
1DATA seeds;
2 INPUT r n seed extract;
3 ind = _N_;
4 DATALINES;
510 39 0 0 23 62 0 0 23 81 0 0 26 51 0 0
617 39 0 0 5 6 0 1 53 74 0 1 55 72 0 1
732 51 0 1 46 79 0 1 10 13 0 1 8 16 1 0
810 30 1 0 8 28 1 0 23 45 1 0 0 4 1 0
9 3 12 1 1 22 41 1 1 15 30 1 1 32 51 1 1
10 3 7 1 1
11;
2 Code Block
PROC MCMC Data
Explanation :
Performs a Bayesian (MCMC) analysis on the 'seeds' data. Defines a binomial logistic model with random effects 'delta'. Posterior samples are stored in 'postout'. Result display is temporarily disabled to optimize execution.
Copied!
1ods select none;
2PROC MCMC DATA=seeds outpost=postout seed=332786 nmc=20000;
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;
11ods select all;
3 Code Block
Macro Call
Explanation :
Calls the `%CATER` macro (assumed to be defined in the environment or an autocall library) to generate the Caterpillar plot of variables starting with 'delta' from the 'postout' dataset.
Copied!
1%CATER(DATA=postout, var=delta:);
4 Code Block
PROC TEMPLATE
Explanation :
Displays the source code of the ODS graph template 'Stat.MCMC.Graphics.Caterpillar' stored in 'sashelp.tmplmst', allowing inspection of the graph definition used.
Copied!
1PROC TEMPLATE;
2 path sashelp.tmplmst;
3 SOURCE Stat.MCMC.Graphics.Caterpillar;
4RUN;
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 - NAME: MCMCCAT - PRODUCT: STAT