GAM using brm

Hi there, I am trying to study GAM with brm. In doing some examples, there are two things hard for to understand.

The data I used as examples:

set.seed(10)
dat <- gamSim(3,n=400)
head(dat)
image

First, I tried the following model:
fit1=brm(y~t2(x1,by=x2),data=dat,chains=1,iter=200)
image
The question: there is only one smooth term “sds(t2x1x2_1)”, but why is there two interaction terms of smooth x1 and numeric x2 in population-level effects? what do those two terms represent?

The second model is:
fit2=brm(y~s(x1,x2),data=dat,chains=1,iter=200)
image

The third model is:
fit3=brm(y~t2(x1,x2),data=dat,chains=1,iter=200)
image

Question: as far as I understand, both s(x1, x2) and t2(x1, x2) express the statistical model: y = f(x1) + f(x2) + f(x1, x2) + error. In the population-level effects, why are there two terms (sx1x2_1 and sx1x2_2) besides intercept in the second model while three terms (t2x1x2_1, t2x1x2_2, t2x1x2_3) in the third model?

Many thanks!

I’m sure @paul.buerkner can clarify further, but I’d note here that smooths in brms are implemented through mgcv. Accordingly, I’d recommend taking a look at articles like this:


or

to get a sense of the difference between a two-dimensional s() vs t2() smooth. Graphic pp_checks and conditional_smooths will tell you more what’s happening than trying to interpret the coefficients specifically.

1 Like

Many thanks! @franzsf. I will go through the materials you kindly provided.