Skip to content

Instantly share code, notes, and snippets.

@praveenkumarpgiindia
Forked from Lakens/Meta-Analysis in R
Created October 28, 2018 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save praveenkumarpgiindia/18f70cdc1c284ab6cca94e47e5b16cfb to your computer and use it in GitHub Desktop.
Save praveenkumarpgiindia/18f70cdc1c284ab6cca94e47e5b16cfb to your computer and use it in GitHub Desktop.
Perform a meta-analysis in R
#Script based on Carter & McCullough (2014) doi: 10.3389/fpsyg.2014.00823
#Load Libraries
library(meta)
library(metafor)
#Insert effect sizes and sample sizes
es.d<-c(0.38,0.41,-0.14,0.63,0.22)
n1<-c(75,48,22,18,60)
n2<-c(75,52,21,20,55)
#Calculate Variance ES
es.d.v <-(((n1+n2)/(n1*n2))+(es.d^2/(2*(n1+n2))))
#Calculate Standard Errors ES
d.se<-sqrt(es.d.v)
#Fixed-effect and Random-effects meta-analysis
#Once with meta package, once with metafor package
meta1<-metagen(es.d, d.se)
meta2<-rma(es.d, es.d.v)
#Show results from both packages
meta1
meta2
#Forest Plot
#If you add studies, make sure to match number of labels in studlab variable.
forest(meta1, studlab=c("Study1","Study2","Study3","Study4","Study5"), xlab="Cohen’s d", col.square="black",xlim=c(-3,3), col.diamond="black", fontsize=14, plotwidth=unit(12, "cm"), squaresize=0.5, leftcols=c("studlab"), rightcols=c("effect", "ci"), hetstat=FALSE, comb.fixed=FALSE, text.random="Overall ES", print.tau2=FALSE,print.I2=FALSE,TE.random=FALSE, seTE.random=FALSE)
#Outlier Analysis and Check for Influential Cases
influence(meta2)
plot(influence(meta2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment