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 confidenceintervall, from>a logistic model (glm(.......,family=binomial....). I've written myown, 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]]
The output of logisitic procdure only gives you the log(odds-ratio) and the associated standard error of the log(odds-ratio). You need to exponentiate the log(odds-ratio) to get your odds ratio. The code tells you how to obtain the odds ratio from log(odds-ratio). -- View this message in context: http://r.789695.n4.nabble.com/Odds-ratio-from-Logistic-model-in-R-tp2630277p2651963.html Sent from the R help mailing list archive at Nabble.com.
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/
Hi Guoya, One more option, using Joshua's example, would be: # install.packages('epicalc') require(epicalc) logistic.display(my.glm) HTH, Jorge On Fri, Sep 24, 2010 at 1:50 PM, Li, Guoya <> 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@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. >[[alternative HTML version deleted]]