BasisBuilder.cc()#
- BasisBuilder.cc(x, *, k, penalty_order=2, knots=None, absorb_cons=True, diagonal_penalty=True, scale_penalty=True, basis_name='B')[source]#
Cyclic cubic regression spline basis and penalty matrix.
Basis for a penalized cubic regression spline whose ends match, up to second derivative.
- Parameters:
k (
int) – Number of (unconstrained) bases.penalty_order (
int, default:2) – Order of the penalty.knots (
Array|ndarray|bool|number|bool|int|float|complex|None, default:None) – Knots used to set up the basis. IfNone(default), a set of equidistant knots will be set up automatically, with the domain boundaries inferred from the minimum and maximum of the observed values.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.Cyclicity is enforced by matching the function and its derivatives at the domain boundaries. 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. (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.cc("x_nonlin", k=20) Basis(name="B(x_nonlin)")