ps()#
- liesel_ptm.ps(x, nbases, xname=None, knots=None, order=3, outer_ok=False, penalty=None, diagonalize_penalty=True, scale_penalty=True, constraint='sumzero_term', constraint_matrix=None)[source]#
Create a P-spline basis.
Convenience function to build a B-spline/P-spline basis for a numeric predictor. It constructs knots (if not provided), builds a basis function that evaluates the B-spline basis, attaches a difference-penalty (by default a second-order random-walk penalty), and returns a
Basisinstance. Optional post-processing steps like scaling the penalty, diagonalization and constraint application are supported and provided with sensible defaults.- Parameters:
x (
Union[Array,ndarray,bool,number,bool,int,float,complex,Series,Var]) – Predictor values or an observed variable. If an array or Series is provided,xnameshould be set to produce a named observation variable.nbases (
int) – Number of basis functions (parameters) to use for the P-spline.xname (
str|None) – Name for the created observation variable whenxis not already aliesel.model.Var. (default:None)knots (
Union[Array,ndarray,bool,number,bool,int,float,complex,None]) – Knot locations for the B-spline basis. IfNoneequidistant knots are generated based on the data andnbases. (default:None)order (
int) – Order of the B-spline (degree + 1). Default is 3 (cubic splines). (default:3)outer_ok (
bool) – Passed to the underlying basis generator to control behavior for observed values outside the internal knot range. (default:False)penalty (
Union[Array,ndarray,bool,number,bool,int,float,complex,None]) – Penalty matrix to use. IfNonea default P-spline penalty is created using a second-order difference. (default:None)diagonalize_penalty (
bool) – IfTrue(default), diagonalize the penalty. (default:True)scale_penalty (
bool) – IfTrue(default), scale the penalty matrix to improve numeric conditioning. (default:True)constraint (
Optional[Literal['sumzero_term','sumzero_coef','constant_and_linear','custom']]) – Optional constraint to apply to the basis (seeBasis.reparam_constraint()). IfNoneno constraint is applied. (default:'sumzero_term')constraint_matrix (
Union[Array,ndarray,bool,number,bool,int,float,complex,None]) – Custom constraint matrix used whenconstraint=='custom'. (default:None)
- Return type:
Basis- Returns:
A configured
Basisinstance representing the P-spline basis.