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:100testy <- abs(rnorm(length(testx)))^3testy <- cumsum(testy)plot(testx,testy)sspl <- smooth.spline(testx,testy)lines(sspl,col="blue")which is not necessarily increasing everywhere. Any suggestions? 解决方案 This doesn't use smooth.spline() but the splinefun(..., method="hyman") will fit a monotonically increasing spline and is also easy to use. So for example:testx <- 1:100testy <- abs(rnorm(length(testx)))^3testy <- cumsum(testy)plot(testx,testy)sspl <- smooth.spline(testx,testy)lines(sspl,col="blue")tmp <- splinefun(x=testx, y=cumsum(testy), method="hyman")lines(testx[-1], diff(tmp(testx)), col="red")Yields the following figure (red are the values from the monotonically increasing spline)From the help file of splinefun: "Method "hyman" computes a monotone cubic spline using Hyman filtering of an method = "fmm" fit for strictly monotonic inputs. (Added in R 2.15.2.)" 这篇关于如何使用smooth.spline()函数使单调(增加)的平滑样条曲线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-18 22:00