Hello everybody!!!! Quick question, if you'd like to throw a little tip: does anyone knows a function that runs piecewise regression models with coefficients estimation and inferences ? Thank you [[alternative HTML version deleted]]
Searching the archives would surely be a better way to assemble a list of candidate packages but the "segmented" package is surely in the list. On Jan 14, 2011, at 9:42 AM, Federico Bonofiglio wrote:> Hello everybody!!!! > > Quick question, if you'd like to throw a little tip: > does anyone knows a function that runs piecewise regression models > with > coefficients estimation and inferences ? > > Thank you > > [[alternative HTML version deleted]]David Winsemius, MD West Hartford, CT
Hello: I just found 58 help pages in 32 contributed packages containing the terms "piecewise" and "regression", as follows: library(sos) pr <- ???'piecewise regression' # for "piecewise" with "regression" summary(pr) # 58 matches in 32 packages pr # view the 58 links sorted by package in a web browser p.r <- ???"{piecewise regression}" # for "piecewise" followed immediate by "regression" summary(p.r) # 15 matches in 13 packages p.4 # to view in a web browser Beyond this, the "structchange" package supports looking for changes that would be, e.g., linear in one segment then jump to a different linear regime. If you want the lines to connect, then you may want splines. Probably the most common spline is cubic, but you can also get linear splines. One of the most general spline packages is "fda" (functional data analysis), with multiple companion books by James Ramsay and others. However, there are other spline packages. If this does not answer your question, "PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code", as it says in the signature block for each email on this list. Hope this helps. Spencer Graves On 1/14/2011 6:42 AM, Federico Bonofiglio wrote:> Hello everybody!!!! > > Quick question, if you'd like to throw a little tip: > does anyone knows a function that runs piecewise regression models with > coefficients estimation and inferences ? > > Thank you > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
I wish I had a better answer. There are two things that I know of that use a direct approach: The segmentation package seems to work well if you are doing a few fits, but I had problems when I tried running it on loads of data. It's a bit tricky to parametrize. When I tried investigating the internals I found that the variables are are in Italian, which makes it difficult (and comical) to follow. However, the theory is very attractive. There are also some examples in the archives where people have used the nls solver. But, as I remember, it didn't do a great job at estimating breakpoints (maybe it didn't do it at all). If you don't know about markmail, that has a nice interface for searching the help archives, and you can easily find the example I'm referencing: http://r-project.markmail.org/ A second approach (in my mind) is to use a two step approach of smoothing, then segmenting the smooth: The other thing that I have found very useful is using approx in conjunction with a smoother, like a spline or GAM. You can get a smooth estimate, and then do something like have a piecewise line at every 10th percentile of your smoothed line. I've experimented with is using a classification and regression tree (rpart package) to classify the slope of a smooth line, and then use the regions of slopes to reconstitute a line. One of the challenges with this approach is deciding when to stop segmenting, and picking an appropriate CP value. I keep thinking that there must be some sort of annealing optimization approach that would work the best, but I have not had the time to figure out how to specify it. Gene On Fri, Jan 14, 2011 at 8:42 AM, Federico Bonofiglio <bonoricus@gmail.com>wrote:> Hello everybody!!!! > > Quick question, if you'd like to throw a little tip: > does anyone knows a function that runs piecewise regression models with > coefficients estimation and inferences ? > > Thank you > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
You failed to specify 2 crucial issues: Are the join points known (linear rgression, splines) or unknown (nonlinear regression)? And as several have already indicated, what are the smoothness constraints? -- Bert On Fri, Jan 14, 2011 at 6:42 AM, Federico Bonofiglio <bonoricus at gmail.com> wrote:> Hello everybody!!!! > > Quick question, if you'd like to throw a little tip: > ?does anyone knows a function that runs piecewise regression models with > coefficients estimation and inferences ? > > Thank you > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Bert Gunter Genentech Nonclinical Biostatistics
Reasonably Related Threads
- strange PREDICTIONS from a PIECEWISE LINEAR (mixed) MODEL
- PREDICTIONS from a PIECEWISE LINEAR (mixed) MODEL: THEY AIN'T LINEAR BETWEEN BREAK POINTS!!
- intervals {nlme} lower CI greater than upper CI !!!????
- Questions about piecewise spline fitting
- anomalies with the loess() function