-
Notifications
You must be signed in to change notification settings - Fork 4
/
Basic_OR_Meta-Analysis.Rmd
153 lines (115 loc) · 3.94 KB
/
Basic_OR_Meta-Analysis.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
---
title: "Basic Meta-Analysis for Odds Ratios/Relative Risk/Risk Ratio"
nocite: |
@*
output:
html_document:
code_folding: show
pdf_document: default
word_document: default
bibliography: R-Pckgs.bib
---
## Setup details
```{r}
## Specify the file containing your data
filename <- "dataOR.csv"
### Specify the columns containing the Study ID and count of events, non-events, and n for control and intervention within the file
col.int.event <- "Intervention.Event"
col.int.nonevent <- "Intervention.NonEvent"
col.int.n <- "Intervention.N"
col.cont.event <- "Control.Event"
col.cont.nonevent <- "Control.NonEvent"
col.cont.n <- "Control.N"
col.study.id <- "Study.ID"
### Specify the effect size measure
## Options in this template are OR (Odds Ratio), RD (Risk Difference), RR (log
## Relative Risk), AS (Arsine Square-root transformed risk difference), and PETO
## (log odds ratio using Peto's Method).
measure <- "OR"
## Metafor can support more diverse catagorical outcome data see help(escalc)
## for detail
### Specify the model type.
## In most cases REML should be the default
## Options in this template are
# method <- "FE" # Fixed effect meta-analysis
# method <- "REML" # Default random effects meta-analysis
# method <- "DL" # DerSimonian-Laird estimator
# method <- "HE" # Hedges estimator
# method <- "HS" # Hunter-Schmidt estimator
# method <- "SJ" # Sidik-Jonkman estimator
# method <- "ML" # maximum-likelihood estimator
# method <- "REML" # restricted maximum-likelihood estimator
# method <- "EB" # empirical Bayes estimator
# method <- "PM" # Paule-Mandel estimator
# method <- "GENQ" # generalized Q-statistic estimator
method <- "REML"
```
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(metafor)
library(DT)
library(knitr)
library(RCurl)
library(dplyr)
library(rmarkdown)
## These lines of code download and run the metafor_tidiers functions that implement broom type tidy data functions for rma objects
source("metafor_tidiers.R")
# Set so that long lines in R will be wrapped:
opts_chunk$set(tidy.opts = list(width.cutoff = 80), tidy = TRUE)
```
```{r read_data}
dat <- read.csv(filename, stringsAsFactors = FALSE)
```
## Caluclate effect sizes
```{r calculate_ES}
dat_ES <-
escalc(
measure = measure,
ai = get(col.int.event),
bi = get(col.int.nonevent),
n1i = get(col.int.n),
ci = get(col.cont.event),
di = get(col.cont.nonevent),
n2i = get(col.cont.n),
data = dat
)
```
```{r dat_es_html, echo = FALSE, warning = FALSE}
datatable(dat_ES %>%
select(-one_of(c("X", "Timestamp"))), rownames = FALSE) %>%
formatRound('yi', 3) %>%
formatRound('vi', 3)
```
## Run meta-analysis
```{r run_MA}
dat_MA <- rma(yi, vi, data = dat_ES, slab = get(col.study.id), method=method)
dat_MA
```
```{r convenience, echo=FALSE}
##These are some convenience functions that help put things into tables for easier interpretation.
model <- tidy.rma(dat_MA)
het.small <- glance.rma(dat_MA) %>%
select(one_of(c("k", "tau2", "se.tau2", "QE", "QEp", "I2")))
```
### Summary
`r ifelse(dat_MA$method=="FE", "A fixed effect meta-analysis", "A random-effects meta-analysis")` (k = `r dat_MA$k`) was conducted `r ifelse(dat_MA$method=="FE","",paste("using the", dat_MA$method, "estimator"))`.
```{r summary_table, echo=FALSE}
kable(model, col.names=c("*OR*", "se", "z", "*p*", "95% CI LB", "95% CI UB"), row.names=FALSE, digits = 3, caption="Effect Size")
```
```{r het_table, eval=dat_MA$method!="FE", echo=FALSE}
kable(het.small, col.names=c("k", "$\\tau$^2^", "se", "Q", "*p*", "I^2^"), digits = 3, caption="Heterogeneity")
```
## Plots
###Forest plot
```{r forest, warning = FALSE, fig.height = (het.small$k*0.5)}
forest(dat_MA)
```
###Funnel plot
```{r funnel}
funnel(dat_MA, back="white")
```
## Packages used in this document
```{r include=FALSE}
citPkgs <- names(sessionInfo()$otherPkgs)
write_bib(citPkgs, file="R-Pckgs.bib")
```