Tsk, tsk.  You don't seem to be looking very hard.

Here's an example with a glm; lm() works the same way but has fewer internal
objects.

mod3 <- glm(tree ~ altitude, family = binomial)

You can use names() to find out what's inside:

> names(mod3)
 [1] "coefficients"      "residuals"         "fitted.values"     "effects"
"R"                
 [6] "rank"              "qr"                "family"
"linear.predictors" "deviance"         
[11] "aic"               "null.deviance"     "iter"              "weights"
"prior.weights"    
[16] "df.residual"       "df.null"           "y"                 "converged"
"boundary"         
[21] "model"             "call"              "formula"           "terms"
"data"             
[26] "offset"            "control"           "method"            "contrasts"
"xlevels"          

There are lots of ways to retrieve the parameter estimates:

> coefficients(mod3)
(Intercept)    altitude 
13.43360163 -0.01220884
 
> mod3$coeff
(Intercept)    altitude 
13.43360163 -0.01220884
 
> mod3$coef[2]
   altitude 
-0.01220884 

> as.numeric(mod3$coef[2])
[1] -0.01220884
>


Charles Annis, P.E.

[EMAIL PROTECTED]
phone: 561-352-9699
eFax:  614-455-3265
http://www.StatisticalEngineering.com
 

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Pablo Gonzalez
Sent: Thursday, September 15, 2005 4:09 PM
To: [email protected]
Subject: [R] Coefficients from LM

Hi everyone,

Can anyone tell me if its possibility to extract the coefficients from the
lm() command?
For instance, imagine that we have the following data set (the number of
observations for each company is actually larger than the one showed...):

Company Y       X1      X2
1               y_1     x1_1    x2_1
1               y_2     x1_2    x2_2
1               y_3     x1_3    x2_3
(...)
2               y_4     x1_4    x2_4
2               y_5     x1_5    x2_5    
2               y_6     x1_6    x2_6
(...)
n               y_n     x1_n    x2_n
n               y_n1    x1_n1   x2_n1
n               y_n2    x1_n2   x2_n2
(...)

I need to run a regression of Y=b0+b1*X1+b2*X2 for EACH company in the
dataset and then retrieve the coefficients for each regression obtained (and
t-stats and R^2) for each company and put it in another dataset/table. The
procedure can be done easily done with a loop statement, but i need to
retrieve each individual coefficient, t-stat, R^2, etc... I know that, using
the $coefficients command will return the vector of coeffcients but I'm
having trouble to assignt it to the correct row in the final dataset.
Furthermore, I can't find any way of retrieving the R^2 and t-stats...

Thanks for any help,

Pablo.

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to