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
cobsOld(x,y,constraint="increase",pointwise=con)->cobs.o
plot(x,y)
lines(cobs.o$z, cobs.o$fit, col = 2, lwd = 1.5)
lines(spline(x,f.true), col = "gray40")
lines(cobs.o$z, cobs.o$cb.lo,lty=2, col = 3)
lines(cobs.o$z, cobs.o$cb.up,lty=2, col = 3)
## compute the median smoothing B-spline using automatically chosen lambda
cobsOld(x,y,constraint="increase",pointwise=con,lambda=-1)->cobs.oo
plot(x,y, main = "COBS Median smoothing spline, automatical lambda")
lines(spline(x,f.true), col = "gray40")
lines(cobs.oo$z, cobs.oo$fit)
lines(cobs.oo$z, cobs.oo$cb.lo,lty=2)
lines(cobs.oo$z, cobs.oo$cb.up,lty=2)
plot(cobs.oo$pp.lambda[-1], cobs.oo$sic[-1], log = "x",
main = "SIC ~ lambda", xlab = expression(lambda), ylab = "SIC")
axis(1, at = cobs.oo$lambda, label = expression(hat(lambda)),
col.axis = 2, mgp = c(3, 0.5, 0))
Run the code above in your browser using DataLab