I was under the impression that the smooths fit with
mgcv were made identifiable through a sum to zero constraint - i.e. if one was to sum the smooth over the values of its covariates, it would equal zero. This question gives some background, with an excellent answer from @Gavin Simpson.
With single smooths, this seems to be the case:
set.seed(1234); dat <- gamSim(4); mod1<-gam(y ~ s(x1)+s(x2), data=dat) p<-predict(mod1,dat,type="terms") sum(p[,1]) # -8.729996e-16 sum(p[,2]) # -4.956868e-12
But when a smooth is interacted with a factor, this is no longer the case. Is this an error in my understanding, or is something else going on?
mod2<-gam(y ~ s(x2, by=fac), data=dat) p<-predict(mod2,dat,type="terms") head(p) sum(p[,1]) # 1.923649 sum(p[,2]) # 6.496321 sum(p[,3]) # 45.36179