I kindly request your help with specifying a certain prior distribution using set_prior function in the brms package.
The parameter ˮlogbˮ is 16-dimensional and depends on the covariate ˮcompoundˮ (categorical covariate with 16-levels). I need to set a prior for it, which could be - for instance – a 16-dimensional normal distribution with null covariance.
I fail to write the right R code for such a multidimensional prior and its covariance. Could you please help me?
Just want to check here. in dr.fun.m6 you have log(exp(logc)) which is just logc. And then you have a triple-exponential of logd. Is this the formula you intend?
I think your question might have an easy answer, but then there’s a subtlety that may or may not matter to you. The easy answer is that you 16-dimensional prior with null covariance is what you achieve by putting normal priors on all of the margins, which in turn is what you achieve by assigning some prior to the coefficients for nlpar = "logb". So maybe that already solves your question?
However, now the subtlety: the categorical covariate will get dummy coded with a reference level and 15 non-reference levels, meaning that by setting independent marginal priors on the intercept and then on the 15 coefficients, the 15 non-reference levels will necessarily have higher marginal prior variance than the reference level. One way to avoid this is to code comp not as a 16-level factor but as 15 binary covariates coded -1/1 instead of 0/1. Then, if independent, symmetrical, zero-centered priors are assigned to all 15 of those covariates, you will end up with prior symmetry across all of the levels of comp. The intercept will no longer correspond to a reference level, but rather to some hypothetical construct that sits directly “in between” belonging to and not belonging to each category.
Thank you for the answer. Yes, I confirm that the model formula is correct as it is.
The inconvenience of the first solution is that I can only specify one single prior for all margins of logb, which is not in line with my real data. “Comp” exhibits different effects on different logb’s and this is what I want to have it reflected in the priors.
The second solution is also inconvenient because I lose the interpretation of the effects, to which I attach importance.
Finally, I did not receive answer to my question: is this not possible to specify a multi-dimensional prior as argument in set_prior?
Brms has no problem specifying some multidimensional priors, and substantial problem specifying others.
When you call
this is already a multidimensional prior on the levels of logb, it’s just that the covariance is null 15 of the margins are the same, and are all higher variance than the margin of the reference category.
If you want to specify the 16 margins independently, but are still ok with null covariance, you can explicitly unpack the factor covariate to it’s 15 columns in the design matrix as part of your input data, and then pass the desired priors on the coefficients via the coef argument in set_prior. However, unless you are willing to encode these columns using something other than dummy coding, you will still be restricted to priors in which the prior variance is higher for 15 levels than for the reference level.
As far as I know, it is not possible to specify multivariate priors with non-null covariance except by getting really hack-y at the level of the generated Stan code. If you’d like to get hack-y, you can specify whatever prior you want by using stanvars to inject arbitrary Stan code into your model block.
To add on what @jsocolar already described, if you want to put a different prior on each level of comp, you can change
to
logb ~ 0 + comp
which supresses the intercept and will estimate an effect for each level of comp, instead of 1 reference level and 15 differences. Then you can set your priors: