tp {amer} | R Documentation |
Generate a truncated power basis for penalized spline smoothing.
tp(x, degree=1, k=15, by, allPen=FALSE, varying, diag=FALSE, knots=seq(min(x), max(x), l = k - degree + 2)[-c(1, k - degree + 2)], centerscale=NULL, scaledknots=FALSE)
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 equidistant knots. For quantile-based knots at the (i+1)/(k+2)-quantiles for i=1,...,k use knots=quantile(x, probs = (2:(k - degree + 1))/(k - degree + 2)) |
centerscale |
numeric(2), center&scale x by these values if not NULL |
scaledknots |
boolean, are knots given for the rescaled x-values? |
list with entries:
"X"
: n x degree
design matrix for unpenalized part (without intercept) (or a list of those for every level of by if allPen=F),
"Z"
: n x (k-degree)
design matrix for penalized part (or a list of those for every level of by if allPen=F),
Truncated power bases have degree
unpenalized basis functions, namely x^1,..., x^{degree} and k-degree
penalized basis functions that contain the positive part (x-kappa_j)^degree for knots kappa_j, j=1,dots,k-degree
.
This function can be used as a reference when implementing other basisGenerators
that can be used for amer
-fits.
All such functions need to return a list of at least X (unpenalized basis functions, a matrix with zero columns if there are none of those), and Z (penalized basis functions)
that has a call
-attribute with the expanded call returned by expand.call()
. All such functions need to have at least arguments x, by, allPen, diag
and varying
.
See also section 4.4 in the vignette for an example on how to write your own basis-generating functions.
Fabian Scheipl