jswesner / isdbayes

https://jswesner.github.io/isdbayes/
Other
1 stars 1 forks source link

Setting priors #1

Closed JPoppyRomera closed 6 months ago

JPoppyRomera commented 6 months ago

Hi there,

I am wanting to run a regression using the brm() function. The model works, however, I want to also set a prior whereby the model estimate (lambda) is -0.75. How would I go about doing this?

This is my code for the model so far,

Model_brm <- brm(mass | vreal(count, xmin, xmax) ~ group, data = Data, stanvars = stanvars, family = paretocounts(), chains = 1, iter = 1000)

Thanks for your help!

jswesner commented 6 months ago

Hi - You can set priors like any other brms model. Guidance for that is here: https://paul-buerkner.github.io/brms/reference/set_prior.html.

I can't tell from your question whether you want only the intercept to be -0.75 or the betas as well. Either way, remember that you also need to specify a standard deviation the prior. That is what makes it more or less informative. I'm guessing this is what you're after:

Model_brm <- brm(mass | vreal(count, xmin, xmax) ~ group, data = Data, stanvars = stanvars, family = paretocounts(), prior = c(prior(normal(-0.75, 0.1), class = "Intercept"), prior(normal(0, 0.5), class = "b")), chains = 1, iter = 1000)

That puts a prior of -0.75 on the intercept (whichever level of the group that is). It's fairly informative with a standard deviation of 0.1. The prior for "b" is for the difference between the intercept level and the other levels. It's currently assumed to be the same as the intercept (mean = 0) with an sd of 0.5.

JPoppyRomera commented 6 months ago

Thank you! I think that is what I am looking for!

I'm trying to use the brm function to run an ISD on some body mass data to analyze mass-abundance relationships. I wanted to set a prior for the model where the slope/exponent of this relationship is λ = -0.75 as predicted by metabolic theory (i.e., a mass-abundance slope of -0.75), to improve the model. This ISD method of analyzing mass-abundance/size-density relationships is new to me, so I just wanted to double check if my reasoning for setting this prior value is indeed correct?

jswesner commented 6 months ago

I see. In that case, you'll want the prior mean to be -1.75, not -0.75. The formula for the ISD from the MTE is lambda + 1 = log(a)/log(b) + 0.75, which means that a solution that leads to -0.75 requires lambda to be -1.75, since -1.75 + 1 = -0.75. (See Perkins et al. 2019 for a good example of this).

Perkins, D. M., Perna, A., Adrian, R., Cermeño, P., Gaedke, U., Huete-Ortega, M., ... & Yvon-Durocher, G. (2019). Energetic equivalence underpins the size structure of tree and phytoplankton communities. Nature communications, 10(1), 255.

JPoppyRomera commented 6 months ago

Ahh, of course. So my code will now be?

Model_brm <- brm(mass | vreal(count, xmin, xmax) ~ group, data = Data, stanvars = stanvars, family = paretocounts(), prior = c(prior(normal(-1.75, 0.1), class = "Intercept"), prior(normal(0, 0.5), class = "b")), chains = 1, iter = 1000)

Thank you for your help!

jswesner commented 6 months ago

Yep. That looks correct to me.