Skip to content

Instantly share code, notes, and snippets.

Wolfgang Viechtbauer wviechtb

Block or report user

Report or block wviechtb

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@wviechtb
wviechtb / Multivariate meta-analysis
Created Jul 6, 2018
Some literature on multivariate meta-analysis and other methods to account for dependency in multiple estimates
View Multivariate meta-analysis
Kalaian, H. A., & Raudenbush, S. W. (1996). A multivariate mixed linear model for meta-analysis. Psychological Methods, 1(3), 227-235.
Berkey, C. S., Hoaglin, D. C., Antczak-Bouckoms, A., Mosteller, F., & Colditz, G. A. (1998). Meta-analysis of multiple outcomes by regression with random effects. Statistics in Medicine, 17(22), 2537-2550.
van Houwelingen, H. C., Arends, L. R., & Stijnen, T. (2002). Advanced methods in meta-analysis: Multivariate approach and meta-regression. Statistics in Medicine, 21(4), 589-624.
Nam, I.-S., Mengersen, K., & Garthwaite, P. (2003). Multivariate meta-analysis. Statistics in Medicine, 22(14), 2309-2333.
Hedges, L. V., Tipton, E., & Johnson, M. C. (2010). Robust variance estimation in meta-regression with dependent effect size estimates. Research Synthesis Methods, 1(1), 39-65.
@wviechtb
wviechtb / gist:e87ee35ea5544a3a5f875f61e270cd18
Created Jun 2, 2018
Show density of product-moment correlation as a function of sample size
View gist:e87ee35ea5544a3a5f875f61e270cd18
devtools::install_github("wviechtb/metafor")
library(metafor)
rs <- seq(-1,1,length=1001)
ns <- c(seq(10, 100, 10), 150, 200, 300)
ys <- lapply(ns, function(n) metafor:::.dcor(rs, n, rho=0))
plot(NA, xlim=range(rs), ylim=range(ys), xlab="Correlation", ylab="Density")
invisible(lapply(ys, function(y) lines(rs, y)))
@wviechtb
wviechtb / rmat.r
Last active Aug 15, 2018
Function to compute var-cov matrix of correlations (raw or r-to-z transformed)
View rmat.r
rmat <- function(x, n, upper=TRUE, simplify=TRUE, rtoz=FALSE, data) {
if (class(x) == "formula") {
options(na.action = "na.pass")
if (missing(data))
stop("Must specify 'data' argument when 'x' is a formula.")
if (!is.data.frame(data))
@wviechtb
wviechtb / fe_coverage_fixed_theta
Created Jul 5, 2017
Show that FE model has nominal coverage for conditional inferences (fixed theta scenario).
View fe_coverage_fixed_theta
rm(list=ls())
library(metafor)
iters <- 1000
### number of studies/effects
k <- 10
### SD of the true effects
@wviechtb
wviechtb / fe_coverage.r
Last active Jul 5, 2017
Show that FE model has nominal coverage for conditional inferences.
View fe_coverage.r
rm(list=ls())
library(metafor)
iters <- 1000
### number of studies/effects
k <- 10
### SD of the true effects
@wviechtb
wviechtb / bivariate_normal_wallpaper.r
Last active Sep 2, 2018
Code to generate wallpaper (bivariate normal distribution)
View bivariate_normal_wallpaper.r
library(mvtnorm)
### correlation for the bivariate normal distribution
rho <- 0.4
### number of points for x and y at which to evaluate the density of the bivariate normal distribution
n <- 501
sigma <- matrix(c(1,rho,rho,1), nrow=2)
@wviechtb
wviechtb / ll.r
Created Apr 4, 2017
Function to compute the ML/REML log-likelihood for a standard random-effects model.
View ll.r
ll <- function(mu, tau2, yi, vi, method="ML") {
k <- length(yi)
wi <- 1/(vi + tau2)
if (method == "ML") {
sum(dnorm(yi, mean=mu, sqrt(vi + tau2), log=TRUE))
} else {
-1/2 * (k-1) * log(2*pi) + 1/2 * log(k) - 1/2 * sum(log(vi + tau2)) - 1/2 * log(sum(wi)) - 1/2 * sum(wi * (yi - mu)^2)
}
}
@wviechtb
wviechtb / fun.r
Last active Aug 10, 2016
Function that either takes a variable from the data argument or from the parent frame.
View fun.r
fun <- function(x, data) {
if (missing(data))
data <- NULL
if (is.null(data))
data <- sys.frame(sys.parent())
mf <- match.call()
mf.x <- mf[[match("x", names(mf))]]
x <- eval(mf.x, data, enclos=sys.frame(sys.parent()))
temp <- x^2 + 5
return(temp)
You can’t perform that action at this time.