Using pp_check for Dirichlet model

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

2 Likes

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

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?

If anybody has any suggestions I am all ears.

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

1 Like

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/9qkhj/

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 for the format you need to get your data and posterior draws into.

@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,

1 Like

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