ifreak
ifreak

Reputation: 1756

get the error value from linear regression function lm

i have a linear regression problem which i solved using:

m=lm(value ~ mean, data=d)

and from this value i can get the R2 and the regression equation.

but i want to get the standard error(fitting error). i was able to see the value but i don't know how to get it in order to store it inside a data frame.

i get the value using summary(m) and the result is something like this:

Call:
lm(formula = value ~ mean, data = d)

Residuals:
    Min      1Q  Median      3Q     Max 
-25.000 -15.909  -2.124  14.596  44.697 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept)  2.500e+01  1.064e+00   23.49   <2e-16 ***
mean        -1.759e-06  1.536e+00    0.00        1    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 16.85 on 1298 degrees of freedom
Multiple R-squared: 1.01e-15,   Adjusted R-squared: -0.0007704 
F-statistic: 1.311e-12 on 1 and 1298 DF,  p-value: 1 

so the question is: how can i get access to these values??

thank you

Upvotes: 3

Views: 7722

Answers (3)

federico sgoifo
federico sgoifo

Reputation: 66

Extract Residual Standard Deviation 'Sigma'

sigma(m)

Upvotes: 0

Richie Cotton
Richie Cotton

Reputation: 121177

Access residuals using resid(m).

EDIT: From the comments, it seems that you want sum(resid(m) ^ 2).

Upvotes: 3

csgillespie
csgillespie

Reputation: 60522

The function summary just returns an R list.

##Generate some dummy data
x = runif(10);y = runif(10)
m = summary(lm(y ~ x))

We can use the usual list syntax to extract what we want. For example,

m[[4]]

Returns a data frame of model fits

R> m[[4]]
            Estimate Std. Error t value Pr(>|t|)
(Intercept)  0.44265     0.2443  1.8123   0.1075
x            0.07066     0.4460  0.1584   0.8781

and m[[6]] returns the Residual standard error

R> m[[6]]
[1] 0.2928

There are a few convenience functions around, such as coefficients(m)

Upvotes: 9

Related Questions