ps: Specifying a smooth term in the gcrq formula.

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/ps.R


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.


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=2, ridge=FALSE, decompose=FALSE)



The quantitative covariate supposed to have a nonlinear relationships with the quantiles. In growth charts this variable is typically the age.


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. (2020). 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 gcrq.


The difference order of the penalty. Default to 3.


if different from NULL, a numeric or factor variable of the same dimension as the covariate in ... In the numeric vector case the elements multiply the smooth, evaluated at the corresponding covariate values (i.e. a varying coefficient model).


The number of intervals of the covariate range used to build the B-spline basis. Non-integer values are rounded by round(). If NULL, default, the empirical rule of Ruppert is used, namely min(n/4,40). It could be reduced (but no less than 10, say) if the sample size is not large and the default value leads to some error in the fitting procedure, see section Note in gcrq.


The degree of the spline polynomial. Default to 3. The B-spline basis is composed by ndx+deg basis functions and if dropc=TRUE the first column is removed for identifiability (and the model intercept is estimated without any penalty).


The knots locations. If NULL, equispaced knots are set.


Numeric value to set up monotonicity restrictions on the first derivative of fitted smooth function

  • '0' = no constraint (default);

  • '1' = non-decreasing smooth function;

  • '-1' = non-increasing smooth function.


Numeric value to set up monotonicity restrictions on the second derivative of fitted smooth function

  • '0' = no constraint (default);

  • '1' = concave smooth function;

  • '-1' = convex smooth function.


A character indicating the varying penalty. See Details.


if provided, a penalty matrix A, say, such that A'A is the penalty matrix actually used in the estimation process. It overwrites ridge.


logical. Should the first column of the B-spline basis be dropped for the basis identifiability? Default to TRUE. Note, if dropc=FALSE is set, it is necessary to omit the model intercept AND center=FALSE or to set lambda.ridge>0 to fit the model.


logical. If TRUE the smooth effects are 'centered' over the covariate values, i.e. sum_i f(xi)=0.


A factor tuning selection of wiggliness of the smoothed curve. The larger K, the smoother the curve. Simulations suggest K=2. See details.


logical. If TRUE a ridge penalty is empoyed.


logical. If TRUE, the B-spline is decomposed into truncated power functions such as [x, ..., x^d-1, Z]. See Details.


When lambda=0 an unpenalized fit is obtained. At 'middle' lambda values, the fitted curve is a piecewise polynomial of order d-1. The fit gets smoother as lambda increases, and for a very large value of lambda, it approaches to a polynomial of degree d-1. It is also possible to put a varying penalty to set a different amount of smoothing. Namely for a constant smoothing (var.pen=NULL) the penalty is lambda sum_k |Δ^d_k| where Delta^d_k is the k-th difference (of order d) of the spline coefficients. For instance if d=1, |Δ^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 |Δ^d_k| w_k. The weights w_k depend on var.pen; for instance var.pen="((1:k)^2)" results in w_k=k^2. See model m5 in examples of gcrq.


The function simply returns the covariate with added attributes relevant to smooth term.


Vito M. R. Muggeo


Muggeo VMR, Torretta F, Eilers PHC, Sciandra M, Attanasio M (2020). Multiple smoothing parameters selection in additive regression quantiles, Statistical Modelling, to appear.

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



##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

quantregGrowth documentation built on March 27, 2021, 9:06 a.m.