-
Notifications
You must be signed in to change notification settings - Fork 4
/
Lightweight Meta-Analysis.Rmd
119 lines (95 loc) · 2.96 KB
/
Lightweight 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
---
title: "Light Weight Meta-Analysis Example"
output:
word_document: default
pdf_document: default
html_document:
code_folding: show
always_allow_html: yes
csl: https://raw.githubusercontent.com/citation-style-language/styles/master/apa.csl
bibliography: R-Pckgs.bib
nocite: |
@*
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(metafor)
library(DT)
library(knitr)
library(RCurl)
library(dplyr)
library(rmarkdown)
library(kableExtra)
output <- default_output_format(knitr::current_input()) ## This will fail if run manually. Don't worry!
## 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("data_ostracism.csv")
```
## Caluclate effect sizes for standarised mean differences
```{r calculate_ES}
if (!"vi" %in% colnames(dat))
{
dat_ES <-
escalc(
measure = "SMD",
m1i = Intervention.Mean,
sd1i = Intervention.SD,
n1i = Intervention.N,
m2i = Control.Mean,
sd2i = Control.SD,
n2i = Control.N,
data = dat
)
} else {
dat_ES <- dat
attrs <- NULL
attrs$measure <- "SMD"
attrs$ni <- dat$Intervention.N + dat$Control.N
attributes(dat_ES$yi) <- attrs
}
```
```{r dat_es_html, eval = (output$name == "html_document"), echo = FALSE, warning = FALSE}
datatable(dat_ES %>%
select(-one_of(c("X", "Timestamp"))), rownames = FALSE) %>%
formatRound('yi', 3) %>%
formatRound('vi', 3)
```
```{r dat_es_pdf, eval = (output$name == "pdf_document"), echo = FALSE, warning = FALSE}
kable(dat_ES %>%
select(-one_of(c("X", "Timestamp"))), booktabs = T, format = "latex") %>%
kable_styling(latex_options = c("striped", "scale_down"))
```
```{r dat_es_word,eval = (output$name == "word_document"), echo = FALSE, warning = FALSE}
kable(dat_ES %>%
select(-one_of(c("X", "Timestamp"))))
```
## Run meta-analysis
```{r run_MA}
dat_MA <- rma(yi, vi, data = dat_ES, slab = Study.ID)
model <- tidy.rma(dat_MA)
het.small <- glance.rma(dat_MA) %>%
select(one_of(c("k", "tau2", "se.tau2", "QE", "QEp", "I2")))
eggers <- regtest(dat_MA)
```
### Summary
A random-effects meta-analysis (k = `r dat_MA$k`) was conducted using the `r dat_MA$method` estimator.
`r kable(model, col.names=c("*g*", "se", "z", "*p*", "95% CI LB", "95% CI UB"), row.names=FALSE, digits = 3, caption="Effect Size")`
`r 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")
```