6 SAS/STAT Bayesian Analysis Procedures You Must Know

1. Objective

We looked at SAS ANOVA (analysis of variance) in the previous tutorial, today we will be looking at SAS/STAT Bayesian Analysis Procedure. Moreover, we will see how Bayesian Analysis Procedure is used in SAS/STAT for computing different models. Our focus here will be to understand different procedures that can be used for Bayesian analysis through the use of examples.
So, let’s start SAS/STAT Bayesian Analysis Procedure.

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis Procedure

2. SAS/STAT Bayesian Analysis

SAS/ STAT Bayesian analysis is a statistical procedure that helps us in answering research questions about unknown parameters using probability statements.
Bayesian Analysis example- what is the probability that the average female height is between 60 and 70 inches? What is the probability that people in a particular state vote for Congress or vote BJP? What is the probability that treatment A is more cost-effective than treatment B for a specific health care provider?
Let’s Learn SAS/STAT Software Features
These statements are very common in the SAS/STAT Bayesian analysis because of the underlying assumption that all parameters are random quantities. In a SAS/STAT Bayesian analysis, a parameter is summarized by an entire distribution of values instead of one fixed value.
A posterior distribution comprises a prior distribution of a parameter and a likelihood model providing information about the parameter based on observed data.

SAS STAT bayesian analysis

SAS STAT bayesian analysis

3. Calculating Bayesian Analysis in SAS/STAT

SAS/STAT Software uses the following procedures to compute Bayesian analysis of a sample data. Each procedure has a different syntax and is used with different type of data in different contexts. Let us explore each one of these.
Read About SAS/STAT Software Advantages & Disadvantages

Calculating Bayesian Analysis in SAS/STAT

How to Calculate Bayesian Analysis in SAS/STAT

a. SAS PROC BCHOICE

The PROC BCHOICE procedure in SAS/STAT (Bayesian choice) procedure performs Bayesian analysis for discrete choice models. Discrete choice models are derived under the assumption of utility-maximizing behavior by decision makers. When individuals are asked to make one choice among a set of alternatives, they usually determine the level of utility that each alternative offers.
SAS PROC BCHOICE Syntax-

PROC BCHOICE DATASET;
CLASS variable;
MODEL response <(response-options)> = <fixed-effects> </ model-options>;

SAS PROC BCHOICE Example-

data Chocolates;
   input Subj Choice brown white choco_chips;
   datalines;
1 0 0 0 0
1 0 0 0 1
1 0 0 1 0
2 0 0 0 0
2 0 0 0 1
2 0 0 1 0
2 0 0 1 1
3 0 0 0 0
3 0 0 0 1
4 0 0 0 0
4 0 0 0 1
4 0 1 0 1
5 0 0 1 0
5 0 0 1 1
5 0 1 1 1
6 0 0 0 0
6 0 0 0 1
7 0 0 0 0
7 0 1 1 0
7 0 1 1 1
8 0 0 0 0
8 0 0 0 1
8 0 0 1 0
8 0 0 1 1
8 0 1 0 0
8 1 1 0 1
8 0 1 1 0
8 0 1 1 1
9 0 0 0 0
9 0 0 0 1
9 0 0 1 0
9 0 0 1 1
9 0 1 0 0
9 1 1 0 1
9 0 1 1 0
9 0 1 1 1
10 0 0 0 0
10 0 0 0 1
;
proc print data=Chocolates (obs=16);
run;
ods graphics on;
proc bchoice data=Chocolates;
   class brown(ref='0') white(ref='0') choco_chips(ref='0') Subj;
   model Choice = brown white choco_chips / choiceset=(Subj) cprior=normal(var=1000);
run;

Let’s Revise SAS ODS (Output Delivery Systems)
The PROC BCHOICE and MODEL statements are required statements.  

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis – SAS PROC BCHOICE

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis –  – SAS PROC BCHOICE

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis – SAS PROC BCHOICE

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis – SAS PROC BCHOICE

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis – SAS PROC BCHOICE

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis – SAS PROC BCHOICE

b. SAS PROC FMM

The PROC FMM procedure in SAS/STAT Software fits statistical models to data for which the distribution of the response is a finite mixture of distributions—that is, each response is drawn with unknown probability from one of several distributions.
Let’s Learn SAS Frequency Distribution Using SAS PROC FREQ
SAS PROC FMM Syntax-

PROC FMM dataset;
model <VARIABLES>;
output DATASET;

 
The PROC FMM and MODEL statements are required.
The MODEL statement defines elements of the mixture model, such as the model effects, the distribution, and the link function.
The OUTPUT statement creates a data set that contains observations statistics that are computed after fitting the model. By default, all variables in the original data set are included in the output data set.
In the below example, the dist= option specifies the kind of distribution we want. Because our variable is a continuous one, we have taken normal distribution here.
SAS PROC FMM Example-

proc fmm data=sashelp.class;
model age=/ dist=normal;
output out= class class=ML;
RUN;

Let’s Discuss SAS Arithmetic Mean – SAS PROC MEANS Tutorial

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis – SAS PROC FMM

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis – SAS PROC FMM

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis – SAS PROC FMM

c. SAS PROC GENMOD

The PROC GENMOD provides Bayesian analysis for distributions like binomial, gamma, Gaussian, normal and Poisson. It also provides Bayesian analysis for links like identity, log, logit, probit etc. In a Bayesian analysis, the model parameters are treated as random variables, and inference about parameters is based on the posterior distribution of the parameters, given the data.
Read About SAS Histogram Statement With UNIVARIATE Procedure
SAS Proc GENMOD Syntax-

PROC GENMOD dataset;
     model <dependent variable>;
bayes <options>;

Here, MODEL statement signifies the dependent and the independent variable. In the below example, height is the dependent variable and age is the independent variable.
The Bayes statement signifies that we are performing a Bayesian analysis in SAS/STAT.
SAS Proc FMM Example-

proc genmod data=sashelp.class;
model height=age / dist=normal;
bayes outpost=class;
run;

Here the outpost = option saves samples (posterior) to the POST dataset.
DO You Know How to Apply Fishers Exact Test in SAS Using PROC FREQ Procedure
The first table produced in the output provides some usual classical inferences, but all the subsequent tables provide Bayesian analysis.
In the above example, the dist= option specifies the kind of distribution we want. Because our variable is a continuous one, we have taken normal distribution here.
The GENMOD procedure also uses ODS Graphics to create graphs as part of its output. 

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis – SAS PROC GENMOD

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis – SAS PROC GENMOD

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis – SAS PROC GENMOD

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis – SAS PROC GENMOD

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis – SAS PROC GENMOD

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis – SAS PROC GENMOD

Let’s Explore How to Join/Combine Data Sets in SAS

d. SAS PROC LIFEREG

The PROC LIFEREG procedure in SAS/STAT fits parametric models to data that can be uncensored, right censored, left censored, or interval censored. The models for the response variable consist of a linear effect composed of the covariates and a random disturbance term. Bayesian analysis of parametric survival models can be requested by using the BAYES statement in the LIFEREG procedure.
SAS Proc LIFEREG Syntax-

PROC LIFEREG dataset;
model VARIABLE;

Example-

data one;
input y x cen;
cards;
12  2  0
12  3  1
14  1  1
67  3  1
43  2  1
78  1  1
;
ods graphics on;
proc lifereg data=one;
model y= / dist=exponential;
run;

Let’s Discuss Types of Software in SAS Programming language

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis – SAS PROC LIFEREG

SAS STAT bayesian analysis

SAS STAT Bayesian Analysis – SAS PROC LIFEREG

Let’s revise SAS Environment Setup

e. SAS PROC MCMC

The MCMC procedure is a general purpose simulation procedure that uses Markov chain Monte Carlo (MCMC) techniques to fit Bayesian models. PROC MCMC draws samples from a random posterior distribution (posterior probability distribution is the probability distribution of an unknown quantity, treated as a random variable, conditional on the evidence obtained from an experiment or survey), and uses these samples to approximate the data distribution. You need to specify only parameters, prior distributions, and a likelihood function.
SAS PROC MCMC Syntax-

PROC MCMC dataset;
   PARMS <list of parameters>;
   PRIOR <type of distribution of each parameter>;
   MODEL <variable used as likelihood>;

 
SAS PROC MCMC Example-

ods graphics on;
proc mcmc data=sashelp.class ;
   parms b0 0 b1 0;
   parms sigma2 1;
   prior b0 b1 ~ normal(mean = 5, var = 1e6);
   prior sigma2 ~ igamma(shape = 2/10, scale = 10/4);
   mu = b0 + b1*height;
   model height ~ n(mu, var = sigma2);
run;

 
Here, height is a likelihood function specified in the model, ~ sign indicates that we want to specify a distribution for our data. Here likelihood is a normal distribution with mean (mu) and variance (sigma2).
The b0, b1 and sigma2 are parameters used with a parms statement. These are names given by us.
The MODEL statement also automatically compensates missing data.
The PROC MCMC also supports univariate or multivariate distributions.
Follow this link to know about SAS Syntax Cheat Sheet

SAS STAT bayesian analysis

SAS STAT Bayesian Procedure – SAS PROC MCMC

SAS STAT bayesian analysis

SAS STAT Bayesian Procedure – SAS PROC MCMC

SAS STAT bayesian analysis

SAS STAT Bayesian Procedure – SAS PROC MCMC

SAS STAT bayesian analysis

SAS STAT Bayesian Procedure – SAS PROC MCMC

Related topic- SAS Functions – Arithmetic, Character, Date and Time, Truncation

f. SAS PROC PHREG

The PROC PHREG procedure in SAS/STAT performs survival analysis of data. Many types of models have been used for survival data. Two of the more popular types of models are the accelerated failure time model (Kalbfleisch and Prentice 1980) and the Cox proportional hazards model (Cox 1972). The PHREG procedure performs a regression analysis of survival data based on the Cox proportional hazards model.
SAS PROC PHREG Syntax-

PROC PHREG  dataset;
   model response <*censor(list)> = <effects> </ options>;
  bayes </ options>;

The PROC PHREG and MODEL statements are required statements.
SAS PROC PHREG Example-

ods graphics on;
proc phreg data=sashelp.cars ;
   model horsepower*length(0) = cylinders;
  bayes outpost=cars;
run;

By using ODS Graphics, PROC PHREG allows you to plot the survival curve for CYLINERS GROUP.
The BAYES statement invokes the Bayesian analysis.
the OUTPOST= option saves the posterior distribution samples in a SAS data set for post-processing.
The “Model Information” table below summarizes information about the model you fit and the size of the simulation.
Do You Know How to Enter and Read Raw Data in SAS
So, this was all About SAS/STAT Bayesian Analysis Procedure Tutorial. Hope you like our explanation.

SAS STAT bayesian analysis

SAS STAT Bayesian Procedure – SAS PROC PHREG

SAS STAT bayesian analysis

SAS STAT Bayesian Procedure – SAS PROC PHREG

SAS STAT bayesian analysis

SAS STAT Bayesian Procedure – SAS PROC PHREG

4. Conclusion

Hence, this was a complete description and a comprehensive understanding of all the procedure offered by SAS/STAT Bayesian Analysis. We looked at each of them: PROC PHREG, PROC MCMC, PROC LIFEREG, PROC GENMOD, PROC FMM, and PROC BCHOICE with their syntax, and how they can be used. Hope you all enjoyed it. Stay tuned for more. Furthermore, if you have any query feel free to ask in a comment section.
Related Topic- Simple, Stacked & Clustered Bar Charts in SAS
For reference 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.