Search code examples
rsplinemgcv

mgcv: How to get spline equations


Probably I'm not the only one to ask the following question concerning estimated equations in mgcv::gam.

Well, thing is I've surfed the internet in vain to get an explicit answer to how I should make the following output into a full equation that I can subsequently take to any other analytical software, especially GIS software, in order to map/project the equation onto a certain geographic space using predictors X1 & X2:

family = gaussian(link = "identity")

smooth class = p-spline

The following is a transposed output of spline function coefficients:

**Intercept** 2.121

**s(X1).1** -1.23E-07

**s(X1).2** 1.86E-07

**s(X1).3** -7.33E-08



**s(X2).1** -2.51E-08

**s(X2).2** 3.08E-07

**s(X2).3** -3.00E-08

It's clear that the output means: Y = 2.121 + (-1.231e-07 * s(X1).1) + (1.856e-07 * s(X1).2) + (-7.331e-08 * s(X1).3)…..

How can I mathematically interpret s(Xi).j? In other words could you please advise how to extract the exact full equations for p-spline from mgcv::gam?


Solution

  • This gives some necessary background of P-splines in mgcv: mgcv: how to extract knots, basis, coefficients and predictions for P-splines in adaptive smooth? but your question is not a duplicate. Very likely you have seen this thread.

    Exact math formula is ugly, because B-spline construction is recursive.

    Another thing is that mgcv imposes numerical centering to smooth functions. This is a reparametrization at run-time. There will be no beautiful formula for transformed basis, even if the original basis has one.

    Well, mgcv is written for R, so model estimation and prediction are expected to be handled in R. There are handy generic functions to do so in my linked answer. They are not exportable to your intended software.

    A possible remedy I could think of, is that you approximate those basis with linear interpolation, and export the interpolation function.