cobs {cobs99} | R Documentation |
Computes constrained quantile curves using linear or quadratic splines. The median spline (L_1 loss) is a robust (constrained) smoother.
cobs(x, y, constraint = c("none", "increase", "decrease", "convex", "concave", "periodic"), knots, nknots = if(lambda == 0) 6 else 20, method = "quantile", degree = 2, tau = 0.5, lambda = 0, ic = "aic", n.sub = n1000cut(n), knots.add = FALSE, pointwise, print.warn = TRUE, print.mesg = TRUE, trace = print.mesg, coef = rep(0,nvar), w = rep(1,n), maxiter = 20*n, lstart = 7872, toler.kn = 1e-6, eps = .Machine$double.eps, factor = 1) n1000cut(n)
x |
vector of covariate; missing values are omitted. |
y |
vector of response variable. It must have the same length as
x . |
constraint |
character (string) specifying the kind of constraint; must be one of the values in the default list, above; may be abbreviated. |
knots |
vector of locations of the knot mesh; if missing,
nknots number of knots will be created using the
specified method and automatic knot selection will be carried
out for regression B-spline (lambda=0); if not missing and
length(knots)==nknots , the provided knot mesh will be used in
the fit and no automatic knot selection will be performed;
otherwise, automatic knots selection will be performed on the
provided knots . |
nknots |
maximum number of knots; defaults to 6 for regression B-spline, 20 for smoothing B-spline. |
method |
character specifying the method for generating
nknots number of knots when knots is not provided;
"quantile" (equally spaced in percentile levels)
or "uniform" (equally spaced knots); defaults to "quantile". |
degree |
degree of the splines; 1 for linear spline and 2 for quadratic spline; defaults to 2. |
tau |
desired quantile level; defaults to 0.5 (median). |
lambda |
penalty parameter;
lambda = 0: no penalty (regression B-spline); lambda > 0: smoothing B-spline with the given lambda; lambda < 0: smoothing B-spline with lambda chosen by an information criterion, see ic . |
ic |
information criterion used in knot deletion and addition for regression B-spline method when lambda=0; "aic" (Akaike-type) or "sic" (Schwarz-type); default to "aic". |
n.sub |
integer, not larger than sample size n ; the
default has n.sub == n as long as n is less than 1000. |
knots.add |
logical indicating if an additional step of stepwise knot addition should be performed for regression B-splines. |
pointwise |
an optional three-column matrix with each row
specifies one of the following constraints:
|
print.warn |
logical flag for printing of interactive warning messages; true by default;
probably needs to be set to FALSE if performing simulation. |
print.mesg |
logical flag or integer for printing of intermediate messages; true
by default. Probably needs to be set to FALSE in simulations. |
trace |
integer >= 0 indicating how much the Fortran
routine drqssbc should print intermediate messages;
defaults to print.mesg . |
coef |
initial guess of the B-spline coefficients; default to a vector of zeros. |
w |
vector of weights the same length as x (y) assigned to both x and y; default to uniform weights adding up to one; using normalized weights that add up to one will speed up computation. |
maxiter |
upper bound of the number of iteration; default to 20*n. |
lstart |
starting value for lambda when performing parametric
programming in lambda if lambda < 0 ; defaults to
log(big)^2 . |
toler.kn |
numeric tolerance for shifting the boundary knots outside; default 1e-6 used to be built in. |
eps |
tolerance passed to qbsks and drqssbc . |
factor |
determines how big a step to the next smaller lambda should be while
performing parametric programming in lambda; the default 1
will give all unique lambda's; use of a bigger factor (> 1 & < 4)
will save time for big problems. |
n |
integer, the sample size. |
cobs()
computes the constraint quantile smoothing B-spline with
penalty when lambda is not zero.
If lambda < 0, an optimal lambda will be chosen using Schwarz type
information criterion.
If lambda > 0, the supplied lambda will be used.
If lambda = 0, cobs computes the constraint quantile regression B-spline
with no penalty using the provided knots or those selected by Akaike or
Schwarz information criterion.
an object of class cobs
, a list with components
call |
the cobs(..) call used for creation. |
tau, degree |
as input |
constraint |
as input (but no more abbreviated). |
call |
the cobs(..) call used for creation. |
coef |
B-spline coefficients. |
knots |
the final set of knots used in the computation. |
ifl |
exit code:
|
icyc |
length 2: number of cycles taken to achieve convergence for final lambda, and total number of cycles for all lambdas. |
k |
the effective dimensionality of the final fit. |
k0 |
(usually the same) |
x.ps |
the pseudo design matrix X (as returned by
qbsks ). |
resid |
vector of residuals from the fit. |
fitted |
vector of fitted values from the fit. |
SSy |
the sum of squares around centered y (e.g. for
computation of R^2.) |
lambda |
the penalty parameter used in the final fit. |
pp.lambda |
vector of all unique lambda's obtained from
parametric programming when lambda < 0 on input. |
sic |
vector of Schwarz information criteria evaluated at
pp.lambda . |
This is still a beta version, and we do appreciate comments and
suggestions; library(help = cobs)
shows the authors.
He, X. and Ng, P. (1999) COBS: Qualitatively Constrained Smoothing via Linear Programming; Computational Statistics 14, 315–337.
Koenker, R. and Ng, P. (1996) A Remark on Bartels and Conn's Linearly Constrained L1 Algorithm, ACM Transaction on Mathematical Software 22, 493–495.
Ng, P. (1996) An Algorithm for Quantile Smoothing Splines, Computational Statistics & Data Analysis 22, 99–118.
Bartels, R. and Conn A. (1980) Linearly Constrained Discrete L_1 Problems, ACM Transaction on Mathematical Software 6, 594–608.
A postscript version of the paper that describes the details of COBS can be downloaded from http://www.cba.nau.edu/pin-ng/cobs.html
smooth.spline
for unconstrained smoothing
splines; bs
for unconstrained (regression)
B-splines.
x <- seq(-1,1,,50) y <- (f.true <- pnorm(2*x)) + rnorm(50)/10 ## specify pointwise constraints (boundary conditions) con <- rbind(c( 1,min(x),0), # f(min(x)) >= 0 c(-1,max(x),1), # f(max(x)) <= 1 c(0, 0, 0.5))# f(0) = 0.5 ## obtain the median regression B-spline using automatically selected knots Rbs <- cobs(x,y,constraint="increase",pointwise=con) Rbs plot(x,y) lines(predict(Rbs), col = 2, lwd = 1.5) lines(spline(x,f.true), col = "gray40") Rbsub <- cobs(x,y,constraint="increase",pointwise=con, n.sub = 45) summary(Rbsub) lines(predict(Rbsub), col = 4, lwd = 1) ## compute the median smoothing B-spline using automatically chosen lambda Sbs <- cobs(x,y,constraint="increase",pointwise=con,lambda=-1) Sbs plot(Sbs$pp.lambda[-1], Sbs$sic[-1], log = "x", main = "SIC ~ lambda", xlab = expression(lambda), ylab = "SIC") axis(1, at = Sbs$lambda, label = expression(hat(lambda)), col.axis = 2, mgp = c(3, 0.5, 0)) Sb1 <- cobs(x,y,constraint="increase",pointwise=con,lambda=-1, degree=1) summary(Sb1) pxx <- predict(Sb1, xx <- seq(-1.2, 1.2, len = 201), interval = "both") plot(x,y, main = deparse(Sb1$call), xlim = range(xx), ylim = range(y, pxx[,"fit"])) lines(pxx, col = 2) rug(Sb1$knots, col = 4, lwd = 1.6)# (too many knots) matlines(pxx[,1], pxx[,-(1:2)], col= rep(c("green","blue"),c(2,2)), lty=2)