I'm trying to use the spline2 package in R to build a monotone spline.
I'm having trouble in evaluating the model for new values of the independent variable. In general, I'm having trouble grasping R treatment of "predict" and its relation to spline2, and how to use the bs object produced.
I tried to follow this example which uses spline1. My data is in a dataframe named BRIyII, with independent variable t and dependent variable P so:
plot(BRIyII$t,BRIyII$P)
So I do:
knots=c(9)
myMat=mSpline(BRIyII$t, knots = knots, degree = 3, intercept = TRUE)
mylm=lm(BRIyII$P~myMat)
Now, if we:
pr = predict(mylm,data.frame(BRIyII$t))
points(BRIyII$t,pr,col = "red")
So my questions are:
1- Since the rightmost predicted value (red dot) is lower than the one to its left, am I misunderstanding the "monotonic" nature of the m splines ?
2- How can I evaluate the spline in values other than those defined in BRIyII$t ? I tried several combinations of stuff but I lack the R syntax knowledge. I would ideally want to do something like :
newdata=seq.int(0,41.5,0.1)