My question concerns the calculation of risk ratios and odds ratios for meta-analysis using the metafor package. I know it looks long, but please bear with me, as it is a simple question. I've simply provided a lot of background information. First, copy/paste the below to make my example data.

# Load package

# Create example_data      
example_data <- 
trial = c(1, 2, 3, 4, 5, 6),
author = c("Abers", "Baker", "Cook", "Dodds", "Eggers", "Fritz"),
year = c(2000, 2001, 2002, 2003, 2004, 2005),
tpos = c(437, NA, 51, 26, 468, 10),
tneg = c(49, NA, 1, 8, 83, 1),
cpos = c(50, 7, 6, 0, 36, 0),
cneg = c(33, 8, 0, 0, 19, 0)

# Show example_data
  trial author year tpos tneg cpos cneg
1     1  Abers 2000  437   49   50   33
2     2  Baker 2001   NA   NA    7    8
3     3   Cook 2002   51    1    6    0
4     4  Dodds 2003   26    8    0    0
5     5 Eggers 2004  468   83   36   19
6     6  Fritz 2005   10    1    0    0

More background

If I were to make a two-by-two table by hand for the first study, Abers, it would look as follows:

      pos  neg
 pos  437   49 
 neg  50    33

The relative risk would be calculated by hand as follows:

RR = (437/(437 + 49)) / (50/(50 + 33)) = 1.49
log(RR) = 0.40

The odds ratio would be calculated by hand as follows:

OR = (437 * 33) / (50 * 49) = 5.89
log(OR) = 1.77

Here are the forest plots for log(RR) and log(OR). If you look at the first line in each plot, you can see that metafor produces the same values as I did by hand for the Abers study.

Example log(RR)

Example log(OR)

My question

Take a look at the line for Dodds on the plots. Where are these values for log(RR) and log(OR) coming from? As I see it, if I were to make a two-by-two table for the Dodds, it would look as follows:

      pos  neg
 pos   26    8 
 neg    0    0

The relative risk would be calculated by hand as follows:

RR = (26/(26 + 8)) / (0/(0 + 0)) = Undefined! As you cannot divide by zero.
log(RR) = ?

The odds ratio would be calculated by hand as follows:

OR = (26 * 0) / (0 * 8) = Again, undefined!
log(OR) = ?

So how did the metafor package calculate a log(RR) of 0.41 and a log(OR) of 1.14 for the Dodds study? And more generally, for all of my studies with zero values (e.g., Cook, Dodds, and Fritz), can I even include any of them in my meta-analysis?


1 Answer 1


Quoting from the documentation (help(escalc)):

Cell entries with a zero count can be problematic, especially for the relative risk and the odds ratio. Adding a small constant to the cells of the 2x2 tables is a common solution to this problem. When to="only0" (the default), the value of add (the default is 1/2) is added to each cell of those 2x2 tables with at least one cell equal to 0. When to="all", the value of add is added to each cell of all 2x2 tables. When to="if0all", the value of add is added to each cell of all 2x2 tables, but only when there is at least one 2x2 table with a zero cell. Setting to="none" or add=0 has the same effect: No adjustment to the observed table frequencies is made. Depending on the outcome measure and the data, this may lead to division by zero inside of the function (when this occurs, the resulting value is recoded to NA). Also, studies where ai=ci=0 or bi=di=0 may be considered to be uninformative about the size of the effect and dropping such studies has sometimes been recommended (Higgins & Green, 2008). This can be done by setting drop00=TRUE. The counts for such studies will then be set to NA.

So, to make a long story short, escalc() added 1/2 to the cell counts before computing the log(RR) or the log(OR).

  • $\begingroup$ Thanks @Wolfgang - Do you therefore think I should remove these studies from the meta-analysis/plot? $\endgroup$
    – Alexander
    Apr 12, 2014 at 18:22
  • 1
    $\begingroup$ It's common practice to make this adjustment, so no, not necessarily. But I cannot give any more detailed recommendations without knowing much more about these data. And by the way, the two-by-two tables for Dodds and for Fritz are a bit strange, as both cells in the second row ('c' and 'd') are zeros. I suppose this could happen under multinominal (cross-sectional) sampling, but seems a bit odd for stratified sampling. Are these real data? And if yes, what are they supposed to reflect? $\endgroup$
    – Wolfgang
    Apr 12, 2014 at 18:26
  • $\begingroup$ You are right, they are strange. They are from a case series report, and I know that it's illegal to include such a report in a meta-analysis so I don't plan to actually include them. These are surgical patients who either had (positive) or did not have (negative) an attribute noted during the surgery, and then their post-operative course was either complicated (positive) or non-complicated (negative). Another question - do you think it would be better to report the RR or the OR analysis for these data? $\endgroup$
    – Alexander
    Apr 12, 2014 at 18:31
  • 1
    $\begingroup$ Then that sounds like cross-sectional sampling (both variables were simply observed). I would then suggest to only use the odds ratio as the outcome measure. And in that case, it would probably be okay to include those studies. $\endgroup$
    – Wolfgang
    Apr 12, 2014 at 18:39
  • 1
    $\begingroup$ If you only want the visual reminder, you could also set to="none", but then use options(na.action="na.pass") before creating the forest plot. See here for further details. $\endgroup$
    – Wolfgang
    Apr 13, 2014 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.