0
$\begingroup$

I have generated a dataset with two covariates x1 and x2 and have fitted a gam model with k=5. The R code is as follows:

library(mgcv)

set.seed(123)

n <- 30
x1 <- runif(n,0,1)
x2 <- runif(n,0,1)
noise <- rnorm(n, 0,1)
y <- sin(2*pi*x1)+0.5*x2+noise

model <- gam(y ~ s(x1, k=5) + s(x2,k=5), family = gaussian()) 

summary(model)
plot(model)

model.matrix(model)

The model.matrix() function provides the design matrix having columns:(Intercept),s(x1).1, s(x1).2, s(x1).3, s(x1).4, s(x2).1, s(x2).2, s(x2).3, s(x2).4. My question is how to arrive at the values for the spline functions for the variable x1 and x2. What is the transformation or decomposition that is being applied to the raw data (x1 and x2) to obtain these values s(x1).1, s(x1).2, s(x1).3, s(x1).4, s(x2).1, s(x2).2, s(x2).3, s(x2).4?

Also, why do we observe negative values for these columns s(x1).1,...,s(x1).4 inspite of the variable x1 being positive?

$\endgroup$
6
  • $\begingroup$ Does this answer your questions? stats.stackexchange.com/a/613296/1390 If not, can you explain what's missing and I'll try to answer $\endgroup$ Jun 17, 2023 at 12:17
  • $\begingroup$ How to interpret the smoothing terms? $\endgroup$
    – T_S
    Jun 19, 2023 at 7:16
  • $\begingroup$ What do you mean by "smoothing terms"? Do you mean the coefficients? Or the values of the basis functions? $\endgroup$ Jun 19, 2023 at 9:07
  • $\begingroup$ The values as well as the coefficients. How do I understand the impact of a covariate on the dependent variable? $\endgroup$
    – T_S
    Jun 19, 2023 at 10:06
  • 1
    $\begingroup$ You don't; there's no point looking at the coefficients for the TPRS. You plot the estimated smooth function. $\endgroup$ Jun 19, 2023 at 12:29

0