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