forked from MathiasHarrer/Doing-Meta-Analysis-in-R
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04-forest_plots.Rmd
More file actions
264 lines (197 loc) · 7.29 KB
/
Copy path04-forest_plots.Rmd
File metadata and controls
264 lines (197 loc) · 7.29 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# Forest Plots

<<<<<<< HEAD
Now that we created the **output of our meta-analysis** using the `metagen`, `metacont` or `metabin` functions in `meta` (see [Chapter 4.1](#fixed),[Chapter 4.2](#random) and [Chapter 4.3](#binary)), it is time to present the data in a more digestable way. **Forest Plots** are an easy way to do this, and it is conventional to report forest plots in meta-analysis publications.
=======
```{block,type='rmdinfo'}
Now that we created the **output of our meta-analysis** using the `metagen`, `metacont` or `metabin` functions in `meta` (see [Chapter 4.1](#fixed),[Chapter 4.2](#random) and [Chapter 4.3](#binary)), it is time to present the data in a more digestable way.
**Forest Plots** are an easy way to do this, and it is conventional to report forest plots in meta-analysis publications.
```
<br><br>
---
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
## Generating a Forest Plot
To produce a forest plot, we use the meta-analysis output we just created (e.g., `m`, `m.raw`) und the `meta::forest()` function. I'll use my `m.hksj.raw` output from [Chapter 4.2.3](#random.raw) to create the forest plot
<<<<<<< HEAD
$~$
=======
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
```{r,echo=FALSE,warning=FALSE,message=FALSE}
load("metacont_data.RData")
metacont$Ne<-as.numeric(metacont$Ne)
metacont$Me<-as.numeric(metacont$Me)
metacont$Se<-as.numeric(metacont$Se)
metacont$Mc<-as.numeric(metacont$Mc)
metacont$Sc<-as.numeric(metacont$Sc)
library(meta)
library(metafor)
m.hksj.raw<-metacont(Ne,
Me,
Se,
Nc,
Mc,
Sc,
data=metacont,
studlab=paste(Author),
comb.fixed = FALSE,
comb.random = TRUE,
method.tau = "SJ",
hakn = TRUE,
prediction=TRUE,
sm="SMD")
metacont$intervention.type<-c("PCI","PCI","Mindfulness","CBT","CBT","CBT")
```
<<<<<<< HEAD
```{r,fig.width=11,fig.height=3,fig.align='center'}
forest(m.hksj.raw)
```
$~$
Looks good so far. We see that the function plotted a forest plot with a **diamond** (i.e. the overall effect and its confidence interval) and a **prediction interval**. There are plenty of **other parameters** within the `meta::forest` function which we can use to modify the forest plot.
=======
```{r,fig.width=11,fig.height=4,fig.align='center'}
forest(m.hksj.raw)
```
Looks good so far. We see that the function plotted a forest plot with a **diamond** (i.e. the overall effect and its confidence interval) and a **prediction interval**.
There are plenty of **other parameters** within the `meta::forest` function which we can use to modify the forest plot.
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
```{r,echo=FALSE}
library(knitr)
library(grid)
load("foresttable.RData")
<<<<<<< HEAD
foresttable1<-foresttable[1:23,]
kable(foresttable1) %>%
column_spec(3, width = "30em")
```
```{r,echo=FALSE}
library(knitr)
library(grid)
load("foresttable.RData")
foresttable2<-foresttable[24:48,]
kable(foresttable2) %>%
column_spec(3, width = "30em")
```
```{r,echo=FALSE}
library(knitr)
library(grid)
load("foresttable.RData")
foresttable3<-foresttable[49:52,]
kable(foresttable3) %>%
column_spec(3, width = "35em")
```
This is again just an overview. For all settings, type `?meta::forest` in your **console** to see more.Let's play around with the function a little now:
$~$
=======
kable(foresttable)
```
This is again just an overview. For all settings, type `?meta::forest` in your **console** to see more.
Let's play around with the function a little now:
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
```{r,fig.width=9,fig.height=3.5,fig.align='center'}
forest(m.hksj.raw,
sortvar=TE,
xlim = c(-1.5,0.5),
rightlabs = c("g","95% CI","weight"),
leftlabs = c("Author", "N","Mean","SD","N","Mean","SD"),
lab.e = "Intervention",
pooled.totals = FALSE,
smlab = "",
text.random = "Overall effect",
print.tau2 = FALSE,
col.diamond = "blue",
col.diamond.lines = "black",
col.predict = "black",
print.I2.ci = TRUE,
digits.sd = 2
)
```
<<<<<<< HEAD
$~$
Looks good so far! For special **layout types**, proceed to [Chapter 5.2](#layouttypes) now.
=======
Looks good so far! For special **layout types**, proceed to [Chapter 5.2](#layouttypes) now.
<br><br>
---
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
## Layout types {#layouttypes}
The `meta::forest` function also has two **Layouts** preinstalled which we can use. Those layouts can be accessed with the `layout=` parameter.
* **"RevMan5"**. This layout is used for Cochrane reviews and generated by *Review Manager 5*.
* **"JAMA"**. This layout gives you a forest plot according to the guidelines of the *Journal of the American Medical Association* as output (see details [here](https://jamanetwork.com/journals/jama/pages/instructions-for-authors)).
The **RevMan** layout looks like this:
<<<<<<< HEAD
$~$
=======
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
```{r,fig.width=10,fig.height=4,fig.align='center'}
forest(m.hksj.raw,
layout = "RevMan5",
digits.sd = 2)
```
<<<<<<< HEAD
$~$
=======
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
The **JAMA** layout looks like this:
```{r,fig.width=7,fig.height=3,fig.align='center'}
forest(m.hksj.raw,
layout = "JAMA",
text.predict = "95% PI",
col.predict = "black",
colgap.forest.left = unit(15,"mm"))
```
<<<<<<< HEAD
## Saving the forest plots
Let's say i want to save the JAMA version of my Forest Plot now. To do this, i have to reuse the code with which i plotted my forest plot, and put it between `pdf(file='name_of_the_pdf_i_want_to_create.pdf')` and `dev.off`, both in separate lines. This saves the plot into a PDF in my Working Directory. This way, i can export the plot in different formats (you can find more details on the saving options [here](#saving)).
<br></br>
$~$
=======
<br><br>
---
## Saving the forest plots
Let's say i want to save the JAMA version of my Forest Plot now. To do this, i have to reuse the code with which i plotted my forest plot, and put it between `pdf(file='name_of_the_pdf_i_want_to_create.pdf')` and `dev.off`, both in separate lines. This saves the plot into a PDF in my Working Directory.
This way, i can export the plot in different formats (you can find more details on the saving options [here](#saving)).
<br></br>
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
**PDF**
```{r, eval=FALSE}
pdf(file='forestplot.pdf')
forest.jama<-forest(m.hksj.raw,
layout = "JAMA",
text.predict = "95% PI",
col.predict = "black",
colgap.forest.left = unit(15,"mm"))
dev.off()
```
<<<<<<< HEAD
$~$
=======
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
**PNG**
```{r, eval=FALSE}
png(file='forestplot.png')
forest.jama<-forest(m.hksj.raw,
layout = "JAMA",
text.predict = "95% PI",
col.predict = "black",
colgap.forest.left = unit(15,"mm"))
dev.off()
```
<<<<<<< HEAD
$~$
=======
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
**Scalable Vector Graphic**
```{r, eval=FALSE}
svg(file='forestplot.svg')
forest.jama<-forest(m.hksj.raw,
layout = "JAMA",
text.predict = "95% PI",
col.predict = "black",
colgap.forest.left = unit(15,"mm"))
dev.off()
```
<<<<<<< HEAD
=======
<br><br>
---
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876