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: _BSplineBase

P-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 to PSpline, NaturalSpline, or CubicRegressionSpline based on kind.

The m parameter 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 below m however 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 above degree keeps 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)). With fit_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 a ConstraintRules. Use Constraint.fit.increasing, Constraint.fit.decreasing, Constraint.fit.convex, Constraint.fit.concave, Constraint.postfit.increasing, Constraint.postfit.decreasing, Constraint.postfit.convex, or Constraint.postfit.concave. For PSpline, fit-time shape constraints apply on the spline term’s linear-predictor contribution and, by default, use the constrained QP solver path that BSplineSmooth uses: 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 and discrete=True fitting paths. With fit_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 a Constraint.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 a UserWarning, and so does a PSpline saved on SCOP when it is refitted.