# Using pp\_check for Dirichlet model

**URL:** <https://discourse.mc-stan.org/t/using-pp-check-for-dirichlet-model/8033>\
**Category:** brms\
**Created:** [March 13, 2019, 10:54am UTC](https://discourse.mc-stan.org/t/using-pp-check-for-dirichlet-model/8033 "2019-03-13T10:54:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cian](https://avatars.discourse-cdn.com/v4/letter/c/97f17d/32.png) [@Cian](https://discourse.mc-stan.org/u/Cian)\
**Post date:** [March 13, 2019, 10:54am UTC](https://discourse.mc-stan.org/t/using-pp-check-for-dirichlet-model/8033/1 "2019-03-13T10:54:04Z")

</div>

Please also provide the following information in addition to your question:

- Operating System: Windows 10
- brms Version: 2.7.3

Hello, I am relatively new to Stan and brms. I fiited a Dirichlet model and I tried to use the pp\_check function on my model fit but I get the error:

Error in validate\_y(y) : ‘y’ must be a vector or 1D array.

I assume this is because I have multiple response variables. However I do not know how to indicate to the function to check a specific response variable.

Here is a reproducible example:

########

A\<-rnorm(40,2,0.5)  
B\<-rnorm(40,2,0.5)  
C\<-rnorm(40,2,0.5)  
V1 \<- as.factor(rep(1:4, 10))  
V2 \<- as.factor(rep(1:4, 10))  
df \<- data.frame(A, B, C, V1, V2)

df\_prop\<-DR\_data(df[,1:3])  
df\_prop\<-as.matrix(df\_prop)  
df$prop\<-df\_prop

fit \<- brm(  
prop ~ V1 + (1|ID|V2), data = df, chains = 2, cores = 2, dirichlet(link = “logit”))

pp\_check(fit)

##########

Any help would be much appreciated.

Cian

---

<div class="post-metadata">

**Author:** ![paul.buerkner](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/paul.buerkner/32/3303_2.png) [@paul.buerkner](https://discourse.mc-stan.org/u/paul.buerkner)\
**Post date:** [March 13, 2019, 11:19am UTC](https://discourse.mc-stan.org/t/using-pp-check-for-dirichlet-model/8033/2 "2019-03-13T11:19:13Z")

</div>

That’s because pp\_check does not support dirichlet models. I just added an informative error message for that.

---

<div class="post-metadata">

**Author:** ![Cian](https://avatars.discourse-cdn.com/v4/letter/c/97f17d/32.png) [@Cian](https://discourse.mc-stan.org/u/Cian)\
**Post date:** [March 13, 2019, 11:50am UTC](https://discourse.mc-stan.org/t/using-pp-check-for-dirichlet-model/8033/3 "2019-03-13T11:50:52Z")

</div>

Thank you for the quick response.

Could you, or anyone else, propose an alternative way to compare simulated data from the model fit with the observed data?

---

<div class="post-metadata">

**Author:** ![Cian](https://avatars.discourse-cdn.com/v4/letter/c/97f17d/32.png) [@Cian](https://discourse.mc-stan.org/u/Cian)\
**Post date:** [March 18, 2019, 8:56am UTC](https://discourse.mc-stan.org/t/using-pp-check-for-dirichlet-model/8033/4 "2019-03-18T08:56:45Z")

</div>

If anybody has any suggestions I am all ears.

---

<div class="post-metadata">

**Author:** ![cavid](https://avatars.discourse-cdn.com/v4/letter/c/c67d28/32.png) [@cavid](https://discourse.mc-stan.org/u/cavid)\
**Post date:** [November 28, 2019, 4:32pm UTC](https://discourse.mc-stan.org/t/using-pp-check-for-dirichlet-model/8033/5 "2019-11-28T16:32:24Z")

</div>

Hi Cian,

Did you figure out a way to implement some model checking? I notice that kfolds also don’t work with the dricihlet family.

Perhaps the pp\_plots could be done for each variable of the Dirichlet distribution…?

Cavid

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [November 28, 2019, 5:19pm UTC](https://discourse.mc-stan.org/t/using-pp-check-for-dirichlet-model/8033/6 "2019-11-28T17:19:24Z")

</div>

Is there a reason for why you’re not modeling it as an ordinal regression in `brms`? If you then have `Dirichlet` **priors** on any predictors (that are ordered categorical), and which you try to estimate, that should work.  
[https://psyarxiv.com/x8swp/](https://psyarxiv.com/x8swp/)  
[https://psyarxiv.com/9qkhj/](https://psyarxiv.com/9qkhj/)

---

<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:** [December 1, 2019, 12:37pm UTC](https://discourse.mc-stan.org/t/using-pp-check-for-dirichlet-model/8033/7 "2019-12-01T12:37:03Z")

</div>

If you are willing to do mild preprocessing yourself, the `ppc_bars` and `ppc_bars_grouped` should work for you (will easily show the observed counts for each category vs. the predictions), see [https://mc-stan.org/bayesplot/reference/PPC-discrete.html](https://mc-stan.org/bayesplot/reference/PPC-discrete.html) for the format you need to get your data and posterior draws into.

---

<div class="post-metadata">

**Author:** ![cavid](https://avatars.discourse-cdn.com/v4/letter/c/c67d28/32.png) [@cavid](https://discourse.mc-stan.org/u/cavid)\
**Post date:** [December 1, 2019, 4:31pm UTC](https://discourse.mc-stan.org/t/using-pp-check-for-dirichlet-model/8033/8 "2019-12-01T16:31:01Z")

</div>

@martinmodrak yes thanks I’l fiddle around and should be able to do it with minimal work, would in general be nice to have the full diagniostic tools available for the compositional data.

@torkar I’m not sure an ordinal model works for me, as my predictors are not categorical, rather it is a compositional response variable , so continuous shares of various categories being predicted,

---

<div class="post-metadata">

**Author:** ![Cian](https://avatars.discourse-cdn.com/v4/letter/c/97f17d/32.png) [@Cian](https://discourse.mc-stan.org/u/Cian)\
**Post date:** [December 2, 2019, 2:15pm UTC](https://discourse.mc-stan.org/t/using-pp-check-for-dirichlet-model/8033/9 "2019-12-02T14:15:53Z")

</div>

@cavid I don’t remember what I did; it was nearly a year ago that I had this problem!
