Szymon Marszalek
2010-Apr-19 07:55 UTC
[R] Natural cubic splines produced by smooth.Pspline and predict function in the package "pspline"
Hello, I am using R and the smooth.Pspline function in the pspline package to smooth some data by using natural cubic splines. After fitting a sufficiently smooth spline using the following call: (ps=smooth.Pspline(x,y,norder=2,spar=0.8,method=1) [the values of x are age in years from 1 to 100] I tried to check that R in fact had fitted a natural cubic spline by checking that the resulting spline was LINEAR outside the knots. I did this by plotting the predicted values from the spline fitting in the following way: plot(predict(ps,c(seq(100,150,1)) Unfortunately, the trend beyond the region of knots (i.e. over x values of 100) was far from linear - it was some sort of exponentially increasing trend. My understanding of natural cubic splines (from Green and Silverman - Nonparametric regression and generalized linear models, 1994) is that a natural cubic spline is a series of cubic polynomials joined at a set of knots in such a way that first and second derivatives are equal at all knots. Furthermore, a natural cubic spline has a knot at every data point, and is LINEAR on the range outside of its knots. This leads me to the question of what smooth.Pspline actually performs to the data and whether it actually fits a natural cubic spline as stated in the help file? Or does smooth.Pspline work as I expect it, but I am using predict incorrectly? I thank you for your time. Szymon [[alternative HTML version deleted]]