BasisBuilder.ts()#
- BasisBuilder.ts(*x, k, penalty_order=None, knots=None, absorb_cons=True, diagonal_penalty=True, scale_penalty=True, basis_name='B')[source]#
Thin plate spline basis and penalty matrix with null space penalty.
- Parameters:
k (
int) – Number of (unconstrained) bases.penalty_order (
int|None, default:None) – Order of the penalty. Quote from mgcv: “The default is to set this to the smallest value satisfying2*penalty_order > d+1wheredis the number of covariates of the term.”knots (
Array|ndarray|bool|number|bool|int|float|complex|None, default:None) – Knots used to set up the basis. IfNone(default), a set knots will be set up automatically.absorb_cons (
bool, default:True) – Whether the default identification constraint should be applied by reparameterization and absorbing the reparameterization matrix into the basis and penalty matrices for computational efficiency. IfFalse, the basis is unconstrained, ifTrueit receives a sum to zero constrained. Also seeBasis.constrain().diagonal_penalty (
bool, default:True) – Whether the penalty matrix associated with this term should be reparameterized into a diagonal matrix. In this case, the basis matrix is reparameterized accordingly. This can be beneficial for posterior geometry, which is why it is the default. Also seeBasis.diagonalize_penalty().scale_penalty (
bool, default:True) – Whether the penalty matrix should be scaled such that its infinity norm is one. This can improve numerical stability, which is why it is done by default. Also seeBasis.scale_penalty().basis_name (
str, default:'B') – Function-name for the basis matrix. If"B", and the basis is a function of the variable"x", the full name of theBasisobject will be"B(x)". Names are made unique by appending a counter if necessary.
- Return type:
Notes
This basis is initialized with
use_callback=Trueandcache_basis=True. SeeBasisfor details.This method internally calls the R package mgcv to set up the basis and penalty. The mgcv documentation provides further details.
References
Wood, S.N. (2003) Thin-plate regression splines. Journal of the Royal Statistical Society (B) 65(1):95-114.
Wood, S.N. (2017) Generalized Additive Models: An Introduction with R (2nd edition). Chapman and Hall/CRC.
R package mgcv https://cran.r-project.org/web/packages/mgcv/index.html
Examples
>>> import liesel_gam as gam >>> df = gam.demo_data(n=100) >>> registry = gam.PandasRegistry(df) >>> bb = gam.BasisBuilder(registry) >>> bb.ts("x_nonlin", k=20) Basis(name="B(x_nonlin)")