Hi All, I want to fit a piecewise spline of degree 1, i.e. a spline consisting of a straight line over each piece. I downloaded the R package pspline, then I have following questions: 1. in the program, the degree of the spline is specified by 2*norder-1. Why do they adopt such scheme that we can only fit a spline with odd degree? 2. norder cannot be set to 1. Is there any specific reason for doing so? Maybe I need to code this by myself. So I'd like to hear your advices. Thanks in advance, Gang _________________________________________________________________ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi, What you need is just the bs() or ns() functions in the library splines in the R-software. You have to specify the knots and can specify the degree. For instance: library(splines) bs(1:20, knots=c(5,11), degree=1) #performs three #straight lines with break-point at x=5 and 11 for the variable 1:20 lm(y~bs(1:20, knots=c(5,11), degree=1)) #piecewise linear regression Common "problem" is that the beta parameters for the pseudo-variables inducted by bs() are not interpretable (i.e. in linear case they don't represents the slopes in each piece). best, vito ----- Original Message ----- From: "Gang Liang" <gumpleon at hotmail.com> To: <r-help at hypatia.math.ethz.ch> Sent: Wednesday, December 05, 2001 7:05 AM Subject: [R] Questions about piecewise spline fitting> Hi All, > > I want to fit a piecewise spline of degree 1, i.e. a spline consisting ofa> straight line over each piece. I downloaded the R package pspline, then I > have following questions: > > 1. in the program, the degree of the spline is specified by 2*norder-1.Why> do they adopt such scheme that we can only fit a spline with odd degree? > > 2. norder cannot be set to 1. Is there any specific reason for doing so? > > Maybe I need to code this by myself. So I'd like to hear your advices. > > Thanks in advance, > Gang > > > _________________________________________________________________ > > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-> r-help mailing list -- Readhttp://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html> Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch >_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
If all you want is a linear spline do something like x + pmax(x-a,0) + pmax(x-b,0) in a model, where knots are a and b. Frank Harrell On Tue, 04 Dec 2001 22:05:34 -0800 Gang Liang <gumpleon at hotmail.com> wrote:> Hi All, > > I want to fit a piecewise spline of degree 1, i.e. a spline consisting of a > straight line over each piece. I downloaded the R package pspline, then I > have following questions: > > 1. in the program, the degree of the spline is specified by 2*norder-1. Why > do they adopt such scheme that we can only fit a spline with odd degree? > > 2. norder cannot be set to 1. Is there any specific reason for doing so? > > Maybe I need to code this by myself. So I'd like to hear your advices. > > Thanks in advance, > Gang > > > _________________________________________________________________ > > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-- Frank E Harrell Jr Prof. of Biostatistics & Statistics Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences U. Virginia School of Medicine http://hesweb1.med.virginia.edu/biostat -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Tue, 4 Dec 2001, Gang Liang wrote:> Hi All, > > I want to fit a piecewise spline of degree 1, i.e. a spline consisting of a > straight line over each piece. I downloaded the R package pspline, then I > have following questions: > > 1. in the program, the degree of the spline is specified by 2*norder-1. Why > do they adopt such scheme that we can only fit a spline with odd degree? > > 2. norder cannot be set to 1. Is there any specific reason for doing so? > > Maybe I need to code this by myself. So I'd like to hear your advices. >There is a splines package in the R base distribution. You want to use the bs() function in the splines package. The pspline package fits smoothing splines, which are not what you want. For linear splines it may be easier to code them yourself in any case, as there are at least two different codings where the parameter estimates and tests are of interest in themselves. What bs() gives is yet another coding that is more numerically stable but has less interesting coefficients. -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Another approach to this problem - probably not as good as those already proposed - is to use nls, for example, nls(st1~pmin(A,A+B-C*wc),start=list(A=.5,B=1.5,C=.0020)) This was something I did for a data set with a flat initial segment followed by a rougly linear decline. The dependent measure was st1 and the predictor was wc. It was hard to find the right starting list, though. An advantage of this is that it finds the knot by itself. Jon Baron -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._