1
$\begingroup$

I know its possible to extract r-squared values to quantify the 'goodness-of-fit' of regressions in R, with something to the effect of:

fit <- lm(y ~ x1 + x2 + x3, data=mydata)  # Not actual data
r-sq <- summary(fit)$r.squared # or $adj.r.squared

I've recently been using the cumSeg package for step-function regressions, but it doesn't appear to offer this functionality, though it does provide residuals as a vector.

Is there some way to extract an r-squared (or adj. r squared) that I don't know about? Or can it be calculated 'de novo' with something that cumSeg does actually provide?

EDIT This is the output of summary() for my stepfunction created via cumSeg. Perhaps someone more mathematically versed with stepfunctions knows if the nomenclature for an r-squared (or whatever the equivalent is) is just different and the data I'm looking for is actually there (or if it is even a legitimate question to ask for an R-squared for stepfunctions?! I'm assuming it should be calculable from any fitted model really.

> summary(stepfunc)
              Length Class  Mode   
coefficients   3     -none- numeric
residuals     16     -none- numeric
effects       16     -none- numeric
rank           1     -none- numeric
fitted.values 16     -none- numeric
assign         0     -none- NULL   
qr             5     qr     list   
df.residual    1     -none- numeric
epsilon        1     -none- numeric
it             1     -none- numeric
psi            1     -none- numeric
beta.c         1     -none- numeric
gamma.c        1     -none- numeric 
V             16     -none- numeric
y             16     -none- numeric
id.group      16     -none- numeric
est.means      2     -none- numeric
n.psi          1     -none- numeric
$\endgroup$
1
$\begingroup$

You can extract what you need directly from your result with squared brackets []. Here an example:

set.seed(your seed)    

dt <- data.frame(fc = rep(sample(0:100, 100, replace = TRUE), 
100), v1 =     rep(rnorm(100, 0, 1), 100), v2 = rep(rnorm(100, 0, 2), 100))

fit <- lm(fc ~ v1 + v2, data = dt)  # Not actual data

summary(fit)[9]

$adj.r.squared
[1] 0.01484017

Otherwise, you can look for the $ operator in this way:

summary(fit$effects)

It will show you a list of possible parameters you could be interested in.

$\endgroup$
  • $\begingroup$ Yes that's what I would ordinarily have done with packages like lm, but the fit that cumSeg creates doesn't seem to offer that. I've edited by answer to show what the output of summary() of my stepfunction gives. $\endgroup$ – Joe Healey Apr 26 '16 at 11:20
  • $\begingroup$ Brackets is the way R itself indexes, with double brackets in the case of lists, for example. Try to execute class on your output, and to find the correct indexing procedure. I could try, but, in order to to that, I need at least a sample of the code that produced your summary. Posted here, the output does not provide many useful information. $\endgroup$ – Worice Apr 26 '16 at 11:43
  • $\begingroup$ The exact data/code I'm using is given in a related question I asked here: stackoverflow.com/questions/36728663/…. stepfunc is my fit to the GC data in that code. $\endgroup$ – Joe Healey Apr 26 '16 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.