# how to calculate odd ratios with R? Classic List Threaded 5 messages Open this post in threaded view
|

## how to calculate odd ratios with R?

 Hello, Is it possible to calculate with a single function the odd ratios? Now I can use this implement: ``` or <- (De/He)/(Dn/Hn) # Disease exposed, Healthy non-exposed logo <- log(or) x <- sqrt(((1/De) + (1/He) + (1/Dn) + (1/Hn))) lower_ci = exp(logo - 1.96*x) upper_ci = exp(logo + 1.96*x) cat("OR:", round(or, 3), "(", round(lower_ci, 3), "-", round(upper_ci, 3), ")",     spe = "") ``` for instance, ``` De <-6 Dn <-3 He <-4 Hn <-5 or <- (De/He)/(Dn/Hn) logo <- log(or) x <- sqrt(((1/De) + (1/He) + (1/Dn) + (1/Hn))) lower_ci = exp(logo - 1.96*x) upper_ci = exp(logo + 1.96*x) cat("OR:", round(or, 3), "(", round(lower_ci, 3), "-", round(upper_ci, 3), ")",     spe = "") > OR: 2.5 ( 0.37 - 16.889 ) ``` Is there a simple function from some package that can also add a p-value to this test? Or how can I calculate the p-value on my own? -- Best regards, Luigi ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: how to calculate odd ratios with R?

 Luigi, Odds ratios can be produced using a logistic regression, which can be performed using the glm function. The following has a detailed description of how logistic regression can be performed using R: https://stats.idre.ucla.edu/r/dae/logit-regression/John John David Sorkin M.D., Ph.D. Professor of Medicine Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) ________________________________ From: R-help <[hidden email]> on behalf of Luigi Marongiu <[hidden email]> Sent: Monday, July 6, 2020 9:01 AM To: r-help <[hidden email]> Subject: [R] how to calculate odd ratios with R? Hello, Is it possible to calculate with a single function the odd ratios? Now I can use this implement: ``` or <- (De/He)/(Dn/Hn) # Disease exposed, Healthy non-exposed logo <- log(or) x <- sqrt(((1/De) + (1/He) + (1/Dn) + (1/Hn))) lower_ci = exp(logo - 1.96*x) upper_ci = exp(logo + 1.96*x) cat("OR:", round(or, 3), "(", round(lower_ci, 3), "-", round(upper_ci, 3), ")",     spe = "") ``` for instance, ``` De <-6 Dn <-3 He <-4 Hn <-5 or <- (De/He)/(Dn/Hn) logo <- log(or) x <- sqrt(((1/De) + (1/He) + (1/Dn) + (1/Hn))) lower_ci = exp(logo - 1.96*x) upper_ci = exp(logo + 1.96*x) cat("OR:", round(or, 3), "(", round(lower_ci, 3), "-", round(upper_ci, 3), ")",     spe = "") > OR: 2.5 ( 0.37 - 16.889 ) ``` Is there a simple function from some package that can also add a p-value to this test? Or how can I calculate the p-value on my own? -- Best regards, Luigi ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=02%7C01%7C%7C2cd90411f0e34701d7f308d821acceb7%7C717009a620de461a88940312a395cac9%7C0%7C0%7C637296373389265031&sdata=GVQUX4DafNEu29kEupPbDrNblkQyas3LquN%2FVahCFPw%3D&reserved=0PLEASE do read the posting guide https://nam03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=02%7C01%7C%7C2cd90411f0e34701d7f308d821acceb7%7C717009a620de461a88940312a395cac9%7C0%7C0%7C637296373389265031&sdata=9hLF%2F0BrW3Tn%2BleeHoXaoRXY0NNxeXVQZAJQEvLBn7E%3D&reserved=0and provide commented, minimal, self-contained, reproducible code.         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: how to calculate odd ratios with R?

 In reply to this post by Luigi Dear Luigi You could try the epitools package which gives a large number of ways of doing this. I would have thought that using Wald intervals for the log odds ration was not optimal with small frequencies. Michael On 06/07/2020 14:01, Luigi Marongiu wrote: > Hello, > Is it possible to calculate with a single function the odd ratios? > Now I can use this implement: > ``` > or <- (De/He)/(Dn/Hn) # Disease exposed, Healthy non-exposed > logo <- log(or) > x <- sqrt(((1/De) + (1/He) + (1/Dn) + (1/Hn))) > lower_ci = exp(logo - 1.96*x) > upper_ci = exp(logo + 1.96*x) > cat("OR:", round(or, 3), "(", round(lower_ci, 3), "-", round(upper_ci, 3), ")", >      spe = "") > ``` > for instance, > ``` > De <-6 > Dn <-3 > He <-4 > Hn <-5 > or <- (De/He)/(Dn/Hn) > logo <- log(or) > x <- sqrt(((1/De) + (1/He) + (1/Dn) + (1/Hn))) > lower_ci = exp(logo - 1.96*x) > upper_ci = exp(logo + 1.96*x) > cat("OR:", round(or, 3), "(", round(lower_ci, 3), "-", round(upper_ci, 3), ")", >      spe = "") >> OR: 2.5 ( 0.37 - 16.889 ) > ``` > Is there a simple function from some package that can also add a > p-value to this test? Or how can I calculate the p-value on my own? > -- Michael http://www.dewey.myzen.co.uk/home.html______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.