Generate basis functions for penalized spline smoothing.

Share:

Description

tp generates a truncated power basis and bsp generates a reparameterized b-spline basis for penalized spline smoothing.

Usage

1
2
3
4
5
6
7
tp(x, degree=1, k=15, by=NULL, allPen=FALSE, varying=NULL, diag=FALSE,
    knots=quantile(x, probs = (1:(k - degree))/(k - degree  + 1)), 
    centerscale=NULL, scaledknots=FALSE)
    
bsp(x, k=15, spline.degree=3, diff.ord=2, knots, by,
    allPen=FALSE, varying, diag=FALSE)
    

Arguments

x

covariate for the smooth function

degree

integer: degree of truncated polynomials (0: piecewise constant, 1: piecewise linear etc..)

k

integer: dimensionality of the basis (i.e.: number of knots + degree)

by

factor variable: estimate separate functions for each level - this assumes standard treatment contrasts for the supplied factor.

allPen

boolean: if TRUE, make design for group-specific curves with common smoothing parameter: all parameters (including the normally unpenalized basis functions in X) are penalized, every level of "by" has the same amount of smoothing if FALSE, make design for separate curves for each by-level: separate smoothing parameters for every level of "by", unpenalized estimates for the coefficients associated with X

varying

numeric: if not NULL, a varying coefficient model is fit: f(x,varying) = f(x)*varying

diag

logical: force a diagonal covariance-matrix for the random effects for X if allPen=TRUE?

knots

vector of knot locations (optional). Defaults to quantile-based knots at the i/(k+1-degree)-quantiles for i=1,…,k-degree.

centerscale

numeric(2): center&scale x by these values if not NULL

scaledknots

boolean: are knot locations given for the rescaled x-values?

spline.degree

integer: degree of B-splines (defaults to cubic)

diff.ord

integer: order of the difference penalty on the un-reparamerized spline coefficients. Defaults to 2, that is, penalized deviations from linearity.

Details

tp generates truncated power bases which have degree unpenalized basis functions, namely x^1,…, x^{degree} and k-degree penalized basis functions that contain the positive part (x-κ_j)^{degree} for knots κ_j, j=1,dots,k-degree. This function can be used as a reference when implementing other basisGenerators that can be used for additive models through cpglmm.

bsp generate a b-spline basis with equidistant knots in mixed model reparameterization.

Value

list with entries: "X": For tp, it is an n x degree design matrix for unpenalized part (without intercept) (or a list of those for every level of by if allPen=F); and for bsp, it is an n x (diff.ord - 1) design matrix for unpenalized part (without intercept).

"Z": For tp, it is an n x (k-degree) design matrix for penalized part (or a list of those for every level of by if allPen=F); and for bsp, it is an n x (k - diff.ord+1) design matrix for penalized part.

Note

These are from the amer package that has retired from CRAN.

Author(s)

Fabian Scheipl fabian.scheipl@googlemail.com