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

  • 2
    $\begingroup$ What is $C^1$? Other than that, it sounds like isotonic regression might be a good fit for you needs. $\endgroup$ – Sycorax Oct 29 '15 at 20:49
  • 3
    $\begingroup$ 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. $\endgroup$ – Gavin Simpson Oct 29 '15 at 21:02
  • $\begingroup$ @user777 $C^1$ denotes the smoothness; maybe it is not internationally used - i studied math in Germany. (cf. en.wikipedia.org/wiki/Smoothness) $\endgroup$ – dotwin Oct 31 '15 at 2:23
  • $\begingroup$ @both: upvotes + thx a bunch for your suggestions; I will look into it now. $\endgroup$ – dotwin Oct 31 '15 at 2:24
  • 1
    $\begingroup$ CV user Rob Hyndman has some functions available: robjhyndman.com/software/monotonic-splines $\endgroup$ – mark999 Oct 31 '15 at 3:27

R package cobs allows you to fit shape-constrained splines, including monotonically increasing ones; syntax would be something like:

fit = cobs(x,y,
      constraint= "increase", 
       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....


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.