I am right now doing my first baby steps with defining my own custom family in brms. When doing so I noticed that the code generated is not vectorized. Just take the default beta-binomial example from the vignette:
The Stan code will then loop over each observation.
I tried the “loop=FALSE” option from the dev version, but that still loops over each observation, because trials is being passed to the custom density. So I get this code then… which is presumably a bug (@paul.buerkner ?):
for (n in 1:N) {
target += beta_binomial2_lpmf(Y[n] | mu, phi, vint1[n]);
}
That does not look quite right to me. I would expect to get this:
You had a type in your second custom family. You wrote vars = "vint1[n]" but it should have been vars = "vint1". That said, this mistake can be captured and I will add a check for that.
Oh…user error… sorry for the noise. An error message would great indeed.
BTW… I took me quite some time to figure out how to pass into user likelihoods multiple int vectors. It’s vars=c("vint1", "vint2") and then I need to use vint(col1, col2)… but I don’t think it’s anywhere documented that you can pass to vint multiple columns. I always tried vint(col1) + vint(col2), but failed. It totally makes sense how you did it… but I overlooked the doc for this. A note for this would be great.
ahh… and the model I implemented is the one in OncoBayes2:
I did code it up for the 2 drug case… if that’s of interest to evaluate further as a future family in brms, then let me know and I post an issue for this. EDIT: I did not include the “EXNEX” stuff which requires heavy mixture model coding.
Maybe add it to the vignette on custom families to encourage people to contribute there? :) I will make a PR for my code of the natural scale parameterization of the lognormal