Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Bayesian t-test in proc MCMC

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 01-04-2021 01:19 PM
(1105 views)

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?

1. Bayesian First Aid: One Sample and Paired Samples t-test - Publishable Stuff (sumsar.net)

2. BEST: Bayesian estimation of groups (iu.edu)

7 REPLIES 7

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@MichaelL_SAS or @StatDave_sas any suggestions or sample exmple?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

**Available on demand!**

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.