-
Notifications
You must be signed in to change notification settings - Fork 4
/
Basic_SMD_Meta-Analysis.Rmd
149 lines (112 loc) · 3.75 KB
/
Basic_SMD_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
---
title: "Basic Meta-Analysis for (Standarised) Mean Differences"
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 <- "data.csv"
### Specify the columns containing the Study ID and means, SDs, and Ns for intervention and control within the file
col.int.means <- "Intervention.Means"
col.int.sds <- "Intervention.SD"
col.int.ns <- "Intervention.N"
col.cont.means <- "Control.Means"
col.cont.sds <- "Control.SD"
col.cont.ns <- "Control.N"
col.study.id <- "Study.ID"
### Specify the effect size measure
## Options in this template are SMD (standarised mean differences) and MD (raw mean differences).
## In most cases SMD is most appropriate.
measure <- "SMD"
### 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,
m1i = get(col.int.means),
sd1i = get(col.int.sds),
n1i = get(col.int.ns),
m2i = get(col.cont.means),
sd2i = get(col.cont.sds),
n2i = get(col.cont.ns),
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("*g*", "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")
```