BasisBuilder.cs()

BasisBuilder.cs()#

BasisBuilder.cs(x, *, k, penalty_order=2, knots=None, absorb_cons=True, diagonal_penalty=True, scale_penalty=True, basis_name='B')[source]#

Cubic regression spline basis and penalty matrix with null space penalty.

Parameters:
  • x (str | Var) – Name of input variable.

  • 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. If None (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. If False, the basis is unconstrained, if True it receives a sum to zero constrained. Also see Basis.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 see Basis.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 see Basis.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 the Basis object will be "B(x)". Names are made unique by appending a counter if necessary.

Return type:

Basis

Notes

This basis is initialized with use_callback=True and cache_basis=True. See Basis for details.

This method internally calls the R package mgcv to set up the basis and penalty. The mgcv documentation provides further details.

References

Examples

>>> import liesel_gam as gam
>>> df = gam.demo_data(n=100)
>>> registry = gam.PandasRegistry(df)
>>> bb = gam.BasisBuilder(registry)
>>> bb.cs("x_nonlin", k=20)
Basis(name="B(x_nonlin)")