ncs function

Tool to build the basis matrix and the penalty matrix of natural cubic splines.

Tool to build the basis matrix and the penalty matrix of natural cubic splines.

ncs builds the basis matrix and the penalty matrix to approximate a smooth function using a natural cubic spline.

ncs(xx, lambda, nknots, all.knots)

Arguments

  • xx: the explanatory variable.
  • lambda: an optional positive value that represents the smoothing parameter value.
  • nknots: an optional positive integer that represents the number of knots of the natural cubic spline. Default is m=[n13]+3m=[n^{\frac{1}{3}}]+3. The knots are located at the quantiles of order 0/(m1),1/(m1),,(m1)/(m1)0/(m-1),1/(m-1),\ldots,(m-1)/(m-1) of xx.
  • all.knots: logical. If TRUE, the set of knots and the set of different values of xxxx coincide. Default is FALSE.

Returns

  • xx: the explanatory variable xxxx with the following attributes: set of knots, basis matrix, penalty matrix, smoothing parameter (if it was specified), and other interest matrices.

References

Lancaster, P. and Salkauskas, K. (1986) Curve and Surface Fitting: an introduction. Academic Press, London. Green, P.J. and Silverman, B.W. (1994) Nonparametric Regression and Generalized Linear Models, Boca Raton: Chapman and Hall.

Author(s)

Luis Hernando Vanegas hvanegasp@gmail.com and Gilberto A. Paula

Examples

n <- 300 t <- sort(round(runif(n),digits=1)) t2 <- ncs(t,all.knots=TRUE) N <- attr(t2, "N") ## Basis Matrix M <- attr(t2, "K") ## Penalty Matrix knots <- attr(t2, "knots") ## Set of knots
  • Maintainer: Luis Hernando Vanegas
  • License: GPL-2 | GPL-3
  • Last published: 2023-04-22

Useful links