rStats.js v1.3.0
    Preparing search index...

    Function oddsRatio

    • Odds ratio of a 2 x 2 table with its confidence interval and three p-values of independence. Equivalent to epitools::oddsratio() in R.

      The table is in epitools' orientation: rows are the exposure (row 1 the reference level) and columns the outcome (column 1 without the disease); the odds ratio x11 x22 / (x12 x21) is the same for the transposed table.

      Methods (method): "midp" (the default, as epitools: the median-unbiased estimate and the mid-p exact interval from Fisher's noncentral hypergeometric distribution of x11 given the margins), "fisher" (the conditional MLE and the exact interval of fisherTest), "wald" (the sample odds ratio and Woolf's interval on the log scale; as epitools, no zero-cell correction: a zero cell gives an estimate of 0 or Infinity and NaN for the limit that is not defined) and "score" (the sample odds ratio and the score interval of epiR's epi.2by2, Miettinen-Nurminen without the factor N/(N - 1)). The mid-p and score limits are the roots of their equations to the precision of the doubles (epitools solves with uniroot's tolerance on [0, 1000] and fails beyond and for zero cells; epiR steps by 0.1%). With a zero cell the mid-p estimate and limits follow the conventions of exact2x2: 0 or Infinity at the end of the support.

      pValue has epitools' three p-values: the two-sided mid-p (twice the smaller one-sided mid-p value), Fisher's exact test and Pearson's chi-squared without continuity correction (with R's warning "Chi-squared approximation may be incorrect" where an expected count is below 5).

      Parameters

      Returns OddsRatioResult

      See OddsRatioResult. Limits: the exact methods ("midp", "fisher") need the support of x11 given the margins (min(x11, x22) + min(x12, x21) + 1 values) to be at most 2^23 (about 6 s), and "fisher" counts of at most 2^31 - 1 (as fisherTest); the p-values of every method need phyper within its 2^26 terms (counts up to about 1e12).

      TypeError if the table is not 2 x 2; RangeError for negative or non-integer counts, a table of zeros, a level outside (0, 1), an unknown method, or a table beyond the limits above.

      const r = oddsRatio([[56, 14], [48, 32]]);
      r.estimate; // 2.6364237331551914
      r.confInt; // [1.276159154292712, 5.670866460839431]
      r.pValue; // { midp: 0.008449442679452648, fisher: 0.012521129749209155, chiSquare: 0.00804508136819659 }