R code for Constrained Penalized Spline Estimation

CONSTRAINED PENALIZED SPLINES


The penalized spline is a popular method for smooth function estimation. Here penalized spline estimates are given where the function also has a shape such as monotonicity or convexity imposed. The necessary subroutines for cone projection and B-spline basis function generation are included.

If monotonicity is imposed, the quadratic B-spline basis functions are used. If the constraints include convexity (or concavity), the cubic B-spline basis functions are used.

The following code has arguments type (monotone, convex, etc.), x, y, k=#knots, q=degree of penalty, and penalty parameter.

It returns the constrained and unconstrained fit, GCV values, effective degrees of freedom, and the estimated function values on a fine grid.

MUST HAVE coneproj package installed -- uses the coneB function

R code for constrained penalized splines

Here is an example implementation, fitting a monotone convex curve to a dataset generated from an exponential function.

x=runif(50)

y=exp(2*x)+rnorm(50)

ans=penspl(5,x,y,10,3,2.5)

plot(x,y)

lines(ans$xpl,ans$cpl)

lines(ans$xpl,ans$ucpl,col=2)


meyer@stat.colostate.edu