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