Meat analysis using metacor() form the meta package

557 views
Skip to first unread message

Ayala Allon

unread,
Apr 12, 2017, 3:11:10 AM4/12/17
to Israel R User Group
Hi everyone,

I'm trying to do a meta analysis (random effects estimates with correlations) using the metaocr() from the meta package. I already did it using the Comprehensive Meta Analysis Software, but the free trial there is over and I want to be able to do this in R (I need to add more studies now, but first I wanna make sure I can replicate the analysis I already did using R). 

This is my data (also attached as a text file): 
1. The Experiment column is the label for each study.
2. The Corr column is the effect size column.
3. The N represents the number of cases in each study.

> cor
   Experiment       Corr  N
1 Experiment1 -0.3173759 16
2 Experiment2  0.2253440 16
3 Experiment3 -0.3209169 16
4 Experiment4 -0.7070982 16
5 Experiment5 -0.4100372 16
6 Experiment6 -0.5502341 16

I tried running metacor() with the following arguments. However, I get an error and I can't figure it out. I tried google it and everything but couldn't find anything:

> library(meta)
> testcor <- metacor(cor$Corr, cor$N, cor$Experiment,
+                    data=NULL, subset=NULL,
+                    sm=gs("ZCOR"),
+                    level=gs(0.95), level.comb=gs(0.95),
+                    comb.fixed=gs(FALSE), comb.random=gs(TRUE),
+                    hakn=gs("hakn"),
+                    method.tau=gs("method.tau"), tau.preset=NULL, TE.tau=NULL,
+                    tau.common=gs("tau.common"),
+                    prediction=gs(FALSE), level.predict=gs("level.predict"),
+                    null.effect=0,
+                    method.bias=gs("method.bias"),
+                    backtransf=gs("backtransf"),
+                    title=gs("title"), complab=gs("complab"), outclab="",
+                    byvar, bylab, print.byvar=gs("print.byvar"),
+                    byseparator = gs("byseparator"),
+                    keepdata=gs("keepdata")
+ )
Error in chkchar(x) : Argument 'x' must be a character string.


I'm also attaching the results of the meta analysis using the Comprehensive Meta Analysis Software.

Does anyone know why I get this error? Any help would be greatly appreciated.

Thanks,

Ayala 

correlation_meta_analysis.txt
BasicStats.pdf
MetaAnalysis.pdf
NextTable.pdf

Avraham N Kluger

unread,
Apr 13, 2017, 4:43:26 AM4/13/17
to Israel R User Group
Try this code:

r       <- c(-0.3173759, 0.2253440, -0.3209169, -0.7070982, -0.4100372, -0.5502341)
N       <- rep (16, 6)
Study   <- paste0("Experiment", 1:6)
x       <- as.data.frame(cbind (r, N, Study))
x

install.packages("meta")              #Run once for each computer, or when you want to update the package.
library(meta)                         #load the package for use, each time you start R, or after detaching it. 
metacor(r, N, Study)                  #Run function metacor from "meta" to meta analyze correlations.

fit <- metacor(r, N, Study)           #Run function metacor from "meta" to meta analyze correlations and 
                                      #insert output into an object named "fit". 
forest(fit)
funnel(fit)

Avraham N Kluger

unread,
Apr 13, 2017, 4:58:23 AM4/13/17
to Israel R User Group

Meta analysis

Avi Kluger

April 13, 2017

Ayala’s data with forest and funnel plots

In this example, I fixed the issue of the data frame, so you have an example that will also work when you read the data from your text file.

######The code below just replicate your data #######################################

r       <- c(-0.3173759, 0.2253440, -0.3209169, -0.7070982, -0.4100372, -0.5502341)
N       <- rep (16, 6)
x       <- as.data.frame(cbind (r, N))
x$Study <- paste0("Experiment", 1:6)
x
##            r  N       Study
## 1 -0.3173759 16 Experiment1
## 2  0.2253440 16 Experiment2
## 3 -0.3209169 16 Experiment3
## 4 -0.7070982 16 Experiment4
## 5 -0.4100372 16 Experiment5
## 6 -0.5502341 16 Experiment6
#install.packages("meta")              #Run once for each computer, or when you want to update the package.

library(meta)                         #load the package for use, each time you start R, or after detaching it. 
## Loading 'meta' package (version 4.8-1).
## Type 'help("meta-package")' for a brief overview.
metacor(r, N, Study, data = x)        #Run function metacor from "meta" to meta analyze correlations.
##                 COR             95%-CI %W(fixed) %W(random)
## Experiment1 -0.3174 [-0.7026;  0.2116]      16.7       16.7
## Experiment2  0.2253 [-0.3044;  0.6486]      16.7       16.7
## Experiment3 -0.3209 [-0.7045;  0.2079]      16.7       16.7
## Experiment4 -0.7071 [-0.8906; -0.3255]      16.7       16.7
## Experiment5 -0.4100 [-0.7527;  0.1075]      16.7       16.7
## Experiment6 -0.5502 [-0.8218; -0.0750]      16.7       16.7
## 
## Number of studies combined: k = 6
## 
##                          COR             95%-CI     z  p-value
## Fixed effect model   -0.3754 [-0.5487; -0.1710] -3.49   0.0005
## Random effects model -0.3754 [-0.5987; -0.0979] -2.61   0.0091
## 
## Quantifying heterogeneity:
##  tau^2 = 0.0603; H = 1.34 [1.00; 2.12]; I^2 = 44.0% [0.0%; 77.8%]
## 
## Test of heterogeneity:
##     Q d.f.  p-value
##  8.92    5   0.1122
## 
## Details on meta-analytical method:
## - Inverse variance method
## - DerSimonian-Laird estimator for tau^2
## - Fisher's z transformation of correlations
fit <- metacor(r, N, Study, data = x) #Run function metacor from "meta" to meta analyze correlations and 

                                      #insert output into an object named "fit". 
forest(fit)

funnel(fit)


On Wednesday, April 12, 2017 at 10:11:10 AM UTC+3, Ayala Allon wrote:
Auto Generated Inline Image 1
Auto Generated Inline Image 2

Ayala Allon

unread,
Apr 13, 2017, 6:03:11 AM4/13/17
to Israel R User Group
Hi Avi,

Wow, many tnx!!! After I saw what you did I tried running the metacor() with the following arguments and it worked. I got exactly what you got.
testcor <- metacor(cor$Corr, cor$N, cor$Experiment)

I wonder why I got the error yesterday when trying to specify some of the other arguments. 

As for generating the forest plot I used the forestplot package (see below). I will definitely check out the forest plot meta offers

library(forestplot)

cochrane_from_rmeta <- 
  structure(list(
    mean  = c(NA, cor$Corr, -.375354256640877, NA), 
    lower = c(NA, -0.702552236, -0.304359568, -0.704543333, -0.890627584, -0.752741977, -0.821792317, -0.598671803696715, -1),
    upper = c(NA, 0.211623028, 0.648598183, 0.207853851, -0.325476408, 0.107523011, -0.0749798348470502, -0.097892973605829, 1)),
    .Names = c("mean", "lower", "upper"), 
    row.names = c(NA, -9L), 
    class = "data.frame")

tabletext <- cbind(c("Experiment", paste("Experiment", 1:6), "Meta Analysis",""))
forestplot(tabletext, 
           cochrane_from_rmeta,new_page = TRUE,
           is.summary=c(TRUE, rep(FALSE, 6), TRUE, FALSE),
           clip = c(-1.0, 1.0), 
           xlog = FALSE, 
           col = fpColors(box = "black", line = "black", summary="black"),
           hrzl_lines = gpar(col="black"),
           txt_gp = fpTxtGp(cex = 1.25, ticks = gpar(cex = 1, fontface = "bold"), 
           xlab  = gpar(cex = 1.25)),
           xticks = c(-1.0, -0.5, 0, 0.5, 1),
           xticks.digits = 2, 
           grid = TRUE, title = "Correlation and 95% CI", 
           xlab = "\nMeta Analysis: r = -0.375 (95% CI: -0.599 - -0.098), Z = -2.609, p = 0.009")
          


Thank you very much again for the help! After replicating the analysis in R I'm ready to add more studies to the analysis :)

Best,
Ayala
Reply all
Reply to author
Forward
0 new messages