# Math formula to reproduce a plot comparing Relative Risk to Odds Ratios

I'm trying to reproduce Figures 1, 2 and 3 in this paper (notice that clicking on the FIGURES/TABLES tab is enough to see the plots - no need to sign up or create an account), simply to understand how they were calculated - the code is irrelevant - I'm looking for the math formulas used.

QUESTION: What would be the correct formula (or pseudo-code) to reproduce the plots (or at least Fig. 1). Am I not limiting correctly the boundaries of cases among exposed and unexposed? Why am I not getting similar x and y values as on the paper plot?

To reproduce Fig 1: Relationship of the odds ratio to the risk ratio according to 4 levels of outcome risk (cumulative incidence) for unexposed subjects: .01, .10, .25, and .50., I tried:

n <- 100               # No. of subjects in the cohort to be split 50/50 Exposed/Unexposed
A <- seq(1, n/2 - 1,1) # No. of events among Exposed group (eliminating 1 and 50)
B <- n/2 - A           # No. of non-events in the Exposed
RiskUE <- 0.01         # Outcome risk (cumulative incidence) for unexposed subjects
C <- RiskUE * n/2      # No. of events in the Not-Exposed group
D <- n/2 - C           # No. of non-events in the Not-Exposed group
RR <- (A / (A + B)) / (C / (C + D))  # Relative risk
OR <- (A/B) / (C/D)                  # Odds ratio
plot(RR, OR, log ="xy", type = 'l')   # Logarithmic plot

# What follows calculates different outcome risks:

RiskUE <- 0.1
C <- RiskUE * n/2
D <- n/2 - C
RR <- (A / (A + B)) / (C / (C + D))
OR <- (A/B) / (C/D)
lines(RR,OR)

RiskUE <- 0.25
C <- RiskUE * n/2
D <- n/2 - C
RR <- (A / (A + B)) / (C / (C + D))
OR <- (A/B) / (C/D)
lines(RR,OR)

RiskUE <- 0.5
C <- RiskUE * n/2
D <- n/2 - C
RR <- (A / (A + B)) / (C / (C + D))
OR <- (A/B) / (C/D)
lines(RR,OR)


Not really it:

• @MartijnWeterings I made the question more explicit.
– user216729
Aug 4, 2018 at 19:23

Your graphs are correct but you have different scales (see the lower left corner being more or less 2,2 instead of 0.1,0.1). You get something more similar (limits of RR and OR closer to 0.1) if you crank up your $n$ to 2000. But it will be easier to make the graph with a more direct method as below.

With risk ratio and odds ratio

$$RR = \frac{R_E}{R_U} \qquad \text{and} \qquad OR = \frac{O_E}{O_U}$$

using relations between odds and risk as $R = O/(O+1)$ or $O = R/(1-R)$ you can get to:

$$RR = \frac{OR}{1+R_U(OR-1)}$$

or

$$\frac{1-RR^{-1}}{1-OR^{-1}} =(1-R_U)$$

#empty plot
plot(0.0001, 0.0001,
log="xy",
xlim=c(0.1,10), ylim=c(0.1,13),
xlab="RR",ylab="OR")

line_type=0

# odds ratios
OR <- seq(0.1,10,0.1)

# various unexposed risks
for (UR in c(0.01, 0.1, 0.25, 0.5)) {
RR <- OR/(1+UR*(OR-1))

#plot
line_type = line_type + 1
lines(RR, OR, lt=line_type)
text(max(RR), max(OR), UR, pos=3)
}


• The graph in the article seems actually a bit odd. The .50 line goes vertical through a maximum risk ratio around odds ratio ~ 8. This is probably due to the way that the curves are drawn by the graphical software. Aug 4, 2018 at 22:02