MyNixOS website logo
Description

'Stata'-Like Matched Case-Control Analysis.

Calculate multiple statistics with confidence intervals for matched case-control data including risk difference, risk ratio, relative difference, and the odds ratio. Results are equivalent to those from 'Stata', and you can choose how to format your input data. Methods used are those described on page 56 the 'Stata' documentation for "Epitab - Tables for Epidemologists" <https://www.stata.com/manuals/repitab.pdf>.

matchedcc

R-CMD-check CRANstatus codecov

The aim of matchedcc is to provide epidemiologists using R with Stata-like analysis of matched case-control data. This package has two functions, mcc() and mcci(), which are direct analogues of Stata’s own mcc and mcci commands.

Installation

You can install matchedcc from CRAN with:

install.packages("matchedcc")

You can also install the development version from GitHub with pak:

# install.packages("pak")
pak::pkg_install("simpar1471/matchedcc")

Examples

The functions in matchedcc are easy to use. To demonstrate their use, we will use the mccxmpl dataset, which is included in matchedcc. This dataset has two columns - cases and controls. In this dataset, cases had experienced a heart attack, and cases and controls were matched accordingly. Each column has only 1 or 0 values, which describe whether a case or control encountered our exposure - in this case, drinking >6 cups of coffee per day.

library(matchedcc)
head(matchedcc::mccxmpl)
#>   case control
#> 1    1       1
#> 2    1       0
#> 3    0       1
#> 4    0       0
#> 5    1       1
#> 6    1       1

Vector input

The mcc() function will take vectors of 1s and 0s and use these to run a matched case control analysis:

mcc(cases = matchedcc::mccxmpl$case, controls = matchedcc::mccxmpl$control)
#> $data
#>            Controls
#> Cases       Unexposed Exposed Total
#>   Unexposed         8       8    16
#>   Exposed           3       8    11
#>   Total            11      16    27
#> 
#> $mcnemar_chi2
#> 
#>  McNemar's Chi-squared test
#> 
#> data:  mcc_table
#> McNemar's chi-squared = 2.2727, df = 1, p-value = 0.1317
#> 
#> 
#> $mcnemar_exact_p
#> Exact McNemar significance probability 
#>                              0.2265625 
#> 
#> $proportions
#>   Proportion with factor
#>        Cases  Controls
#>    0.5925926 0.4074074
#> 
#> $statistics
#>             estimate [95% CI]
#> statistic     estimate       lower      upper
#>   difference 0.1851852 -0.08225420  0.4526246
#>   ratio      1.4545455  0.89110096  2.3742568
#>   rel. diff. 0.3125000 -0.02436881  0.6493688
#>   odds ratio 2.6666667  0.64003641 15.6064036

2x2 table input

The mcc() function can also accept a 2x2 table with matched case-control data, provided it is in the following format:

CasesControls
ExposedUnexposed
Exposedab
Unexposedcd
mcc_table <- table(matchedcc::mccxmpl$control,
                   matchedcc::mccxmpl$case)
mcc(table = mcc_table)
#> $data
#>            Controls
#> Cases       Unexposed Exposed Total
#>   Unexposed         8       8    16
#>   Exposed           3       8    11
#>   Total            11      16    27
#> 
#> $mcnemar_chi2
#> 
#>  McNemar's Chi-squared test
#> 
#> data:  mcc_table
#> McNemar's chi-squared = 2.2727, df = 1, p-value = 0.1317
#> 
#> 
#> $mcnemar_exact_p
#> Exact McNemar significance probability 
#>                              0.2265625 
#> 
#> $proportions
#>   Proportion with factor
#>        Cases  Controls
#>    0.5925926 0.4074074
#> 
#> $statistics
#>             estimate [95% CI]
#> statistic     estimate       lower      upper
#>   difference 0.1851852 -0.08225420  0.4526246
#>   ratio      1.4545455  0.89110096  2.3742568
#>   rel. diff. 0.3125000 -0.02436881  0.6493688
#>   odds ratio 2.6666667  0.64003641 15.6064036

‘Immediate’ input

Last but not least, if you have individual cell counts from a 2x2 table, you can provide them to mcci():

mcci(a = 8, b = 8, c = 3, d = 8)
#> $data
#>            Controls
#> Cases       Unexposed Exposed Total
#>   Unexposed         8       8    16
#>   Exposed           3       8    11
#>   Total            11      16    27
#> 
#> $mcnemar_chi2
#> 
#>  McNemar's Chi-squared test
#> 
#> data:  mcc_table
#> McNemar's chi-squared = 2.2727, df = 1, p-value = 0.1317
#> 
#> 
#> $mcnemar_exact_p
#> Exact McNemar significance probability 
#>                              0.2265625 
#> 
#> $proportions
#>   Proportion with factor
#>        Cases  Controls
#>    0.5925926 0.4074074
#> 
#> $statistics
#>             estimate [95% CI]
#> statistic     estimate       lower      upper
#>   difference 0.1851852 -0.08225420  0.4526246
#>   ratio      1.4545455  0.89110096  2.3742568
#>   rel. diff. 0.3125000 -0.02436881  0.6493688
#>   odds ratio 2.6666667  0.64003641 15.6064036

Validation against Stata

The package is validated against Stata’s own outputs, using 1000 randomly generated mcci runs from Stata. The code to generate these can be seen in /tests/testdata/run-stata-mcc.R.

Citation

Parker S (2024). matchedcc: Stata-like matched case-control analysis. https://github.com/simpar1471/matchedcc/.

Metadata

Version

0.1.1

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows