Specifying knot positions in splines in BRMS

Hi,

Does anyone have an example of how to specify the position of knots in a spline in BRMS? I have done it like so:

knots.l <- list(delta=0:12)
mdl <- brm(y~s(delta),data=fit.dat,knots=knots.l)

However, this doesn’t seem to be getting picked up by brm - the resulting model has only 8 parameters corresponding to the spline term, rather than the expected 13.

Additional question for extra points: what happens when you want to have multiple splines e.g. for distributional regression e.g.

mdl ← brm(brmformula(y~s(delta),sigma~s(delta)),…)

Thanks,

Mark

  • Operating System: Arch Linux
  • brms Version: 2.6.0

In order for knots to be picked up, you need to specify k in s(...). This is only related to how mgcv handles splines and I have no control over that via brms. However, there was a problem in brms that may have prevented knots from being passed correctly in models with multiple splines. This should be fixed this in the brms version on GitHub.

Here is an example that works for me in the sense that results differ based on the chosen knots:

set.seed(2)
dat <- mgcv::gamSim(1,n=400,dist="normal",scale=2)

library(brms)
b2 <- brm(y~s(x2, k = 3), knots = list(x2 = c(0, 0.1, 0.2)), data=dat)
summary(b2)
marginal_smooths(b2)

b3 <- brm(y~s(x2, k = 3), knots = list(x2 = c(0.8, 0.9, 1)), data=dat)
summary(b3)
marginal_smooths(b3)
3 Likes