expandTables: Convert '2x2 tables' to 'data.frame'

Description Usage Arguments Details Author(s) See Also Examples

View source: R/expandTables.R

Description

expandTables generates a data frame and supports two levels.

Usage

1
2
3
4
5
6
7
8
9
expandTables(
  ...,
  exp_name = "exposure",
  exp_lvl = c("exposed", "unexposed"),
  case_name = "outcome",
  case_lvl = c("disease", "healthy"),
  strata_name = "strata",
  stringsAsFactors = FALSE
)

Arguments

...

vectors of 2x2 tables

exp_name

Name of Exposure Variable

exp_lvl

Names of two categories in the order of Exposed and non-exposed

case_name

Name of Case variable

case_lvl

names of two categories in the order of

strata_name

Name of stratified variable

stringsAsFactors

logical: should the character vector be converted to a factor? Disease and healthy

Details

expandTables uses the vectors of 2x2 tables and generates a data frame of three columns: Exposure, Outcome and Strata, intended for calculations of stratified 2x2 tables using Mantel Haenszel methods.

Author(s)

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

See Also

mhodds, stmh

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
## Not run: 

## one table
tab <- expandTables(c(60, 140, 60, 40))
xtab(tab, exposure)

## one table with full labels
tab <- expandTables(c(60, 140, 60, 40), exp_name = "Type of area",
    exp_lvl = c("Rural", "urban"),
    case_name = "Antibodies",
    case_lvl = c("Yes", "No"))
xtab(tab)

## 2 tables
tab <- expandTables(male = c(36, 14, 50, 50),
    female = c(24, 126, 10, 90),
    exp_name = "Type of area", exp_lvl = c("Rural", "Urban"),
    case_name = "Antibodies", case_lvl = c("Yes", "No"),
    strata_name = "gender")
### checking numbers
tab %>%
    pick(gender == "male") %>%
    xtab(`Type of area`, `Antibodies`, .)
tab %>%
    pick(gender == "female") %>%
    xtab(`Type of area`, `Antibodies`, .)

## End(Not run)

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