makespline | R Documentation |
Fits a monotonic cubic spline to the data provided, using the penalized constrained least squares method from the mgcv
package.
makespline(x, y, newX=NULL, nKnots = 6, lower_bound = 10^-3)
x |
The predictor variable. |
y |
The response variable. Must be the same length as |
newX |
The points at which to return the value on the fitted spline. If not specified |
nKnots |
The number of knots to use in fitting the spline. |
lower_bound |
The spline cannot drop below this value. |
This uses the pcls
function from the mgcv package to produce the fit. The montonicity constraint is enforced using mono.con
from the same package. The lower_bound
argument is only used on the rare occasions when the fitting function becomes negative or arbitrarily close to zero. If this does occur lower_bound
is added everywhere to ensure that no one length is given essentially infinite weighting.
Returns a vector of values containing the value of the fit at each point newX
.
Matthew D. Young myoung@wehi.edu.au.
Package mgcv. In particular this function is a modification of an example given in the man page for pcls
.
y <- c( rbinom(50,p=0.4,size=1), rbinom(50,p=0.6,size=1) ) x <- 1:100 plot(x,y) p <- makespline(x,y) lines(x,p)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.