ps {quantregGrowth} | R Documentation |
Specifying a smooth term in the gcrq formula.
Description
Function used to define the smooth term (via P-splines) within the gcrq formula. The function actually does not evaluate a (spline) smooth, but simply it passes relevant information to proper fitter functions.
Usage
ps(..., lambda = -1, d = 3, by=NULL, ndx = NULL, deg = 3, knots=NULL,
monotone = 0, concave = 0, var.pen = NULL, pen.matrix=NULL, dropc=TRUE,
center=TRUE, K=NULL, decom=FALSE, constr.fit=TRUE, shared.pen=FALSE,
st=FALSE, ad=0)
Arguments
... |
The covariate supposed to have a nonlinear relationship with the quantile curve(s) being estimated. A B-spline is built, and a (difference) penalty is applied. In growth charts this variable is typically the age. If the covariate is a factor, category-specific coefficients are estimated subject to a lasso penalty. See the last example in ?gcrq. A matrix of (continuous) covariates can be also supplied to perfom variable selection (among its columns). |
lambda |
A supplied smoothing parameter for the smooth term. If it is negative scalar, the smoothing parameter is estimated iteratively as discussed in Muggeo et al. (2021). If a positive scalar, it represents the actual smoothing parameter. If it is a vector, cross validation is performed to select the ‘best’ value. See Details in |
d |
The difference order of the penalty. Default to 3 Ignored if |
by |
if different from |
ndx |
The number of intervals of the covariate range used to build the B-spline basis. Non-integer values are rounded by |
deg |
The degree of the spline polynomial. Default to 3. The B-spline basis is composed by |
knots |
The knots locations. If |
monotone |
Numeric value to set up monotonicity restrictions on the first derivative of fitted smooth function
|
concave |
Numeric value to set up monotonicity restrictions on the second derivative of fitted smooth function
|
var.pen |
A character indicating the varying penalty. See Details. |
pen.matrix |
if provided, a penalty matrix |
dropc |
logical. Should the first column of the B-spline basis be dropped for the basis identifiability? Default to |
center |
logical. If |
K |
A scalar tuning the selection of wiggliness of the smoothed curve when |
decom |
logical. If |
constr.fit |
logical. If |
shared.pen |
logical. If |
st |
logical. If |
ad |
a positive number to carry out a form of adaptive lasso. More specifically, at each step of the iterative algorithm, the penalty is |
Details
If a numeric variable has been supplied, ps()
builds a B-spline basis with number of columns equal to ndx+deg
(or length(knots)-deg-1
). However, unless dropc=FALSE
is specified, the first column is removed for identifiability, and the spline coefficients are penalized via differences of order d
; d=0
leads to a penalty on the coefficients themselves. If pen.matrix
is supplied, d
is ignored. Since versions 1.5-0 and 1.6-0, a factor or matrix can be supplied.
lambda
is the tuning parameter, fixed or to be estimated. When lambda
=0 an unpenalized (and typically wiggly) fit is obtained, and as lambda increases the curve gets smoother till a d-1
degree polynomial. At 'intermediate' lambda values, the fitted curve is a piecewise polynomial of degree d-1
.
It is also possible to put a varying penalty via the argument var.pen
. Namely for a
constant smoothing (var.pen=NULL
) the penalty is \lambda\sum_k |\Delta^d_k|
where
\Delta^d_k
is the k-th difference (of order d
) of the spline coefficients. For instance if d=1
,
|\Delta^1_k|=|b_k-b_{k-1}|
where the b_k
are the spline coefficients.
When a varying penalty is set, the penalty becomes \lambda\sum_k |\Delta_k^d| w_k
where the weights w_k
depend on var.pen
; for instance var.pen="((1:k)^2)"
results in w_k=k^2
. See models m6
and m6a
in the examples of gcrq
.
If decom=TRUE
, the smooth can be plotted with or without the fixed part, see overall.eff
in the function plot.gcrq
.
Value
The function simply returns the covariate with added attributes relevant to smooth term.
Note
For shape-constrained fits, use constr.fit=FALSE
only if you are using a single full and uncentred basis, namely something like
gcrq(y~0+ps(x, center=FALSE, dropc=FALSE, monotone=1, constr.fit=FALSE),..)
.
Author(s)
Vito M. R. Muggeo
References
Muggeo VMR, Torretta F, Eilers PHC, Sciandra M, Attanasio M (2021). Multiple smoothing parameters selection in additive regression quantiles, Statistical Modelling, 21, 428-448.
For a general discussion on using B-spline and penalties in regression model see
Eilers PHC, Marx BD. (1996) Flexible smoothing with B-splines and penalties. Statistical Sciences, 11:89-121.
See Also
Examples
##see ?gcrq
##gcrq(y ~ ps(x),..) #it works (default: center = TRUE, dropc = TRUE)
##gcrq(y ~ 0 + ps(x, center = TRUE, dropc = FALSE)) #it does NOT work
##gcrq(y ~ 0 + ps(x, center = FALSE, dropc = FALSE)) #it works