PSpline#
- class superglm.PSpline(
- n_knots: int = 10,
- 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=None,
- m: int | tuple[int, ...] = 2,
- lambda_policy: LambdaPolicy | dict[str, LambdaPolicy] | None = None,
- shape_engine: Literal['qp', 'scop'] = 'qp',
Bases:
_BSplineBaseP-spline: B-spline basis with a discrete-difference penalty.
This is the concrete P-spline implementation. For the recommended public API, use
Spline()which dispatches toPSpline,NaturalSpline, orCubicRegressionSplinebased onkind.The
mparameter controls the discrete difference order(s) for the penalty (default 2, second-difference).Evenly spaced knots, placed by the
"uniform"rule or stated at its positions, take the standard difference penalty of Eilers and Marx (1996). On unevenly spaced stated or quantile-placed knots the standard penalty no longer measures wiggliness, so they take the general difference penalty of Li and Cao (2022, arXiv:2201.06808), whose null space is the polynomials of degree belowmhowever the knots are spaced, scaled to the standard penalty’s size. Knots too uneven for it in double precision take the standard penalty with those polynomials projected out. A penalty order abovedegreekeeps the standard penalty.- Parameters:
- n_knotsint
Number of interior knots.
- degreeint
B-spline polynomial degree.
- knot_strategystr
“uniform” (default), “quantile”, “quantile_rows”, or “quantile_tempered”.
- penaltystr
“ssp” enables SSP reparametrisation, “none” disables it.
- selectbool
If True, decompose the spline into null-space (linear) and range-space (wiggly) subgroups for three-way selection: nonlinear -> linear -> dropped.
Double penalty: The null-space (linear) subgroup is penalised with a ridge penalty (
penalty_matrix=eye(1)). Withfit_reml(), REML estimates separate lambdas for the linear and spline subgroups — driving the linear lambda to infinity effectively zeros the linear component (three-way selection: nonlinear -> linear -> dropped). See Wood (2011).- knotsarray-like or None
Explicit interior knot positions.
- constraintConstraintSpec, ConstraintRules or None
Public shape-constraint token, or fit-time rules joined with
&into aConstraintRules. UseConstraint.fit.increasing,Constraint.fit.decreasing,Constraint.fit.convex,Constraint.fit.concave,Constraint.postfit.increasing,Constraint.postfit.decreasing,Constraint.postfit.convex, orConstraint.postfit.concave. ForPSpline, fit-time shape constraints apply on the spline term’s linear-predictor contribution and, by default, use the constrained QP solver path thatBSplineSmoothuses: monotone is non-negative (or non-positive) first differences of the B-spline coefficients, which holds the curve monotone everywhere on the knot range, and convex/concave use the exact curvature rows. This works in both exact anddiscrete=Truefitting paths. Withfit_reml(), fixed lambdas work directly; automatic lambda estimation uses the QP passthrough heuristic (unconstrained REML followed by constrained refit). Fit-time convexity/concavity is supported for degrees one through three; higher degrees require aConstraint.postfit.*token.- shape_engine{“qp”, “scop”}
The engine for a fit-time shape constraint:
"qp", the path above."scop"named the SCOP reparameterization (Pya and Wood, 2015), which 0.41.0 fitted every shape-constrained P-spline on. It is retired: the constraint fits on the QP with aUserWarning, and so does aPSplinesaved on SCOP when it is refitted.