# [R] how to calculate odd ratios with R?

Sorkin, John j@ork|n @end|ng |rom @om@um@ry|@nd@edu
Mon Jul 6 15:17:57 CEST 2020

```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 <r-help-bounces using r-project.org> on behalf of Luigi Marongiu <marongiu.luigi using gmail.com>
Sent: Monday, July 6, 2020 9:01 AM
To: r-help <r-help using r-project.org>
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

______________________________________________
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see