Better priors (non-flat) for GAMs (brms)

I appreciate that this is now an older posting and that @martinmodrak has provided an answer that solved @DominiqueMakowski’s original question. But I thought I’d briefly comment on this aspect of the question

In the toy example above, there is one fixed parameter (swt_1 ) which I assume is related to the smooth term (s(wt) ). However, I am not sure what does it mean (does it control the wigliness of the smooth term? or some other features of the splines?)

in case others arrive here while looking for info on priors for smooths in brms.

With these penalised splines we have terms in the spline basis expansion that are affected by the wiggliness penalty and terms that aren’t. For the default second derivative penalty, the linear and constant functions are in the null space of the penalty meaning that they aren’t affected by the penalty (the have 0 second derivative). Due to identifiability (sum to zero) constraints imposed on the basis expansions of all splines in one of these models so we can have an intercept term, the constant function is removed from the span of functions representable by the basis. That leaves the linear function only that is unpenalized.

When we cast these splines in random effect form, the functions in the penalty null space get treated as fixed effects terms in the model, while the basis functions in the range space (those affected by the penalty) are treated as random effect terms. In this fully Bayes approach we now need a prior on the otherwise unpenalized linear basis function, plus a prior for each smoothing parameter (penalty) associated with each smooth (usually this will be 1, but can be more if you are using tensor products or some of the fancier bases). In the random effect form we don’t put priors on the smoothing parameter(s) but on the variances (standard deviations) of the random effect. The variance of the random effect is inversely proportional to the smoothing parameter (smaller variances = larger smoothing parameters = less wiggly smooth functions).

Hence, in your model you have sds(swt_1), which is the variance (standard deviation) parameter for the wiggly basis functions - the further this is away from 0 the more wiggly the estimated smooth - and you have the swt_1 population (fixed) effect which is for that linear basis function.

brms knows about all this, and pulls the linear term back into the basis when you plot the estimated smooths or prior draws etc.

But you can pop a gaussian or t prior on the swt_1 term, for example, and another separate prior on the sds term, and then simulate from the prior distribution of the model (with prior_only = TRUE) and plot the prior draws using conditional_smooths() to see samples of smooths drawn from your prior. You should be looking at the amount of wigglines of the prior smooths to see if that about on average matches plausible range of wiggliness for the non-linear relationships you envisage based on your prior knowledge. You can also look at the values on the y axis to see if the implied effect sizes are reasonable given your prior expectations or not. Then you can adjust the priors you use until you effect sizes roughly in line with expectations and the same for the wigglinesses of the smooths implied by the prior.

8 Likes