I have data that are strictly increasing and would like to fit a smoothing spline that is monotonically increasing as well with the smooth.spline()
function if possible, due to the ease of use of this function.
For example, my data can be effectively reproduced with the example:
testx <- 1:100
testy <- abs(rnorm(length(testx)))^3
testy <- cumsum(testy)
plot(testx,testy)
sspl <- smooth.spline(testx,testy)
lines(sspl,col="blue")
which is not necessarily increasing everywhere. Any suggestions?
sspl <- smooth.spline(testx,testy,tol = 3)
(or binning) works for this particular dataset. – Saffronlowess
as an alternate fit method. The granularity can be adjusted with thef
parameter. To generalize, you could wrap it in a method to try parameter options and check againstmin(diff(sspl$y,1))
to ensure monotonic behavior. – Montemontefiascone