GAM in R – How to Obtain the Model Coefficients of Generalized Additive Models

generalized-additive-modelmodelingnonlinear regressionr

I have been trying to reconcile R coefficients with actual coefficients for simulated data which follows the equation:
$$
y = \alpha + \beta \cdot f(x) + \epsilon
$$

where $\alpha$ is intercept and $\beta$ is the slope value.

When I fit the GAM model in R using gam(y~s(x), data = data, method = "REML") from mgcv package, and I print the summary. I only get the intercept value, that is, $\alpha$.
I want to know: how can I obtain the coefficient for $\beta$ which I multiplied with $x$ in the start?

Best Answer

The model you fitted with {mgcv} is

$$ y_i = \alpha + f(x_i) + \varepsilon_i $$

not

$$ y_i = \alpha + \beta \cdot f(x_i) + \varepsilon_i $$

So that makes me a little unsure as to what $\beta$ you want. In the {mgcv} formulation, the smooth function $f$ is parameterised as a penalised spline and represented as a sum of one or more ($K$) basis functions, each of which has a coefficient $\beta_k$

$$ f(x_i) = \sum_{k=1}^{K} \beta_k b_k(x_i) $$

Hence, if you want those $\beta_k$, use the coef() method

library(mgcv)
set.seed(2) ## simulate some data... 
dat <- gamSim(1, n = 400, dist = "normal", scale = 2)
m <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat)
coef(m)

The last line yields:

> coef(m)                                                                    
  (Intercept)       s(x0).1       s(x0).2       s(x0).3       s(x0).4 
 7.833279e+00  2.173964e-01  3.805544e-01 -1.356960e-01 -3.768858e-01 
      s(x0).5       s(x0).6       s(x0).7       s(x0).8       s(x0).9 
-4.175098e-02  3.566379e-01 -1.460338e-02  1.662533e+00 -1.107835e-02 
      s(x1).1       s(x1).2       s(x1).3       s(x1).4       s(x1).5 
-5.169824e-02 -3.356803e-01 -7.802932e-02  2.992721e-01 -7.940761e-02 
      s(x1).6       s(x1).7       s(x1).8       s(x1).9       s(x2).1 
-2.829178e-01 -1.044189e-01 -1.378039e+00  1.520851e+00 -6.550020e+00 
      s(x2).2       s(x2).3       s(x2).4       s(x2).5       s(x2).6 
 1.005427e+01  2.136084e+00  1.614333e+00 -2.352140e+00  1.495629e+00 
      s(x2).7       s(x2).8       s(x2).9       s(x3).1       s(x3).2 
-1.550494e+00  9.859330e+00  5.834315e+00  1.083155e-10  5.828135e-11 
      s(x3).3       s(x3).4       s(x3).5       s(x3).6       s(x3).7 
-5.924120e-11  9.849940e-11  4.198290e-11  1.014248e-10  3.309607e-11 
      s(x3).8       s(x3).9 
 4.894399e-10 -2.082265e-01