I have points in the x-y-plane that are strictly increasing most of the time. The problem is that there are cases with one or two outliers (Knots where an out-of-the-box spline would be decreasing). Without deleting any data points, is there a way to interpolate / create a spline that is strictly increasing everywhere? Also, I would like the interpolation to be $C^1$. (Which package could do this in R?)
Asked
Active
Viewed 1,600 times
2
1 Answers
3
R package cobs allows you to fit shape-constrained splines, including monotonically increasing ones; syntax would be something like:
require(cobs)
fit = cobs(x,y,
constraint= "increase",
lambda=0,
degree=1, # for L1 roughness
knots=seq(min(x),max(x),length.out=10), # desired nr of knots
tau=0.5) # to predict median
preds = predict(fit,interval="none",z=xvals)[,2]
And R packages ConSpline, scar, scam and cgam offer also alternative options to fit shape-constrained splines, including monotonically increasing ones....
Tom Wenseleers
- 3,200
-
Example with R code here: https://stats.stackexchange.com/questions/206073/looking-for-function-to-fit-sigmoid-like-curve/316446#316446 – kjetil b halvorsen Aug 20 '18 at 10:02
mono.confor constraints on a cubic spline, and the models are fitted using thepcls()function - the help page of which has an example. – Gavin Simpson Oct 29 '15 at 21:02