forked from MathiasHarrer/Doing-Meta-Analysis-in-R
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path04-forest_plots.Rmd
84 lines (54 loc) · 3.11 KB
/
04-forest_plots.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
# Forest Plots
![](forest.jpg)
```{block,type='rmdinfo'}
Now that we created the **output of our meta-analysis** using the `rma` function in `metafor` (see [Chapter 5.1](#fixedef), and [Chapter 5.2](#random)), 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>
---
## Generating a Forest Plot
To produce a forest plot, we use the meta-analysis output we just created (e.g., `m`, `m_re`) and apply the `rma::forest()` function.
```{r,echo=FALSE,warning=FALSE,message=FALSE}
library(metaforest)
df <- curry
m <- rma(yi = df$d, # The d-column of the df, which contains Cohen's d
vi = df$vi, # The vi-column of the df, which contains the variances
method = "FE") # Run a fixed-effect model
m_re <- rma(yi = df$d, # The d-column of the df, which contains Cohen's d
vi = df$vi)
```
```{r,fig.width=11,fig.height=11,fig.align='center'}
forest(m_re, slab = df$study_id)
```
### Prediction interval
**Prediction intervals** give us a range for which we can **expect the effects of future studies to fall** based on **our present evidence in the meta-analysis**. They take the between-study variance into account. If our prediction interval, for example, lies completely on the positive side favoring the intervention, we can be quite confident to say that **despite varying effects, the intervention might be at least in some way beneficial in all contexts we studied in the future**. If the confidence interval includes **zero**, we can be less sure about this, although it should be noted that **broad prediction intervals are quite common, especially in medicine and psychology**. We can simply add a prediction interval to the forest plot:
```{r,fig.width=11,fig.height=11,fig.align='center'}
forest(m_re, slab = df$study_id, addcred = TRUE)
```
<br><br>
---
## Saving the forest plot
Let's say I want to save the Forest Plot now. The easiest way to do this is to plot it to a **graphics device** instead of to the screen. Just like the function `sink()` redirected text output from the console tab to a text file, there are functions that redirect images from the plot tab to a file.
One of these functions is `pdf()`, which opens the PDF **graphics device**. You can then plot your image, it will be sent to the PDF, and then close the device again. This saves the plot into a PDF to the Working Directory.
This way, you can export the plot in different formats (you can find more details on the saving options [here](#saving)).
<br></br>
**PDF**
```{r, eval=FALSE}
pdf(file='forestplot.pdf') # Open PDF device with specific file name
forest(m_re, slab = df$study_id) # Plot the forest
dev.off() # Turn the PDF device off
```
**PNG**
```{r, eval=FALSE}
png(file='forestplot.png') # Open PNG device with specific file name
forest(m_re, slab = df$study_id) # Plot the forest
dev.off()
```
**Scalable Vector Graphic**
```{r, eval=FALSE}
svg(file='forestplot.svg') # Open SVG device with specific file name
forest(m_re, slab = df$study_id) # Plot the forest
dev.off()
```
<br><br>
---