# How can I implement the Bayesian pairwise t-test using Stanfit object in R?

**URL:** <https://discourse.mc-stan.org/t/how-can-i-implement-the-bayesian-pairwise-t-test-using-stanfit-object-in-r/26335>\
**Category:** General\
**Tags:** rstan, techniques\
**Created:** [February 14, 2022, 11:30am UTC](https://discourse.mc-stan.org/t/how-can-i-implement-the-bayesian-pairwise-t-test-using-stanfit-object-in-r/26335 "2022-02-14T11:30:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsd353](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/dsd353/32/11480_2.png) [@dsd353](https://discourse.mc-stan.org/u/dsd353)\
**Post date:** [February 14, 2022, 11:30am UTC](https://discourse.mc-stan.org/t/how-can-i-implement-the-bayesian-pairwise-t-test-using-stanfit-object-in-r/26335/1 "2022-02-14T11:30:26Z")

</div>

I fitted a hierarchical regression model using RStan and want to implement the pairwise t-test in a Bayesian way.  
For example, my data involves 100 subjects and there are two conditions (say A, B).  
I fitted a linear regression model for each condition.

```nohighlight
y=K_(ij)*x

```

, where i and j denotes the subject and the condition, respectively.  
I fitted 200 Ks (100 subjects \* 2 conditions) using the hierarchical model and Stan.  
Therefore, I had 200 posterior distributions.  
My purpose is to test whether Ks in the condition A is significantly different from Ks in the condition B.  
In the classical statistics, the problem would be addressed by comparing the means of 100 Ks in the condition A with those of 100 Ks in the condition B using the pairwise t-test .  
Then, what is the appropriate Bayesian way for testing the difference of Ks between the conditions and how can I implement it using Stanfit object?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![js592](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@js592](https://discourse.mc-stan.org/u/js592)\
**Post date:** [February 14, 2022, 5:11pm UTC](https://discourse.mc-stan.org/t/how-can-i-implement-the-bayesian-pairwise-t-test-using-stanfit-object-in-r/26335/2 "2022-02-14T17:11:39Z")

</div>

Bayesian point hypothesis testing is a fairly nuanced topic. This webpage ([BEST: Bayesian estimation of groups](https://jkkweb.sitehost.iu.edu/BEST/)) might be a good place to start.
