2

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

dotwin
  • 123
  • 6
  • 2
    What is $C^1$? Other than that, it sounds like isotonic regression might be a good fit for you needs. – Sycorax Oct 29 '15 at 20:49
  • 3
    **mgcv** can fit general penalised regression models with monotonicity constraints using cubic splines. **mgcv** has function `mono.con` for constraints on a cubic spline, and the models are fitted using the `pcls()` function - the help page of which has an example. – Gavin Simpson Oct 29 '15 at 21:02
  • @user777 $C^1$ denotes the smoothness; maybe it is not internationally used - i studied math in Germany. (cf. https://en.wikipedia.org/wiki/Smoothness) – dotwin Oct 31 '15 at 02:23
  • @both: upvotes + thx a bunch for your suggestions; I will look into it now. – dotwin Oct 31 '15 at 02:24
  • 1
    CV user Rob Hyndman has some functions available: http://robjhyndman.com/software/monotonic-splines/ – mark999 Oct 31 '15 at 03:27
  • @dotwin The wiki link makes it appear that it is common usage and I'm just ignorant. Anyhow, I'm pretty sure isotonic regression doesn't satisfy the $C^1$ requirement! Interesting question, though! – Sycorax Oct 31 '15 at 15:42
  • R packages ConSpline, cobs, scar, scam and cgam can all fit shape-constrained splines, including monotonically increasing ones - I would try some of these! The cobs package also allows you to specify the desired degree of the splines; 1 for linear spline (equivalent to L_1-roughness) and 2 for quadratic spline (corresponding to L_infinity ('L_oo') roughness). Is this what you are after? – Tom Wenseleers Sep 19 '17 at 00:26

1 Answers1

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
  • 2,413
  • 1
  • 21
  • 39