create a data frame from a 2x2 matrix

data_frame_from_2x2(x)

Arguments

x

a 2x2 matrix or 3D array with exposure variable in rows and outcome in columns

Value

a data frame with the important combinations:

  • A_exp_cases

  • B_exp_controls

  • C_unexp_cases

  • D_unexp_controls

  • total_cases (A + B)

  • total_controls (C + D)

  • total_exposed (A + C)

  • total_unexposed (B + D)

  • total (A + B + C + D)

Examples

arr <- c(10, 35, 90, 465, 36, 25, 164, 175)
arr <- array(arr,
  dim = c(2, 2, 2),
  dimnames = list(
    risk = c(TRUE, FALSE),
    outcome = c(TRUE, FALSE),
    old = c(FALSE, TRUE)
  )
)
arr
#> , , old = FALSE
#> 
#>        outcome
#> risk    TRUE FALSE
#>   TRUE    10    90
#>   FALSE   35   465
#> 
#> , , old = TRUE
#> 
#>        outcome
#> risk    TRUE FALSE
#>   TRUE    36   164
#>   FALSE   25   175
#> 
data_frame_from_2x2(arr)
#>       A_exp_cases B_exp_controls C_unexp_cases D_unexp_controls total_cases
#> crude          46            254            60              640         106
#> FALSE          10             90            35              465          45
#> TRUE           36            164            25              175          61
#>       total_controls total_exposed total_unexposed total
#> crude            894           300             700  1000
#> FALSE            555           100             500   600
#> TRUE             339           200             200   400