You are right that R's output usually contains only essential information, and more needs to be calculated separately.
N <- 100 # generate some data
X1 <- rnorm(N, 175, 7)
X2 <- rnorm(N, 30, 8)
X3 <- abs(rnorm(N, 60, 30))
Y <- 0.5*X1 - 0.3*X2 - 0.4*X3 + 10 + rnorm(N, 0, 12)
# dichotomize Y and do logistic regression
Yfac <- cut(Y, breaks=c(-Inf, median(Y), Inf), labels=c("lo", "hi"))
glmFit <- glm(Yfac ~ X1 + X2 + X3, family=binomial(link="logit"))
coefficients()
gives you the estimated regression parameters $b_{j}$. It's easier to interpret $exp(b_{j})$ though (except for the intercept).
> exp(coefficients(glmFit))
(Intercept) X1 X2 X3
5.811655e-06 1.098665e+00 9.511785e-01 9.528930e-01
To get the odds ratio, we need the classification cross-table of the original dichotomous DV and the predicted classification according to some probability threshold that needs to be chosen first. You can also see function ClassLog()
in package QuantPsyc
(as chl mentioned in a related question).
# predicted probabilities or: predict(glmFit, type="response")
> Yhat <- fitted(glmFit)
> thresh <- 0.5 # threshold for dichotomizing according to predicted probability
> YhatFac <- cut(Yhat, breaks=c(-Inf, thresh, Inf), labels=c("lo", "hi"))
> cTab <- table(Yfac, YhatFac) # contingency table
> addmargins(cTab) # marginal sums
YhatFac
Yfac lo hi Sum
lo 41 9 50
hi 14 36 50
Sum 55 45 100
> sum(diag(cTab)) / sum(cTab) # percentage correct for training data
[1] 0.77
For the odds ratio, you can either use package vcd
or do the calculation manually.
> library(vcd) # for oddsratio()
> (OR <- oddsratio(cTab, log=FALSE)) # odds ratio
[1] 11.71429
> (cTab[1, 1] / cTab[1, 2]) / (cTab[2, 1] / cTab[2, 2])
[1] 11.71429
> summary(glmFit) # test for regression parameters ...
# test for the full model against the 0-model
> glm0 <- glm(Yfac ~ 1, family=binomial(link="logit"))
> anova(glm0, glmFit, test="Chisq")
Analysis of Deviance Table
Model 1: Yfac ~ 1
Model 2: Yfac ~ X1 + X2 + X3
Resid. Df Resid. Dev Df Deviance P(>|Chi|)
1 99 138.63
2 96 110.58 3 28.045 3.554e-06 ***