-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
104 lines (76 loc) · 3.02 KB
/
README.Rmd
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# matchedcc
<!-- badges: start -->
[](https://github.com/simpar1471/matchedcc/actions/workflows/R-CMD-check.yaml)
[](https://CRAN.R-project.org/package=matchedcc)
[](https://app.codecov.io/gh/simpar1471/matchedcc)
[](https://doi.org/10.5281/zenodo.14199808)
<!-- badges: end -->
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:
``` r
install.packages("matchedcc")
```
You can also install the development version from GitHub with **pak**:
``` r
# 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.
```{r show_data}
library(matchedcc)
head(matchedcc::mccxmpl)
```
### Vector input
The `mcc()` function will take vectors of `1`s and `0`s and use these to run a
matched case control analysis:
```{r example_vec}
mcc(cases = matchedcc::mccxmpl$case, controls = matchedcc::mccxmpl$control)
```
### 2x2 table input
The `mcc()` function can also accept a 2x2 table with matched case-control data,
provided it is in the following format:
| Cases | Controls | |
|-----------|----------|-----------|
| | Exposed | Unexposed |
| Exposed | a | b |
| Unexposed | c | d |
```{r example_tbl}
mcc_table <- table(matchedcc::mccxmpl$control,
matchedcc::mccxmpl$case)
mcc(table = mcc_table)
```
### 'Immediate' input
Last but not least, if you have individual cell counts from a 2x2 table, you can
provide them to `mcci()`:
```{r example_imm}
mcci(a = 8, b = 8, c = 3, d = 8)
```
## 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/>.