Can anyone please tell me how to get the r-squared output from a piecewise (segmented) regression using the strucchange package? Here is the R code I have tried thus far. library(lmtest) library(strucchange) data <- ts(c(rnorm(30), runif(30)), frequency = 12, start = c(2005, 01)) bpts <- breakpoints(data ~ 1) print(bpts) summary(bpts) coeftest(bpts) [[alternative HTML version deleted]]
You can't. You shouldn't. Segmented regression with unknown breakpoints in nonlinear regression, and R-squared doesn't make sense for nonlinear regression. See: https://stat.ethz.ch/pipermail/r-help/2002-July/023461.html -- Bert On Sun, Jan 20, 2013 at 3:05 PM, Geoffrey Smith <gps at asu.edu> wrote:> Can anyone please tell me how to get the r-squared output from a piecewise > (segmented) regression using the strucchange package? Here is the R code I > have tried thus far. > > library(lmtest) > library(strucchange) > > data <- ts(c(rnorm(30), runif(30)), frequency = 12, start = c(2005, 01)) > > bpts <- breakpoints(data ~ 1) > > print(bpts) > > summary(bpts) > > coeftest(bpts) > > [[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 Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
On Jan 20, 2013, at 3:05 PM, Geoffrey Smith wrote:> Can anyone please tell me how to get the r-squared output from a > piecewise > (segmented) regression using the strucchange package? Here is the R > code I > have tried thus far. > > library(lmtest) > library(strucchange) > > data <- ts(c(rnorm(30), runif(30)), frequency = 12, start = c(2005, > 01)) > > bpts <- breakpoints(data ~ 1) > > print(bpts) > > summary(bpts) > > coeftest(bpts)The authors of that package do provide some summary statistics that might be of interest. You can get the residual sums of squares: summary(bpts)$RSS You should also look at ?logLik.breakpoints As Bert points out this is not an ordinary linear problem. -- David Winsemius, MD Alameda, CA, USA
On Sun, 20 Jan 2013, Geoffrey Smith wrote:> Can anyone please tell me how to get the r-squared output from a > piecewise (segmented) regression using the strucchange package? Here is > the R code I have tried thus far. > > library(lmtest) > library(strucchange) > > data <- ts(c(rnorm(30), runif(30)), frequency = 12, start = c(2005, 01)) > > bpts <- breakpoints(data ~ 1)You can rather easily compute the R-squared by hand: var(fitted(bpts))/var(data) Alternatively, you can fit a segmented linear regression with lm() by using the factor coding the segments and then extract the R-squared as usual: m <- lm(data ~ breakfactor(bpts)) summary(m)$r.squared Finally, the R-squared is just a simple transformation of the residual sum of squares. Hence, you can also compute it via 1 - summary(bpts)$RSS[1,-1] / summary(bpts)$RSS[1,1] Personally, I prefer to either look at RSS directly or at penalized measures such as BIC/AIC, which is why RSS/BIC are included in summaries and plots and R-squared is not. Best, Z> print(bpts) > > summary(bpts) > > coeftest(bpts) > > [[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. >