s#

superglm.s(
column: Hashable,
*,
kind: Literal['cr', 'ps', 'bs', 'ns', 'cr_cardinal'] | None = None,
k: int | None = None,
n_knots: int | None = None,
degree: int = 3,
knot_strategy: Literal['uniform', 'quantile', 'quantile_rows', 'quantile_tempered'] = 'uniform',
penalty: Literal['ssp', 'none'] | None = 'ssp',
select: bool = False,
knots: ArrayLike | None = None,
discrete: bool | None = None,
n_bins: int | None = None,
extrapolation: Literal['clip', 'extend', 'error'] = 'clip',
boundary: tuple[float, float] | None = None,
knot_alpha: float = 0.2,
constraint: ConstraintSpec | ConstraintRules | None = None,
m: int | tuple[int, ...] = 2,
lambda_policy: LambdaPolicy | dict[str, LambdaPolicy] | None = None,
) → BoundTerm#

Describe a smooth effect of one numeric column.

For example, s("age", kind="cr", k=10) declares a cubic regression spline inside a family predictor. The model learns its basis and coefficients when fitted. All spline options have the same meaning as in Spline.

Parameters:
columnhashable

Label of the numeric input column, usually its name.

kind{“cr”, “ps”, “bs”, “ns”, “cr_cardinal”}, optional

Spline basis. Common choices are "cr" for cubic regression splines, the default, and "ps" for P-splines. See Spline for the other bases and for when a spline with no kind builds as "ps".

kint, optional

Public basis size. This limits flexibility; it is not the fitted effective degrees of freedom. Supply either k or n_knots.

n_knotsint, optional

Number of interior knots, as an alternative to k.

degreeint, default=3

Polynomial degree for bases that support this option. Cubic regression splines remain cubic.

knot_strategy{“uniform”, “quantile”, “quantile_rows”, “quantile_tempered”}, default=”uniform”

Knot-placement rule. "uniform" spaces knots evenly; "quantile" places them at quantiles of the distinct values, "quantile_rows" follows the training data and "quantile_tempered" tempers that concentration.

penalty{“ssp”, “none”} or None, default=”ssp”

Enable SSP basis reparametrization, or disable it with "none" (None also disables it).

selectbool, default=False

Add a penalty on the spline’s null space so that smoothing can also shrink directions left unpenalized by the ordinary wiggle penalty.

knotsarray-like, optional

Explicit interior knot positions, replacing automatic placement.

discretebool, optional

Request discrete evaluation for this term. None inherits the model setting.

n_binsint, optional

Bin count for discrete evaluation. None inherits the model setting.

extrapolation{“clip”, “extend”, “error”}, default=”clip”

Prediction outside the fitted boundaries: hold the boundary value, continue the basis, or raise an error.

boundarytuple of float, optional

Explicit lower and upper spline boundaries. Otherwise use the training range.

knot_alphafloat, default=0.2

Tempering control for "quantile_tempered" knot placement.

constraintConstraintSpec or ConstraintRules, optional

Requested shape constraint, or rules joined with &. See the SuperLSS note below.

mint or tuple of int, default=2

Penalty order: a difference order for P-splines or a derivative order for derivative-penalty bases. Multiple orders require a basis that supports multiple penalty components.

lambda_policyLambdaPolicy or dict of str to LambdaPolicy, optional

Control whether smoothing penalties are estimated or fixed. A mapping sets policies for the spline’s individual penalty components.

Returns:
BoundTerm

A spline declaration for the named column.

See also

Spline

Basis, knot, penalty and extrapolation options.

ti

An interaction between two declared spline terms.

Notes

SuperLSS enforces Constraint.fit rules on a term of any parameter: the smoothing is chosen without them and the coefficients are refitted under them at that smoothing. Effective degrees of freedom treat the rules that bind as fixed; standard errors and bands are those of the fit without the rules, drawn around the ruled curve, because which rules bind is itself estimated (see “What the intervals of a ruled term mean” in the shape-constraints guide). Constraint.postfit rules, which repair a curve after the fit, mean what they mean for SuperGLM: the term is fitted without the rule, and SuperLSS.apply_shape_postfit projects its curve onto the shape and withholds its standard errors.

Examples

>>> from superglm import s
>>> age = s("age", kind="cr", k=10)
>>> age.column
'age'