We present
The
Deaths due to plague during the second plague pandemic were examined using a 2×2 contingency table framework. We considered those with counts given in notation of
Example of 2×2 contingency table.
INCIDENCE  

CLASSIFICATION  +  –  TOTAL AT RISK 
–  
Total  
We outline the considerations we made for the relative risk briefly. The relative risk for a dichotomous variable is given by the proportion of the probability of an outcome of interest and the probability of the other outcome. The relative risk for
which is our variable of interest.
We consider the ratio of two independent beta distributed random variables
and cumulative distribution function [see the appendix of 1, for full derivation]
We add our data from
To obtain an equaltailed, quantile interval (
To obtain a highest posterior density (
to obtain the lower and upper limit of the 100(1–
or
or individually by
Functions in
FUNCTION GROUPING  FUNCTION  DESCRIPTION 

Relative risk, a comparative measure for 2×2 contingency table  
Odds ratio, a comparative measure for 2×2 contingency table seen in Equation 1  
A wrapper function returning both the relative risk and odds ratio  
χ^{2} statistic for testing the hypothesis of no association between the two variables in a 2×2 contingency table  
χ^{2} test for the statistic  
Prior density of a ratio of two independent beta distributions  
Posterior distribution of a ratio of two independent beta distributions  
The equaltailed credible interval of a ratio of two independent beta distributions  
The highest posterior density credible interval of a ratio of two independent beta distributions  
A wrapper function returning the equaltailed credible interval and the highest posterior density credible interval or both (chosen by the user)  
Cholera is a disease caused by the bacterium
Waldemar Mordecai Haffkine studied the effects of inoculation against cholera in India in 1893–1896 [
Haffkine’s cholera data from Greenwood and Yule [
3  4  5  6  

A  NA  T  A  NA  T  A  NA  T  A  NA  T  
I  3  276  279  18  115  133  0  75  75  0  193  193 
NI  66  473  539  120  520  640  19  778  797  6  723  729 
T  69  749  818  138  635  773  19  853  872  6  916  922 
I  8  200  208  5  105  110  4  192  196  27  5751  5778 
NI  20  182  202  11  88  99  34  113  147  198  6351  6549 
T  28  382  410  16  193  209  38  305  343  225  12102  12327 
Relative risks and credible intervals for data from
HAFFKINE  INTERVAL  

EQUALTAILED  HIGHEST POSTERIOR DENSITY  
3  0.0878  [0.0513, 0.3352]  [0.0374, 0.3025]  (HPD starting values: [0.1, 0.4]) 
4  0.7218  [0.5393, 1.0333]  [0.5218, 1.4436]  
7  0.3885  [0.2205, 0.7060]  [0.1881, 0.7753]  
8  0.4091  [0.2179, 0.7972]  [0.1476, 0.9875]  (HPD starting values: [0.2, 0.5]) 
9  0.0882  [0.0353, 0.3319]  [0.0284, 0.3061]  
10  0.1546  [0.0180, 0.3946]  [0.0421, 0.4364]  
We illustrate how to use
In order to obtain the intervals (4, 5) for the
and
for this example we could have also run frac_ints as this assumes an argument of
If the user does not want those defaults, we recommend that they run the two interval functions separately. As we use
We can engage pretty printing using the
which is the expression we evaluated to obtain numerical values when the
We use the
As with all numerical optimisation problems, different starting values can lead to disparate solutions, and as there may not be a closedform expression of the solution to the highest posterior density minimisation, users are encouraged to investigate their own starting parameters.
We compare our
Available options for calculating uncertainty of ratios using credible intervals.
NAME  LANGUAGE  AUTHOR(S) 

Python  Matsen IV et al. [ 

R  supplement to Sverdlov et al. [ 

The strength of our approach compared with these implementations is that we have considered use of priors for the proportions
Our implementation has been demostrated with examples from epidemiology but can be used in any science where 2×2 contingency tablelike data arise. For example, within the field of ecology, the response ratio is an index used in metaanalysis of ecological experiments. It is implied in Hedges et al. [
We have created a Python package
The
Any operating system where Python 2.7.14 or better or 3.5.5 or better with the dependencies enumerated below are installed. In practice this includes all three major operating systems (Linux/Unix, Windows 7 or better and Mac OS/OS X 10.6 or newer) together with a number of smaller platforms.
Python 2.7.14, 3.5.5 and 3.6.6.
This software has no particularly unusual system requirements and should operate on any typical desktop machine produced in the last five years. The calculations are CPU bound so the greater the single thread performance of the machine the more swiftly the computations will complete.
English
We broadly outline the reuse potential of this software in the discussion section of this work but as a recapitulation this package permits the calculation of credible intervals wherever 2×2 type contingency table data appear in science. With the additional benefit that prior knowledge may be incorporated into this estimate in a truly Bayesian manner. Issues and feedback about the software can be provided by users through the GitHub issue logging system.
The research leading to these results has received UK government grantinaid funding. MBND and TJRF were funded by the National Institute for Health Research—Health Protection Research Unit for Modelling Methodology (HPRU MM). The funding bodies (UK government and HPRU MM) did not play any role in the formulation of this manuscript. The views expressed in this publication are those of the authors and not necessarily those of Public Health England.
The authors have no competing interests to declare.