Description Usage Arguments Details Value Author(s) References Examples
View source: R/monotone-spline.R
Monotone spline fitting
1 |
x |
predictors |
y |
values |
k |
max number of knots (default 10) |
lower |
optional lower bound |
upper |
optional upper bound |
Monotone spline fitting function using MGCV. Also has a predict method based on mgcv::Predict.matrix. However, it doesn't really play according to the rules of the generic.
list of class mspline
containing the fitted elements.
Also returns x
and y
.
will townes and gzt
See https://gist.github.com/willtownes/f598e5c2344043675566603d29b6c2d6
1 2 3 4 5 6 7 8 9 10 11 12 | # Generate data from a monotonic truth.
x <- runif(100) * 4 - 1
x <- sort(x)
f <- exp(4 * x) / (1 + exp(4 * x))
y <- f + rnorm(100) * 0.1
plot(x, y)
fv <- mspline(x, y, 5)
lines(x, predict(fv, x), col = "red")
fv <- mspline(x, y, 10)
lines(x, predict(fv, x), col = "blue")
legend("bottomright", lty = 1, paste0("k=", c(5, 10)),
col = c("red", "blue"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.