mspline: mspline

Description Usage Arguments Details Value Author(s) References Examples

View source: R/monotone-spline.R

Description

Monotone spline fitting

Usage

1
mspline(x, y, k = 10, lower = NA, upper = NA)

Arguments

x

predictors

y

values

k

max number of knots (default 10)

lower

optional lower bound

upper

optional upper bound

Details

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.

Value

list of class mspline containing the fitted elements. Also returns x and y.

Author(s)

will townes and gzt

References

See https://gist.github.com/willtownes/f598e5c2344043675566603d29b6c2d6

Examples

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

gzt/monogamy documentation built on April 24, 2020, 9:45 p.m.