CodeGuy - 1 year ago 103
R Question

# Determining the goodness of an R fit using lm()

I learned to get a linear fit with some points using lm in my R script. So, I did that (which worked nice), and printed out the fit:

``````lm(formula = y2 ~ x2)

Residuals:
1          2          3          4
5.000e+00 -1.000e+01  5.000e+00  7.327e-15

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)   70.000     17.958   3.898  0.05996 .
x2            85.000      3.873  21.947  0.00207 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 8.66 on 2 degrees of freedom
Multiple R-squared: 0.9959, Adjusted R-squared: 0.9938
F-statistic: 481.7 on 1 and 2 DF,  p-value: 0.00207
``````

I'm trying to determine the best way to judge how great this fit is. I need to compare this fit with a few others (which are also linear using
`lm()`
function). What value from this summary would be the best way to judge how good this fit is? I was thinking to use the residual standard error. Any suggestions. Also, how do I extract that value from the fit variable?

If you want to access the pieces produced by `summary` directly, you can just call `summary` and store the result in a variable and then inspect the resulting object:

``````rs <- summary(lm1)
names(rs)
``````

Perhaps `rs\$sigma` is what you're looking for?

EDIT

Before someone chides me, I should point out that for some of this information, this is not the recommended way to access it. Rather you should use the designated extractors like `residuals()` or `coef`.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download