<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/how-the-odds-ratio-confounds-a-brief-study-in-a-few-colorful-figures/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.rdatagen.net/post/log-odds/"> ouR data generation</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>The odds ratio always confounds: while it may be constant across different groups or clusters, the risk ratios or risk differences across those groups may vary quite substantially. This makes it really hard to interpret an effect. And then there is inconsistency between marginal and conditional odds ratios, a topic I seem to be visiting frequently, most recently last <a rel="nofollow" href="https://www.rdatagen.net/post/mixed-effect-models-vs-gee/" target="_blank">month</a>.</p>
<p>My aim here is to generate a few figures that might highlight some of these issues.</p>
<p>Assume that there is some exposure (indicated by the use of a <span>\(1\)</span> or <span>\(0\)</span> subscript) applied across a number of different groups or clusters of people (think different regions, hospitals, schools, etc.) – indicated by some number or letter <span>\(i\)</span>. Furthermore, assume that the total number exposed at each location is the same as the number unexposed: <span>\(N_{i0} = N_{i1} = N = 100\)</span>.</p>
<p>The number of folks with exposure at a particular location <span>\(i\)</span> who have a poor outcome is <span>\(n_{i1}\)</span> and the number with a good outcome is <span>\(N-n_{i1}\)</span>. Likewise, the corresponding measures for folks not exposed are <span>\(n_{i0}\)</span> and <span>\(N-n_{i0}\)</span>. The probabilities of a poor outcome for exposed and non-exposed are <span>\(n_{i1}/N\)</span> and <span>\(n_{i0}/N\)</span>. The relative risk of a poor outcome for those exposed compared to those non exposed is</p>
<p><span>\[\text{RR}_i = \frac{n_{i1}/N}{n_{i0}/N} = \frac{n_{i1}}{n_{i0}},\]</span><br>
the risk difference between exposed and unexposed groups is</p>
<p><span>\[ \text{RD}_i = \frac{n_{i1}}{N}-\frac{n_{i0}}{N} = \frac{n_{i1} – n_{i0}}{N},\]</span><br>
and the odds ratio is</p>
<p><span>\[ \text{OR}_i = \frac{[n_{i1}/N] / [(N – n_{i1})/N]}{[n_{i0}/N] / [(N – n_{i0})/N]} \]</span><br>
<span>\[= \frac{n_{i1}(N-n_{i0})}{n_{i0}(N-n_{i1})}.\]</span></p>
<p>The simple conditional logistic regression model that includes a group-level random effect <span>\(b_i\)</span> assumes a constant odds ratio between exposed and unexposed individuals across the different clusters:</p>
<p><span>\[\text{logit} (Y_{ij}) = \beta_0 + \beta_1 E_{ij} + b_i,\]</span><br>
where <span>\(E_{ij}\)</span> is an exposure indicator for person <span>\(j\)</span> in group <span>\(i\)</span>. The parameter <span>\(\text{exp}(\beta_1)\)</span> is an estimate of the odds ratio defined above.</p>
<p>The point of all of this is to illustrate that although the odds-ratio is the same across all groups/clusters (i.e., there is no <span>\(i\)</span> subscript in <span>\(\beta_1\)</span> and <span>\(\text{OR}_i = \text{OR}\)</span>), the risk ratios and risk differences <em>can</em> vary greatly across groups, particularly if the <span>\(b\)</span>’s vary considerably.</p>
<div>
<h3>Constant odds ratio, different risk ratios and differences</h3>
<p>If the odds ratio is constant and we know <span>\(n_{i1}\)</span>, we can perform a little algebraic maneuvering on the <span>\(\text{OR}\)</span> formula above to find <span>\(n_{i0}\)</span>:</p>
<p><span>\[ n_{i0} = \frac{N \times n_{i1}}{\text{OR} \times (N – n_{i1}) + n_{i1}}\]</span></p>
<p>If we assume that the <span>\(n_{i1}\)</span>’s can range from 2 to 98 (out of 100), we can see how the risk ratios and risk differences vary considerably even though we fix the odds ratio fixed at a value of 3 (don’t pay too close attention to the fact the <span>\(n_0\)</span> is not an integer – this is just an illustration that makes a few violations – if I had used <span>\(N=1000\)</span>, we could have called this rounding error):</p>
<pre><code>N &lt;- 100
trueOddsRatio &lt;- 3

n1 &lt;- seq(2:98)
n0 &lt;- (N * n1)/(trueOddsRatio * (N - n1) + n1)

oddsRatio &lt;- ((n1 / (N - n1) ) / (n0 / (N - n0) )) 
riskRatio &lt;- n1 / n0
riskDiff &lt;- (n1 - n0) / N

dn &lt;- data.table(n1 = as.double(n1), n0, oddsRatio, 
                 riskRatio, riskDiff = round(riskDiff,3))
dn[1:6]</code></pre>
<pre><code>##    n1        n0 oddsRatio riskRatio riskDiff
## 1:  1 0.3355705         3      2.98    0.007
## 2:  2 0.6756757         3      2.96    0.013
## 3:  3 1.0204082         3      2.94    0.020
## 4:  4 1.3698630         3      2.92    0.026
## 5:  5 1.7241379         3      2.90    0.033
## 6:  6 2.0833333         3      2.88    0.039</code></pre>
<p>With a constant odds ratio of 3, the risk ratios range from 1 to 3, and the risk differences range from almost 0 to just below 0.3. The odds ratio is not exactly informative with respect to these other two measures. The plots – two takes on the same data – tell a better story:</p>
<p><img src="https://i1.wp.com/www.rdatagen.net/post/2018-07-10-odds-ratio_files/figure-html/unnamed-chunk-2-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
</div>
<div>
<h3>Another look at contrasting marginal vs conditional odds ratios</h3>
<p>Using this same simple framework, I thought I’d see if I can illustrate the relationship between marginal and conditional odds ratios.</p>
<p>In this case, we have two groups/clusters where the conditional odds ratios are equivalent, yet when we combine the groups into a single entity, the combined (marginal) odds ratio is less than each of the conditional odds ratios.</p>
<p>In this scenario each cluster has 100 people who are exposed and 100 who are not, as before. <span>\(a_1\)</span> and <span>\(a_0\)</span> represent the number of folks with a poor outcome for the exposed and unexposed in the first cluster, respectively; <span>\(b_1\)</span> and <span>\(b_0\)</span> represent the analogous quantities in the second cluster. As before <span>\(a_0\)</span> and <span>\(b_0\)</span> are derived as a function of <span>\(a_1\)</span> and <span>\(b_1\)</span>, respectively, and the constant odds ratio.</p>
<pre><code>constantOR &lt;- function(n1, N, OR) {
  return(N*n1 / (OR*(N-n1) + n1))
}


# Cluster A

a1 &lt;- 55
a0 &lt;- constantOR(a1, N = 100, OR = 3)
(a1*(100 - a0)) / (a0 * (100 - a1))</code></pre>
<pre><code>## [1] 3</code></pre>
<pre><code># Cluster B

b1 &lt;- 35
b0 &lt;- constantOR(b1, N = 100, OR = 3)
(b1*(100 - b0)) / (b0 * (100 - b1))</code></pre>
<pre><code>## [1] 3</code></pre>
<pre><code># Marginal OR
tot0 &lt;- a0 + b0
tot1 &lt;- a1 + b1

(tot1*(200 - tot0)) / (tot0 * (200 - tot1))</code></pre>
<pre><code>## [1] 2.886952</code></pre>
<p>For this example, the marginal odds ratio is less than the conditional odds ratio. How does this contrast between the marginal and conditional odds ratio play out with a range of possible outcomes – all meeting the requirement of a constant conditional odds ratio? (Note we are talking about odds ratio larger than 1; everything is flipped if the OR is &lt; 1.) The plot below shows possible combinations of sums <span>\(a_1 + b_1\)</span> and <span>\(a_0 + b_0\)</span>, where the constant conditional odds ratio condition holds within each group. The red line shows all points where the marginal odds ratio equals the conditional odds ratio (which happens to be 3 in this case):</p>
<p><img src="https://i2.wp.com/www.rdatagen.net/post/2018-07-10-odds-ratio_files/figure-html/unnamed-chunk-4-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>Here is the same plot, but a yellow line is drawn in all cases where <span>\(a_1 = b_1\)</span> (hence <span>\(a_0 = b_0\)</span>). This line is the directly over the earlier line where the marginal odds ratios equal 3. So, sort of proof by plotting. The marginal odds ratio appears to equal the conditional odds ratio when the proportions of each group are equal.</p>
<p><img src="https://i2.wp.com/www.rdatagen.net/post/2018-07-10-odds-ratio_files/figure-html/unnamed-chunk-5-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>But are the marginal odds ratios not on the colored lines higher or lower than 3? To check this, look at the next figure. In this plot, the odds ratio is plotted as a function of <span>\(a_1 + b_1\)</span>, which represents the total number of poor outcomes in the combined exposed groups. Each line represents the marginal odds ratio for a specific value of <span>\(a_1\)</span>.</p>
<p><img src="https://i0.wp.com/www.rdatagen.net/post/2018-07-10-odds-ratio_files/figure-html/unnamed-chunk-6-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>If you notice, the odds ratio reaches the constant conditional odds ratio (which is 3) only when <span>\(a_1 + b_1 = 2a_1\)</span>, or when <span>\(a_1 = b_1\)</span>. It appears then, when <span>\(a_1 \ne b_1\)</span>, the marginal odds ratio lies below the conditional odds ratio. Another “proof” by figure. OK, not a proof, but colorful nonetheless.</p>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.rdatagen.net/post/log-odds/"> ouR data generation</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/re57U_TUC20" height="1"></a></div>