[R] Accessing coefficient values in linear regression

Peter Alspach Peter.Alspach at plantandfood.co.nz
Fri Jul 13 06:12:51 CEST 2012

Tena koe Pragya

It is advisable to use the extractor functions where they are available; i.e., coef(j) and coef(j)[1] or coef(j)['(Intercept)'] for the intercept.

However, j$coefficients["(Intercept)"] does give you what I suspect you want.  Check its structure:
and you'll see it is 191.9161 with a name attribute.  Thus you can use it 'for other purposes'.

HTH ....

Peter Alspach

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of PRAGYA SUR
Sent: Friday, 13 July 2012 3:56 p.m.
To: r-help at r-project.org
Subject: [R] Accessing coefficient values in linear regression

Hi everyone,
                  I am fitting a simple linear regression model in R. My
command is j=lm( Y ~ Sex + begsal + time + int)
lm(formula = Y ~ Sex + begsal + time + int)

(Intercept)          Sex       begsal         time          int
    191.916     -241.805        3.969        5.003        3.040
Now I wish to access the values of these coefficients for other purposes
and all this I need to be done within a code. Using
j$coefficients["(Intercept)"] gives me
How can I get just the value 191.9161?
Please help.


	[[alternative HTML version deleted]]

R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

The contents of this e-mail are confidential and may be subject to legal privilege.
 If you are not the intended recipient you must not use, disseminate, distribute or
 reproduce all or any part of this e-mail or attachments.  If you have received this
 e-mail in error, please notify the sender and delete all material pertaining to this
 e-mail.  Any opinion or views expressed in this e-mail are those of the individual
 sender and may not represent those of The New Zealand Institute for Plant and
 Food Research Limited.

More information about the R-help mailing list