-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
119 lines (78 loc) · 3.35 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
warnings = FALSE,
messages = FALSE,
prompt = FALSE,
fig.path = "man/figures/README-",
out.width = "100%"
)
```
<!-- badges: start -->
[](https://github.com/lan-k/CXOwt/actions/workflows/R-CMD-check.yaml)
[](https://codecov.io/gh/lan-k/CXOwt)
<!-- badges: end -->
# CXOwt
This R package was is code to implement weighted conditional logistic regression described [here](https://bmcmedresmethodol.biomedcentral.com/articles/10.1186/s12874-021-01408-5).
## Installation
`CXOwt` is still under development. You can install the latest version from [GitHub](https://github.com/) with:
```{r install, results = "hide", eval = FALSE}
# install.packages("remotes")
remotes::install_github("lan-k/CXOwt")
```
## Data
Data should be structured with one row per period per person. The data should be ordered so that for each person, the earliest period appears first in the data, the case period appears last.
The following 3 variables are required:
Patient ID
Binary exposure indicator (0 for unexposed or 1 for exposed)
Binary indicator for the outcome
- 0 in control periods
- 1 in case period for cases
- 0 in case period for time controls
The package comes with two example dataframes
- "cases" with cases only
- "casetimecontrols" with cases and time controls
The exposure variable is "ex" and the outcome variable is "Event".
```{r data, eval=T}
library(CXOwt)
#case-crossover
data(cases)
head(cases)
tail(cases) # last few rows of data for a case
#case-time-controls
data(casetimecontrols)
tail(casetimecontrols[casetimecontrols$Id == 2,]) # last few rows of data for a time control
```
## Using the package
`CXOwt` contains functions for both case-crossover and case-time-control designs. There are 2 example dataframes, `cases` and `casetimecontrols`.
`CXO_wt_boot()` is the version for case-crossover studies, `CXO_tc_wt_boot()` for case-time-control studies. Both return the weighted Odds Ratio estimate and bootstrapped 95% confidence intervals.
```{r example1, eval=F}
library(CXOwt)
#case-crossover
data(cases)
cfit.b <- CXO_wt_boot(data=cases, exposure = ex, event = Event, Id=Id, B=500)
summary(cfit.b)
#case-time-control
data(casetimecontrols)
ctcfit.b <- CXO_tc_wt_boot(data=casetimecontrols, exposure = ex, event = Event, Id=Id, B = 500)
summary(ctcfit.b)
```
Alternatively, you can return the weighted conditional logistic regression objects without bootstrapping. However, the standard errors and 95% confidence intervals may not be accurate. The output will be a 'clogit' object.
```{r example2, eval=T}
#case-crossover
cfit <- CXO_wt(cases, exposure = ex, event = Event, Id=Id)
exp(cbind(coef(cfit), confint(cfit)))
#case-time-control
ctcfit <- CXO_tc_wt(casetimecontrols, exposure = ex, event = Event, Id=Id)
exp(cbind(coef(ctcfit), confint(ctcfit)))
```
Other functions include
- 'mhor' to produce Mantel-Haenszel (MH) Odds Ratios
- 'SCL_bias' to estimate the bias in (unweighted) conditional logistic regression compared with MH ORs