Posterior probability for models with splines or: How to use posterior_smooths?

@paul.buerkner suggested posterior_smooths as a substitute/work-around for hypothesis() for models with splines (Using **hypothesis()** with **s()** from **brms**).

However, I can‘t get to grips with this approach.

I try to explain what I want to achieve:

seed <- 0
dat <- mgcv::gamSim(1, n = 200, scale = 2)
fit <- brm(y ~ s(x0), data = dat)

From this plot, how do I calculate the posterior probability for e.g. that y increases by more than 2 between x0=0 and x0=0.5?


I think I got it figured out now.

newdata <- data.frame(x0 = c(0, 0.5))
post <- posterior_smooths(fit, smooth = "s(x0)", newdata = newdata)
sum(post[,2] - post[,1] > 2 )/length(post[,1])

Could someone please confirm that I got it right? Thanks.

yes that does look correct to me. instead of sum() / length() you can also just use mean()

1 Like