# Obtaining values of estimates from a regression; How do I get values from a list?

6 messages
Open this post in threaded view
|

## Obtaining values of estimates from a regression; How do I get values from a list?

 I am trying to obtain the coefficients from a regression (performed using lm).  I would like to get the value for the slope (i.e. estimate) for pre from the following regression: fitchange <- lm(post-pre~pre,data=mydata2) I have tried the following without any success: zz <- summary(fitchange)["coefficients"] class(zz) print(zz) zz[[2,1]] zz[2,1] zz["pre","Estimate"] I clearly don't know how to select elements from the list returned by the summary function. A reproducible version of my code follows: mydata2 <-structure(list(pre = c(71.3302299440613, 86.2703384845455, 120.941698468568,                               80.9020778388552, 84.9927752038908, 77.9108032451793, 111.007107108483,                               93.288442414475, 126.097826796255, 111.63734644637),                          post = c(45.9294556667686,                                 114.661937978585, 138.501558726477, 55.355775963925, 97.7906200355594,                                 71.1008233796004, 149.308274695789, 122.828428213951, 143.690814568562,                                 116.607579975539)), class = "data.frame", row.names = c(NA, -10L)) fitchange <- lm(post-pre~pre,data=mydata2) zz <- summary(fitchange)["coefficients"] class(zz) print(zz) zz[[2,1]] zz[2,1] zz["pre","Estimate"] Any help you can offer would be appreciated. John David Sorkin M.D., Ph.D. Professor of Medicine Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing)         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Obtaining values of estimates from a regression; How do I get values from a list?

 You have some choices fitchange\$coefficients[2] zz\$coefficients[2,1] Note that class(zz\$coefficients) shows that it is a matrix. HTH, Eric On Fri, Feb 22, 2019 at 9:45 AM Sorkin, John <[hidden email]> wrote: > I am trying to obtain the coefficients from a regression (performed using > lm).  I would like to get the value for the slope (i.e. estimate) for pre > from the following regression: > > > fitchange <- lm(post-pre~pre,data=mydata2) > > > I have tried the following without any success: > > > zz <- summary(fitchange)["coefficients"] > class(zz) > print(zz) > zz[[2,1]] > zz[2,1] > zz["pre","Estimate"] > > > I clearly don't know how to select elements from the list returned by the > summary function. > > > A reproducible version of my code follows: > > > mydata2 <-structure(list(pre = c(71.3302299440613, 86.2703384845455, > 120.941698468568, >                               80.9020778388552, 84.9927752038908, > 77.9108032451793, 111.007107108483, >                               93.288442414475, 126.097826796255, > 111.63734644637), >                          post = c(45.9294556667686, >                                 114.661937978585, 138.501558726477, > 55.355775963925, 97.7906200355594, >                                 71.1008233796004, 149.308274695789, > 122.828428213951, 143.690814568562, >                                 116.607579975539)), class = "data.frame", > row.names = c(NA, -10L)) > > fitchange <- lm(post-pre~pre,data=mydata2) > zz <- summary(fitchange)["coefficients"] > class(zz) > print(zz) > zz[[2,1]] > zz[2,1] > zz["pre","Estimate"] > > > Any help you can offer would be appreciated. > > > > > > > John David Sorkin M.D., Ph.D. > Professor of Medicine > Chief, Biostatistics and Informatics > University of Maryland School of Medicine Division of Gerontology and > Geriatric Medicine > Baltimore VA Medical Center > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > (Phone) 410-605-7119 > (Fax) 410-605-7913 (Please call phone number above prior to faxing) > > >         [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] mailing list -- To UNSUBSCRIBE and more, see > 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. >         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Obtaining values of estimates from a regression; How do I get values from a list?

Open this post in threaded view
|