Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…Analysis-in-R

# Conflicts:
#	.DS_Store
#	01-rstudio_and_basics.Rmd
#	02-getting_data_in_R.Rmd
#	03-pooling_effect_sizes.Rmd
#	04-forest_plots.Rmd
#	06-Subgroup_Analyses.Rmd
#	07-metaregression.Rmd
#	08-publication_bias.Rmd
#	09-risk_of_bias_summary.Rmd
#	10-Effectsizeconverter.Rmd
#	10-network_metanalysis.Rmd
#	11-Effectsizeconverter.Rmd
#	11-power_analysis.Rmd
#	12-Effectsizeconverter.Rmd
#	12-power_analysis.Rmd
#	13-power_analysis.Rmd
#	14-references.Rmd
#	Doing_Meta_Analysis_in_R.log
#	Doing_Meta_Analysis_in_R.pdf
#	Doing_Meta_Analysis_in_R.tex
#	book.bib
#	index.Rmd
#	packages.bib
  • Loading branch information
MathiasHarrer committed Jan 3, 2019
2 parents e8a921c + f3259ea commit 9f1be42
Show file tree
Hide file tree
Showing 28 changed files with 9,807 additions and 1 deletion.
11 changes: 10 additions & 1 deletion 01-rstudio_and_basics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ Before we start with our meta-analysis, we have to download and prepare a **comp


## Getting RStudio to run on your computer {#RStudio}

<<<<<<< HEAD

=======
```{r, echo=FALSE, fig.width=3,fig.height=2}
library(png)
library(grid)
img <- readPNG("rstudiologo.PNG")
grid.raster(img)
```
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
As a prerequisite for this guide, you need to have **RStudio** and a few essential **R packages** installed.

Expand Down
155 changes: 155 additions & 0 deletions 02-getting_data_in_R.Rmd

Large diffs are not rendered by default.

255 changes: 255 additions & 0 deletions 03-pooling_effect_sizes.Rmd

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions 04-forest_plots.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,33 @@

![](forest.jpg)

<<<<<<< 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)
Expand All @@ -40,18 +55,29 @@ m.hksj.raw<-metacont(Ne,
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")
Expand All @@ -78,6 +104,14 @@ kable(foresttable3) %>%
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,
Expand All @@ -99,11 +133,19 @@ forest(m.hksj.raw,
```

<<<<<<< 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}
Expand All @@ -115,17 +157,23 @@ The `meta::forest` function also has two **Layouts** preinstalled which we can u

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'}
Expand All @@ -136,6 +184,7 @@ forest(m.hksj.raw,
colgap.forest.left = unit(15,"mm"))
```

<<<<<<< HEAD

## Saving the forest plots

Expand All @@ -144,6 +193,19 @@ Let's say i want to save the JAMA version of my Forest Plot now. To do this, i h
<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**

Expand All @@ -157,8 +219,11 @@ forest.jama<-forest(m.hksj.raw,
dev.off()
```

<<<<<<< HEAD
$~$

=======
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
**PNG**

```{r, eval=FALSE}
Expand All @@ -171,8 +236,11 @@ forest.jama<-forest(m.hksj.raw,
dev.off()
```

<<<<<<< HEAD
$~$

=======
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
**Scalable Vector Graphic**

```{r, eval=FALSE}
Expand All @@ -186,5 +254,11 @@ dev.off()
```


<<<<<<< HEAD
=======
<br><br>

---
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876

85 changes: 85 additions & 0 deletions 06-Subgroup_Analyses.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,30 @@

![](subgroup.jpg)

<<<<<<< HEAD
In [Chapter 6](#heterogeneity), we discussed in depth why **between-study heterogeneity** is such an important issue in interpreting the results of our meta-analysis, and how we can **explore sources of heterogeneity** using [outlier](#outliers) and [influence analyses](#influenceanalyses). Another source of between-study heterogeneity making our effect size estimate less precise could be that **there are slight differences in the study design or intervention components between the studies**. For example, in a meta-analysis on the effects of **cognitive behavioral therapy** (CBT) for **depression** in **university students**, it could be the case that some studies delivered the intervention in a **group setting**, while others delivered the therapy to each student **individually**. In the same example, it is also possible that studies used different **criteria** to determine if a student suffers from **depression** (e.g. they either used the *ICD-10* or the *DSM-5* diagnostic manual). Many other differences of this sort are possible, and it seems plausible that such study differences may also be associated with differences in the overall effect.In **subgroup analyses**, we therefore have a look at different **subgroups within the studies of our meta-analysis** and try to determine of the **differ between these subgroups**.

$~$

=======
In [Chapter 6](#heterogeneity), we discussed in depth why **between-study heterogeneity** is such an important issue in interpreting the results of our meta-analysis, and how we can **explore sources of heterogeneity** using [outlier](#outliers) and [influence analyses](#influenceanalyses).

Another source of between-study heterogeneity making our effect size estimate less precise could be that **there are slight differences in the study design or intervention components between the studies**. For example, in a meta-analysis on the effects of **cognitive behavioral therapy** (CBT) for **depression** in **university students**, it could be the case that some studies delivered the intervention in a **group setting**, while others delivered the therapy to each student **individually**. In the same example, it is also possible that studies used different **criteria** to determine if a student suffers from **depression** (e.g. they either used the *ICD-10* or the *DSM-5* diagnostic manual).

Many other differences of this sort are possible, and it seems plausible that such study differences may also be associated with differences in the overall effect.

In **subgroup analyses**, we therefore have a look at different **subgroups within the studies of our meta-analysis** and try to determine of the **differ between these subgroups**.

```{block,type='rmdinfo'}
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
**The idea behind subgroup analyses**
Basically, a every subgroup analysis consists of **two parts**: (1) **pooling the effect of each subgroup**, and (2) **comparing the effects of the subgroups** [@borenstein2013meta].
<<<<<<< HEAD
$~$
=======
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
**1. Pooling the effect of each subgroup**
Expand All @@ -19,8 +34,11 @@ This point it rather straightforward, as the same criteria as the ones for a **s
* If you assume that **all studies in subgroup** stem from the same population, and all have **one shared true effect**, you may use the **fixed-effect-model**. As we mention in [Chapter 4](#pool), many **doubt** that this assumption is ever **true in psychological** and **medical research**, even when we partition our studies into subgroups.
* The alternative, therefore, is to use a **random-effect-model** which assumes that the studies within a subgroup are drawn from a **universe** of populations follwing its own distribution, for which we want to estimate the **mean**.
<<<<<<< HEAD
$~$
=======
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
**2. Comparing the effects of the subgroups**
After we calculated the pooled effect for each subgroup, **we can compare the size of the effects of each subgroup**. However, to know if this difference is in fact singnificant and/or meaningful, we have to calculate the **Standard Error of the differences between subgroup effect sizes** $SE_{diff}$, to calculate **confidence intervals** and conduct **significance tests**.
Expand All @@ -40,8 +58,24 @@ The (simplified) formula for the estimation of $V_{Diff}$ using this model there
$$V_{Diff}=V_A + V_B + \frac{\hat T^2_G}{m} $$
<<<<<<< HEAD
Where $\hat T^2_G$ is the **estimated variance between the subgroups**, and $m$ is the **number of subgroups**. Be aware that subgroup analyses should **always be based on an informed, *a priori* decision** which subgroup differences within the study might be **practically relevant**, and would lead to information gain on relevant **research questions** in your field of research. It is also **good practice** to specify your subgroup analyses **before you do the analysis**, and list them in **the registration of your analysis**. It is also important to keep in mind that **the capabilites of subgroup analyses to detect meaningful differences between studies is often limited**. Subgroup analyses also need **sufficient power**, so it makes no sense to compare two or more subgroups when your entire number of studies in the meta-analysis is smaller than $k=10$ [@higgins2004controlling].
=======
Where $\hat T^2_G$ is the **estimated variance between the subgroups**, and $m$ is the **number of subgroups**.
```

```{block,type='rmdachtung'}
Be aware that subgroup analyses should **always be based on an informed, *a priori* decision** which subgroup differences within the study might be **practically relevant**, and would lead to information gain on relevant **research questions** in your field of research. It is also **good practice** to specify your subgroup analyses **before you do the analysis**, and list them in **the registration of your analysis**.
It is also important to keep in mind that **the capabilites of subgroup analyses to detect meaningful differences between studies is often limited**. Subgroup analyses also need **sufficient power**, so it makes no sense to compare two or more subgroups when your entire number of studies in the meta-analysis is smaller than $k=10$ [@higgins2004controlling].
```

<br><br>

---
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876

## Subgroup Analyses using the Mixed-Effects-Model {#mixed}
Expand Down Expand Up @@ -298,13 +332,22 @@ Description<-c("The output of you meta-analysis. In my case, this is 'm.hksj'",
m<-data.frame(Code,Description)
names<-c("Code","Description")
colnames(m)<-names
<<<<<<< HEAD
kable(m) %>%
column_spec(2, width = "40em")
```

In my `madata` dataset, which i used previously to generate my meta-analysis output `m.hksj`, i stored the subgroup variable `Control`. This variable specifies **which control group type was employed in which study**. There are **three subgroups**: `WLC` (waitlist control), `no intervention` and `information only`. The function to do a subgroup analysis using the mixed-effects-model with these paramters looks like this.

$~$
=======
kable(m)
```
In my `madata` dataset, which i used previously to generate my meta-analysis output `m.hksj`, i stored the subgroup variable `Control`. This variable specifies **which control group type was employed in which study**. There are **three subgroups**: `WLC` (waitlist control), `no intervention` and `information only`.
The function to do a subgroup analysis using the mixed-effects-model with these paramters looks like this.
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
```{r,message=FALSE,warning=FALSE}
subgroup.analysis.mixed.effects(data=m.hksj,
Expand All @@ -315,11 +358,21 @@ subgroup.analysis.mixed.effects(data=m.hksj,
subgroup3 = "information only")
```

<<<<<<< HEAD
$~$

The results of the subgroup analysis are displayed under `Results for subgroups (fixed effect model)`. We see that, while the **pooled effects of the subgroups differ quite substantially** (*g* = 0.41-0.78), this difference is **not statistically significant**. This can be seen under `Test for subgroup differences` in the `Between groups` row. We can see that $Q=3.03$ and $p=0.2196$. This information can be reported in our meta-analysis paper. Please note that the values displayed under `k` in the `Results for subgroups (fixed effects model)` section are always 1, as the pooled effect of the subgroup is treated as a single study. To determine the actual $k$ of each subgroup, you can use the `count` function from `dplyr` in R.


=======
The results of the subgroup analysis are displayed under `Results for subgroups (fixed effect model)`. We see that, while the **pooled effects of the subgroups differ quite substantially** (*g* = 0.41-0.78), this difference is **not statistically significant**.

This can be seen under `Test for subgroup differences` in the `Between groups` row. We can see that $Q=3.03$ and $p=0.2196$. This information can be reported in our meta-analysis paper.

```{block,type='rmdachtung'}
Please not that the values displayed under `k` in the `Results for subgroups (fixed effects model)` section are always 1, as the pooled effect of the subgroup is treated as a single study. To determine the actual $k$ of each subgroup, you can use the `count` function from `dplyr` in R.
```
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
```{r,echo=FALSE}
load("Meta_Analysis_Data.RData")
Expand All @@ -332,6 +385,12 @@ library(dplyr)
dplyr::count(madata, vars=madata$Control)
```

<<<<<<< HEAD
=======
<br><br>

---
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
## Subgroup Analyses using the Random-Effects-Model

Expand All @@ -340,9 +399,15 @@ region<-c("Netherlands","Netherlands","Netherlands","USA","USA","USA","USA","Arg
madata$region<-region
```

<<<<<<< HEAD
Now, let's assume i want to **know if intervention effects in my meta-analysis differ by region**. I use a **random-effects-model** and the selected coutries Argentina, Australia, China, and the Netherlands.Again, i use the `m.hksj` meta-analysis output object. I can perform a random-effects-model for between-subgroup-differences using the `update.meta` function. For this function, we have to **set two parameters**.

$~$
=======
Now, let's assume i want to **know if intervention effects in my meta-analysis differ by region**. I use a **random-effects-model** and the selected coutries Argentina, Australia, China, and the Netherlands.

Again, i use the `m.hksj` meta-analysis output object. I can perform a random-effects-model for between-subgroup-differences using the `update.meta` function. For this function, we have to **set two parameters**.
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
```{r,echo=FALSE}
library(knitr)
Expand All @@ -351,11 +416,17 @@ Description<-c("Here, we specify the variable in which the subgroup of each stud
m<-data.frame(Code,Description)
names<-c("Code","Description")
colnames(m)<-names
<<<<<<< HEAD
kable(m) %>%
column_spec(2, width = "40em")
```

$~$
=======
kable(m)
```
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876
```{r,echo=FALSE}
m.hksj<-metagen(TE, seTE, data=madata, method.tau = "SJ", hakn = TRUE, studlab = paste(Author), comb.random = TRUE)
Expand All @@ -369,6 +440,7 @@ region.subgroup<-update.meta(m.hksj,
region.subgroup
```

<<<<<<< HEAD
$~$

Here, we get the **pooled effect for each subgroup** (country). Under `Test for subgroup differences (random effects model)`, we can see the **test for subgroup differences using the random-effects-model**, which is **not significant** ($Q=4.52$,$p=0.3405$). This means that we did not find differences in the overall effect between different regions, represented by the country in which the study was conducted.
Expand All @@ -380,5 +452,18 @@ $~$
To use a fixed-effect-model in combination with a fixed-effects-model, we can also use the `update.meta` function again. The procedure is the same as the one we described before, but we have to set `comb.random` as `FALSE` and `comb.fixed` as `TRUE`.


=======
Here, we get the **pooled effect for each subgroup** (country). Under `Test for subgroup differences (random effects model)`, we can see the **test for subgroup differences using the random-effects-model**, which is **not significant** ($Q=4.52$,$p=0.3405$). This means that we did not find differences in the overall effect between different regions, represented by the country in which the study was conducted.

```{block,type='rmdachtung'}
**Using a fixed-effect-model for within-subgroup-pooling and a fixed-effects-model for between-subgroup-differences**
To use a fixed-effect-model in combination with a fixed-effects-model, we can also use the `update.meta` function again. The procedure is the same as the one we described before, but we have to set `comb.random` as `FALSE` and `comb.fixed` as `TRUE`.
```

<br><br>

---
>>>>>>> f3259eafbebf95ffc6044d4af3f61e06d59c7876

Loading

0 comments on commit 9f1be42

Please sign in to comment.