r - Extracting coefficients from a regression 1 model with 1 predictor -


i have following regression model:

> print(summary(step1))  call: lm(formula = model1, data = newdat1)  residuals:      min       1q   median       3q      max  -2.53654 -0.02423 -0.02423 -0.02423  1.71962   coefficients:             estimate std. error t value pr(>|t|)     (intercept)   0.3962     0.0532   7.446 2.76e-12 *** i2            0.6281     0.0339  18.528  < 2e-16 *** 

i following returned data frame:

            estimate std. error t value pr(>|t|) i2            0.6281     0.0339  18.528  < 2e-16 

i have following code:

> results1<-as.data.frame(summary(step1)$coefficients[-1,drop=false]) 

which yields:

> results1   summary(step1)$coefficients[-1, drop = false] 1                                  6.280769e-01 2                                  5.320108e-02 3                                  3.389873e-02 4                                  7.446350e+00 5                                  1.852804e+01 6                                  2.764836e-12 7                                  2.339089e-45 

thus not want; however, work when there's more 1 predictor.

it nice if gave reproducible example. think you're looking for

cc <- coef(summary(step1))[2,,drop=false] as.data.frame(cc) 

using accessors such coef(summary(.)) rather summary(.)$coefficients both prettier , more robust (there no guarantee internal structure of summary() stay same -- although admittedly it's unlikely basic part of r change time soon, many users have used constructions $coefficients).

indexing row name, i.e.

coef(summary(step1))["i2",,drop=false] 

would better.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -