[R] Odds ratio from Logistic model in R
Joshua Wiley
jwiley.psych at gmail.com
Sat Sep 25 04:45:09 CEST 2010
Hi Guoya,
Is this what you are after?
# fit logistic model
my.glm <- glm(vs ~ mpg, data = mtcars, family = binomial(link = "logit"))
# look at a summary
summary(my.glm)
# view the coefficients as odds ratios
exp(coef(my.glm))
Hope that helps,
Josh
On Fri, Sep 24, 2010 at 10:50 AM, Li, Guoya <Guoya_Li at bshsi.org> wrote:
> Hi, I am new to R. Anyone can explain the following from R-help or
> anyone can direct me how to calculate odds ratio from logistic model in
> R. Thank you very much. Guoya
>
>
>
>
>
> Stefano <stecalza at tiscalinet.it
> <https://stat.ethz.ch/mailman/listinfo/r-help> > writes:
>>Hi all.
>>
>>A simple question.
>>Is there a function to compute the Odds Ratio and its confidence
> intervall, from
>>a logistic model (glm(.......,family=binomial....). I've written my
> own, but
>>certainly someone did a better job.
>
> I show a simple function to do this in my introductory notes available
> from:
>
> http://www.myatt.demon.co.uk
>
> basically it is:
>
> lreg.or <- function(model)
> {
> lreg.coeffs <- coef(summary(salex.lreg))
> lci <- exp(lreg.coeffs[ ,1] - 1.96 * lreg.coeffs[ ,2])
> or <- exp(lreg.coeffs[ ,1])
> uci <- exp(lreg.coeffs[ ,1] + 1.96 * lreg.coeffs[ ,2])
> lreg.or <- cbind(lci, or, uci)
> lreg.or
> }
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/
More information about the R-help
mailing list