Learn R Programming

mStats (version 3.2.2)

mhor: Calculating Odds Ratios

Description

mhor() calculates odds ratios, Mantel Haenszel pooled estimates and 95% CI.

Usage

mhor(
  data,
  ...,
  by,
  strata = NULL,
  exp_value = NULL,
  case_value = NULL,
  plot = TRUE,
  na.rm = FALSE,
  rnd = 3
)

Arguments

data

Dataset

...

Variable or multiple variables Colon separator : can be used to specify multiple variables.

by

Varaiable for cross-tabulation

strata

Variable for stratification

exp_value

value for exposure as reference

case_value

value for outcome as reference

plot

logical value to display plots of odds ratios including MH estimates across a categorical variable

na.rm

A logical value to specify missing values, NA in the table

rnd

specify rounding of numbers. See round.

Details

Value can be set as baseline by specifying exp_value. This is used when the exposed and case values are not in the right place.

It produces a table with Odds Ratio,95% CI as well as p-value. If strata is specified, Mantel-Haenzsel Pooled estimates of Odds Ratio is generated along with Chi-sqaured test for heterogeneity.

Odds Ratio, OR

$$OR = (D1 x H0) / (D0 x H1)$$

Error Factor, EF using Woolf's formula

$$95\% CI = OR / EF or OR x EF$$

$$EF = exp(1.96 x SE(log(OR)))$$

$$SE(log(OR)) = \sqrt{1/D1 + 1/H1 + 1/D0 + 1/H0}$$

Calculating p-value from Wald's z test

$$z = log OR / SE (log OR)$$

Mantel-Haenszel's OR

$$ORMH = Q / R$$

$$Q = \sum{(D1i x H0i) / ni}$$

$$R = \sum{(D0i x H1i) / ni}$$

Calculating CI for MH-OR

$$95\% CI = OR / EF or OR x EF$$

$$SE(ORMH) = \sqrt{V / (Q x R)}$$

$$V = \sum{(Di x Hi x n0i x n1i) / ( (ni)^2 x (ni - 1))}$$

Chi-square test for MHOR, df = 1

$$X^2 (MH), Chi-square value = U^2 / V$$

$$U = O - E$$

$$O = \sum{D1i}$$

$$E = \sum{Di x n1i / ni}$$

Chi-square test for Heterogeneity

$$X^2 = \sum{(D1i x H0i - ORMH x D0i x H1i)^2 / ORMH x Vi x ni^2}$$

References

  1. Betty R. Kirkwood, Jonathan A.C. Sterne (2006, ISBN:978<U+2013>0<U+2013>86542<U+2013>871<U+2013>3)

  2. B. Burt Gerstman (2013, ISBN:978-1-4443-3608-5)

  3. Douglas G Altman (2005, ISBN:0 7279 1375 1)

Examples

Run this code
# NOT RUN {

### Example from Essential Medical Statistics
# Page 178, Chapter 18: Controlling for confounding: Stratification
lepto <- expandTables(
    male = c(36, 14, 50, 50), female = c(24, 126, 10, 90),
    exp_name = "area", exp_lvl = c("Rural", "Urban"),
    case_name = "ab", case_lvl = c("Yes", "No"),
    strata_name = "gender"
)

## label variables and data
lepto <- labelData(lepto, "Prevalence survey of leptospirosis in West Indies")
lepto <- labelVar(lepto,
              c(area, ab, gender),
              c("Type of area", "Leptospirosis Antibodies",
                "Gender: Male or female"))

## check dataset
codebook(lepto)

## Calculate OR
mhor(lepto, area, by = ab, case_value = "Yes")

# }

Run the code above in your browser using DataLab