Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extract coefficients from glm in R

Tags:

list

r

I have performed a logistic regression with the following result:

ssi.logit.single.age["coefficients"]
# $coefficients
#  (Intercept)          age 
# -3.425062382  0.009916508 

I need to pick up the coefficient for age, and currently I use the following code:

ssi.logit.single.age["coefficients"][[1]][2]

It works, but I don't like the cryptic code here, can I use the name of the coefficient (i.e. (Intercept) or age)

like image 360
lokheart Avatar asked Jan 24 '11 08:01

lokheart


People also ask

What does coef () do in R?

coef is a generic function which extracts model coefficients from objects returned by modeling functions.

What is a coefficient GLM?

The βs in this equation are called standardized coefficients. They are the GLM coefficients from a model in which all variables have been standardized to have a mean of 0 and a standard deviation of 1.0. Standardized βs may be used to compare the relative predictive effects of the independent variables.


2 Answers

There is an extraction function called coef to get coefficients from models:

coef(ssi.logit.single.age)["age"]
like image 78
James Avatar answered Sep 21 '22 06:09

James


I've found it, from here

Look at the data structure produced by summary()

> names(summary(lm.D9))
  [1] "call"          "terms"         "residuals"     "coefficients"
  [5] "aliased"       "sigma"         "df"            "r.squared"
  [9] "adj.r.squared" "fstatistic"    "cov.unscaled"

Now look at the data structure for the coefficients in the summary:

> summary(lm.D9)$coefficients
             Estimate Std. Error   t value     Pr(>|t|)
(Intercept)    5.032  0.2202177 22.850117 9.547128e-15
groupTrt      -0.371  0.3114349 -1.191260 2.490232e-01

> class(summary(lm.D9)$coefficients)
[1] "matrix"

> summary(lm.D9)$coefficients[,3]
(Intercept)    groupTrt
   22.850117   -1.191260
like image 45
lokheart Avatar answered Sep 21 '22 06:09

lokheart