Logistic Regression in R (Odds Ratio)
I'm trying to undertake a logistic regression analysis in
R. I have attended courses covering this material using STATA. I am finding it very difficult to replicate functionality in
R. Is it mature in this area? There seems to be little documentation or guidance available. Producing odds ratio output seems to require installing
epitoolsand/or others, none of which I can get to work, are outdated or lack documentation. I've used
glmto do the logistic regression. Any suggestions would be welcome.
I'd better make this a real question. How do I run a logistic regression and produce odds rations in
Here's what I've done for a univariate analysis:
x = glm(Outcome ~ Age, family=binomial(link="logit"))
And for multivariate:
y = glm(Outcome ~ Age + B + C, family=binomial(link="logit"))
I've then looked at
x$coefficientsof any value?
if you want to interpret the estimated effects as relative odds ratios, just do
exp(coef(x))(gives you $e^\beta$, the multiplicative change in the odds ratio for $y=1$ if the covariate associated with $\beta$ increases by 1). For profile likelihood intervals for this quantity, you can do
require(MASS) exp(cbind(coef(x), confint(x)))
EDIT: @caracal was quicker...
+1 for @fabian's suggestion. An inferior way to do this that usually yields similar intervals is to compute the interval on the logit scale and then transform to the odds scale: `cbind( exp(coef(x)), exp(summary(x)$coefficients[,1] - 1.96*summary(x)$coefficients[,2]), exp(summary(x)$coefficients[,1] + 1.96*summary(x)$coefficients[,2]) )`. There's also the delta method: http://www.ats.ucla.edu/stat/r/faq/deltamethod.htm