Fluorite | Level 6

## Bayesian t-test in proc MCMC

Is there any way yo perform Paired Bayesian t test in Proc MCMC ? I found the following documents to perform analysis in R and bugs. I am just wondering can we do the same Bayesian paired t-test in SAS?

3. GitHub - rasmusab/bayesian_first_aid: Inside every classical test there is a Bayesian model tryin...

7 REPLIES 7
SAS Super FREQ

## Re: Bayesian t-test in proc MCMC

Yes, you can model the pairs of differences by using a t distribution. For example,

MODEL diff = t(mean, sd, dof);

where the three distribution parameters (mean, sd, and dof) are defined by using programming statements and assigned different prior distributions. Once that is done, you can compute a t-statistic.

I haven't done this myself, but perhaps @MichaelL_SAS or @StatDave have additional comments or can direct you to a worked example.

Fluorite | Level 6

## Re: Bayesian t-test in proc MCMC

@MichaelL_SAS or @StatDave_sas any suggestions or sample exmple?

SAS Employee

## Re: Bayesian t-test in proc MCMC

PROC MCMC is a bit out of my wheelhouse, but I believe @Rick_SAS is pretty much correct. The t-distribution is one of the standard distributions recognized by PROC MCMC so it should just be a matter of specifying the the desired prior for the model parameters.

Based on the links you provided here's my quick attempt at mimicking the analysis of the new world data. I did just a quick scan of the link so I might not be matching the prior they used exactly but the results look to be in the same ballpark. I used PROC UNIVARIATE to compute the median absolute deviation of the difference and just by hand used that to determine the prior distribution for the mean and standard deviation based on my quick reading of the link.

``````data exData;
input y80 y01;
datalines;
9139	14620
7686	8767
9996	8729
5488	8231
5920	7740
4096	7264
4566	6408
4965	6283
5487	5740
5227	5116
2347	4124
3089	3240
1938	2789
;

data exData;
set exData;
diff = y01-y80;
run;

proc mcmc data=exData nMC=10000 seed=123456;
parms mu sigma dfm1 ;
prior mu ~ normal(1469.8, var=1134225000000);
prior sigma ~ uniform(1.065,1065000);
prior dfm1 ~ expon(scale=29);
df =dfm1 +1 ;
model diff ~ t(mu, sd=sigma, df);
run;

``````

@SteveDenham I don't think PROC GENMOD supports the REPEATED statement for a Bayesian analysis. While that analysis also probably could be programed in PROC MCMC another alternative would be to use the relatively new BGLIMM procedure.

## Re: Bayesian t-test in proc MCMC

@MichaelL_SAS  - you are absolutely right about the REPEATED statement not being supported for Bayesian analysis in GENMOD.  There was a note in the log that should have let me know, had I looked closely enough (it was buried amongst several pages of notes regarding compression and decompression of temp files for the analysis I had run).  Later today I will give BGLIMM a shot, when I get access to our SAS/STAT 15.1 machine.

SteveDenham

## Re: Bayesian t-test in proc MCMC

One way I have done Bayesian paired t is to use PROC GENMOD with a BAYES statement.  Try something like:

``````proc genmod data=yourdatainlongform;
class pair;
model response=pair;
bayes seed=1 coeffprior=normal;
run;``````

Here 'pair' would take on values like 'Pre' and 'Post'.  This is the simplest paired-t model.  Other covariates/factors can be added to reach the desired model.

SteveDenham

SAS Super FREQ

## Re: Bayesian t-test in proc MCMC

Hi @SteveDenham : I thought of that syntax but rejected it because I decided that it corresponds to an ordinary two-sample t test, not a paired t test. The long-form data does not allow the procedure to know which observations are pre/post, so it just compares the mean of the "pre" and "post" groups. Useful, to be sure, but not a paired t test.

## Re: Bayesian t-test in proc MCMC

Ulp, you are spot on @Rick_SAS .  To get this to be a paired t-test, it has to be a GEE type model.  How about this instead:

``````proc genmod data=for_stats_in_long_format ;
class pair studyid;
model result_n =
pair
/  type3;
repeated subject=subjectid  / type = un printmle ;
bayes statistics=all seed=1;
lsmeans pair/diff;
run;
``````

SteveDenham

Discussion stats
• 7 replies
• 1106 views
• 9 likes
• 4 in conversation