mhodds: Tabulation to display Odds Ratios

Description Usage Arguments Details Author(s) See Also Examples

View source: R/mhodds.R

Description

mhodds generates cross-tabulation between two variables and display odds as well as Odds Ratios of failure var_case against a categorical explanatory variable var_exp.

It is used with cross-sectional as well as case-control data.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
mhodds(
  var_case,
  var_exp,
  data = NULL,
  exposed = NULL,
  strata = NULL,
  na.rm = FALSE,
  rnd = 3,
  print.table = TRUE
)

## S3 method for class 'character'
mhodds(
  var_case,
  var_exp,
  data = NULL,
  exposed = NULL,
  strata = NULL,
  na.rm = FALSE,
  rnd = 3,
  print.table = TRUE
)

## S3 method for class 'list'
mhodds(
  var_case,
  var_exp,
  data = NULL,
  exposed = NULL,
  strata = NULL,
  na.rm = FALSE,
  rnd = 3,
  print.table = TRUE
)

calc_OR(t, ref_lvl, rnd)

Arguments

var_case

Case or outcome variable should be binary vector.

var_exp

Exposure variable.

data

a data frame object (Optional)

exposed

a number or character representing reference value

strata

variable to stratify by Mantel-Haenszel method

na.rm

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

rnd

specify rounding of numbers. See round.

print.table

logical value to display formatted outputs

t

2x2 table input to calaculate odds ratio of non-reference

ref_lvl

logical vector to indicate where reference category is

Details

The variable var_case should coded 1 for case and 0 for non-case. The arugment exposed can be used to set the reference value for comparison of odds ratios.

It produces a simple table with odds, Odds Ratio,95 p-value. If strata is specified, Mantel-Haenzsel\'s Odds Ratio is generated along with chi-sqaured test for heterogeneity.

Odds Ratio

p(x) = λ^{x} exp(-λ)/x!

for x = 0, 1, 2, ….

\square_{i=1}^n X_i$$

Error Factor

is calcluated using the following formula:

EF = exp(log(Odds Ratio) \pm{} 1.96 * SE

SE = √{1/D1 + 1/D0 + 1/H1 + 1/H0}

References:

  1. Essential Medical Statistics, Betty R. Kirkwood & Jonathan A.C. Sterne, Second Edition. Chapter 3

Author(s)

Myo Minn Oo (Email: dr.myominnoo@gmail.com | Website: https://myominnoo.github.io/)

See Also

tabodds, expandTables

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
## Not run: 
## Create stratified 2x2 tables from page 178 (Essential Medical
Statistics)
## See ?expandTables
ab <- expandTables(male = c(36, 14, 50, 50),
    female = c(24, 126, 10, 90),
    exp_name = "areaType", exp_lvl = c("Rural", "Urban"),
    case_name = "Antibodies", case_lvl = c("Yes", "No"),
    strata_name = "gender")

## Labelling data and variables
ab <- labelData(ab, "Prevalence survey of leptospirosis in West Indies")
ab <- labelVars(ab, areaType, "Type of area in west indies")
ab <- labelVars(ab, Antibodies, "Leptospirosis antibodies")
ab <- labelVars(ab, gender, "Male or Female")

## Claculating Odds Ratios
mhodds(areaType, Antibodies, ab)
mhodds(areaType, Antibodies, ab, exposed = "Urban")

## Claculating Mantel-Haenzsel Odds Ratio
mhodds(areaType, Antibodies, ab, exposed = "Urban",
    strata = gender)

## Breast Cancer example (page 162, Essential Medical Statistics)
breast <- expandTables(c(88, 12, 71, 29),
                       exp_name = "drug",
                       exp_lvl = c("new", "standard"),
                       case_name = "nausea",
                       case_lvl = c("severe", "none"))

tabodds(drug, nausea, breast)
mhodds(drug, nausea, breast, exposed = "standard")


## Asthma Example (page 160, Essential Medical Statistics)
asthma <- expandTables(c(81, 995, 57, 867),
             exp_name = "Sex",
             exp_lvl = c("Women", "Man"),
             case_name = "Asthma",
             case_lvl = c("Yes", "No"))

## labelling
asthma <- labelData(asthma, "Hypothetical Data of Asthma Prevalence")
asthma <- labelVars(asthma,
    c(Sex, Asthma), c("Man or Woman", "Asthma or No Asthma"))

## Checking codebook
codebook(asthma)

## Odds
tabodds(Sex, Asthma, asthma)

## Odds ratios
mhodds(Sex, Asthma, asthma)
mhodds(Sex, Asthma, asthma, "Women")

## The odds ratio, J Martin Bland, Douglas G Altman, BMJ 2000;320:1468
hay <- expandTables(c(141, 420, 928, 13525),
                    exp_name = "eczema",
                    exp_lvl = c("Yes", "No"),
                    case_name = "hayFever",
                    case_lvl = c("Yes", "No"))
hay <- labelData(hay, "hay fever and eczema in 11 year old children")
hay <- labelVars(hay,
                 c(eczema, hayFever),
                c("prevalence of eczema", "prevalence of hay fever"))


tabodds(eczema, hayFever, hay)
mhodds(eczema, hayFever, hay, "Yes")

## End(Not run)

myominnoo/mStats_beta documentation built on Feb. 29, 2020, 8:17 a.m.