[R] A quick question about lm()
(Ted Harding)
Ted.Harding at manchester.ac.uk
Mon Jul 7 16:34:12 CEST 2008
PS: I forgot to mention that, since the summary() of an lm() object
is created by the function summary.lm(), you can find out the detail
by looking under "Value:" at
?summary.lm
Ted.
On 07-Jul-08 14:28:23, Ted Harding wrote:
> On 07-Jul-08 13:38:12, rlearner309 wrote:
>>
>> I have a simple regression using lm().
>> If I just want to check the coefficient, I can use summary(lm())$coef;
>> if I need the standard error, I can use summary(lm())$s, if I need
>> the residuals, I can use summary(lm())$res. OK. How can I get the
>> R-squares and Adjusted R-squares using $...?
>> Is there a function, like objects(), that can show all the references
>> for values?
>>
>> Thanks a lot!
>
> A useful function is str(), which displays the components of an object.
> Example:
>
>> X<-rnorm(10);Y<-rnorm(10)
>> LM<-lm(Y~X)
>> sumLM<-summary(LM)
>> str(sumLM)
> List of 11
> $ call : language lm(formula = Y ~ X)
> $ terms :Classes 'terms', 'formula' length 3 Y ~ X
> .. ..- attr(*, "variables")= language list(Y, X)
> .. ..- attr(*, "factors")= int [1:2, 1] 0 1
> .. .. ..- attr(*, "dimnames")=List of 2
> .. .. .. ..$ : chr [1:2] "Y" "X"
> .. .. .. ..$ : chr "X"
> .. ..- attr(*, "term.labels")= chr "X"
> .. ..- attr(*, "order")= int 1
> .. ..- attr(*, "intercept")= int 1
> .. ..- attr(*, "response")= int 1
> .. ..- attr(*, ".Environment")=<R_GlobalEnv>
> .. ..- attr(*, "predvars")= language list(Y, X)
> .. ..- attr(*, "dataClasses")= Named chr [1:2] "numeric" "numeric"
> .. .. ..- attr(*, "names")= chr [1:2] "Y" "X"
> $ residuals : Named num [1:10] 0.086 -0.345 -1.542 -0.168 -0.894
> ...
> ..- attr(*, "names")= chr [1:10] "1" "2" "3" "4" ...
> $ coefficients : num [1:2, 1:4] 0.270 -0.289 0.387 0.321 0.699 ...
> ..- attr(*, "dimnames")=List of 2
> .. ..$ : chr [1:2] "(Intercept)" "X"
> .. ..$ : chr [1:4] "Estimate" "Std. Error" "t value" "Pr(>|t|)"
> $ aliased : Named logi [1:2] FALSE FALSE
> ..- attr(*, "names")= chr [1:2] "(Intercept)" "X"
> $ sigma : num 1.06
> $ df : int [1:3] 2 8 2
> $ r.squared : num 0.0921
> $ adj.r.squared: num -0.0213
> $ fstatistic : Named num [1:3] 0.812 1.000 8.000
> ..- attr(*, "names")= chr [1:3] "value" "numdf" "dendf"
> $ cov.unscaled : num [1:2, 1:2] 0.1322 -0.0541 -0.0541 0.0912
> ..- attr(*, "dimnames")=List of 2
> .. ..$ : chr [1:2] "(Intercept)" "X"
> .. ..$ : chr [1:2] "(Intercept)" "X"
> - attr(*, "class")= chr "summary.lm"
>
>
>>From which you can see that the R-squared and Adjusted R-squared
> are available as summary(LM)$r.squared and summary(LM)$adj.r.squared
>
> Hoping this helps,
> Ted.
>
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 07-Jul-08 Time: 15:28:19
> ------------------------------ XFMail ------------------------------
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 07-Jul-08 Time: 15:34:09
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list