# Shifted Wald (inverse Gaussian) family in brms

**URL:** <https://discourse.mc-stan.org/t/shifted-wald-inverse-gaussian-family-in-brms/23119>\
**Category:** Modeling\
**Tags:** brms\
**Created:** [June 22, 2021, 2:36am UTC](https://discourse.mc-stan.org/t/shifted-wald-inverse-gaussian-family-in-brms/23119 "2021-06-22T02:36:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DominiqueMakowski](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/dominiquemakowski/32/2315_2.png) [@DominiqueMakowski](https://discourse.mc-stan.org/u/DominiqueMakowski)\
**Post date:** [June 22, 2021, 2:36am UTC](https://discourse.mc-stan.org/t/shifted-wald-inverse-gaussian-family-in-brms/23119/1 "2021-06-22T02:36:26Z")

</div>

brms offers a practical tool to implement most of the solutions proposed to model reaction times (RT), which helps pushing the research forward, as these types of models were until now fairly complicated to implement.

However, the body of literature on RT modelling, including Jonas’ [famous RT post](https://lindeloev.github.io/shiny-rt/) and other papers ([Matzke, D., & Wagenmakers, E. J., 2009](https://link.springer.com/article/10.3758/PBR.16.5.798) or [Anders, R., Alario, F., & Van Maanen, L., 2016](https://hal.archives-ouvertes.fr/hal-01432292/file/2016-AndersEtal-PsychMeth.pdf)) mentions the **Shifted Wald** (i.e., shifted Inverse Gaussian) models.

As I couldn’t find this distribution in brmsfamily, I was wondering if it was complicated to add as a custom family - since the non-shifted `inverse.gaussian` already exists in base R? And if any guides for that were already existing?

---

<div class="post-metadata">

**Author:** ![martinmodrak](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/martinmodrak/32/133_2.png) [@martinmodrak](https://discourse.mc-stan.org/u/martinmodrak)\
**Post date:** [June 29, 2021, 11:46am UTC](https://discourse.mc-stan.org/t/shifted-wald-inverse-gaussian-family-in-brms/23119/2 "2021-06-29T11:46:15Z")

</div>

Hi,  
so shifted distributions require some special consideration, but I hope you will find my blog on adding a mixture of uniform and shifted lognormal as a custom distribution helpful:

[https://www.martinmodrak.cz/2021/04/01/using-brms-to-model-reaction-times-contaminated-with-errors/](https://www.martinmodrak.cz/2021/04/01/using-brms-to-model-reaction-times-contaminated-with-errors/)

> [@DominiqueMakowski](#):
>
> As I couldn’t find this distribution in brmsfamily, I was wondering if it was complicated to add as a custom family - since the non-shifted `inverse.gaussian` already exists in base R?

Implementation in base R unfortunately does not help implementing a distribution in Stan and inverse gaussian is not AFAIK implemented natively in Stan. However `brms` already has an implementation of inverse gaussian in Stan code which you can build upon. You can see the code by running:

```r
 brms::make_stancode(y ~1, family = "inverse.gaussian", data = data.frame(y = rinv_gaussian(10)))

```

Feel free to ask for any further clarifications or feedback!
