Hi.. I''m relatively new to both nonparametric modeling and R.. I''m trying to fit a regression spline or a piecewise polynomial using R and have teh following qns.: 1. How do I fit a regression spline/piecewise polynomial to the data for some specified degree of the polynomial? 2. How do I obtain the coefficients of the model? I tried the following (based on an example in the help):> data(cars) > attach(cars) > plot(speed, dist, main = "data(cars) & smoothing splines") > cars.spl <- sm.spline(speed, dist) > cars.splCall: smooth.Pspline(x = ux, y = tmp[, 1], w = tmp[, 2], method = method) Smoothing Parameter (Spar): 366.8429 Equivalent Degrees of Freedom (Df): 2.428851 GCV Criterion: 29.54554 CV Criterion: 39.18787> coef(cars.spl)NULL As seen above, it doesn''t give me the coefficients though it seems to have fitted a piecewise linear model.. I just get "NULL".. is there some other function that will do this? Please cc me on the reply as I''m not subscribed to the list yet.. Thanks, nirmal
1) sm.spline is in package Pspline. It does not fit a regression spline: use ns/bs in packages splines with lm() to do that. For what you did do, smooth.spline in package modreg would be preferred. 2) I don''t see why you think the coefficients would be useful. You need to know the knots and the respresentation of the spline too. What do you want to do with them? For almost all purposes you want to call predict() on a regression-spline fit. Coefficients are less useful in linear regression than many people think, too, but they can often be sent up to have a direct interpretation. That is never true of spline coefficients. My advice is that you seek local statistical advice. If you find something hard to do in R it is usually because no one has wanted to do it, and that is usually because it is not seen as helpful. On Fri, 28 Mar 2003, Nirmal Govind wrote:> > Hi.. I''m relatively new to both nonparametric modeling and R.. I''m trying to fit > a regression spline or a piecewise polynomial using R and have teh following > qns.: > > 1. How do I fit a regression spline/piecewise polynomial to the data for some > specified degree of the polynomial? > > 2. How do I obtain the coefficients of the model? >[...] -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Thanks for your reply...> 2) I don''t see why you think the coefficients would be useful. You need > to know the knots and the respresentation of the spline too. What do you > want to do with them? For almost all purposes you want to call predictThe reason I wanted the coefficients is so that I can do the prediction outside of R, say for example in Excel, once the spline has been created. I just googled and found that there''s something called RExcel which can call R from within Excel.. I think this might be what I need then... will give it a try.. Thanks, nirmal