Re: [R] A quick question about lm()

From: Ted Harding <Ted.Harding_at_manchester.ac.uk>
Date: Mon, 07 Jul 2008 15:28:23 +0100 (BST)


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"

>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 ------------------------------

______________________________________________
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. Received on Mon 07 Jul 2008 - 14:43:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 07 Jul 2008 - 15:31:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive