Skip to content

Instantly share code, notes, and snippets.

View wviechtb's full-sized avatar

Wolfgang Viechtbauer wviechtb

View GitHub Profile
@wviechtb
wviechtb / rcode_rma_mv_example.r
Last active March 8, 2024 18:45
Model Selection using the glmulti and MuMIn Packages with a rma.mv() Model
############################################################################
library(metafor)
library(ape)
############################################################################
# read the documentation for this dataset
help(dat.moura2021)
@wviechtb
wviechtb / install_packages.r
Last active January 23, 2024 09:56
Code to install packages needed during the 'Introduction to R' course.
############################################################################
# During the course, we will make use of a number of add-on packages for R.
# Ideally, you should install these packages before the course (then you don't
# have to bother with installing packages during the course). The code below
# can be used to install each of the packages one by one. So, just run each
# command below (e.g., by copy-pasting it into R) line by line.
# If you are asked to create a 'personal library', choose 'yes'. If you are
# asked to choose a 'CRAN mirror', just select the default one (which is
@wviechtb
wviechtb / diamond_plot.r
Created September 26, 2023 10:01
Diamond plot with metafor::forest() and metafor::addpoly()
# inspired by: https://github.com/mjskay/uncertainty-examples/blob/master/diamond_plot.md
# to see if we can abuse metafor::forest() and metafor::addpoly() to create such a plot
library(palmerpenguins)
library(metafor)
set.seed(1234)
dat <- penguins
dat <- dat[!is.na(dat$sex),]
@wviechtb
wviechtb / backcalculate_sd.r
Created June 2, 2023 14:53
Back-calculate the pooled SD from means, group sizes, and the p-value
# means, SDs, and group sizes
m1 <- 52
m2 <- 40
sd1 <- 6
sd2 <- 4
n1 <- 20
n2 <- 40
# pooled SD
sdp <- ((n1-1)*sd1^2 + (n2-1)*sd2^2) / (n1 + n2 - 2)
@wviechtb
wviechtb / bivariate_normal_wallpaper.r
Last active April 23, 2023 01:09
Code to generate wallpaper (bivariate normal distribution)
rm(list=ls())
setwd("/home/wviechtb/misc/wallpapers/bivariate_normal")
library(mvtnorm)
library(ellipse)
### specify the correlation for the bivariate normal distribution
rho <- 0.4
@wviechtb
wviechtb / boot_rma_mv_parallel.r
Last active February 10, 2023 14:06
Bootstrapping rma.mv() model to get CI for pseudo R^2 statistic
############################################################################
library(metafor)
library(boot)
dat <- dat.crede2010
dat <- escalc(measure="ZCOR", ri=ri, ni=ni, data=dat, subset=criterion=="grade")
############################################################################
@wviechtb
wviechtb / journal_name_generator.r
Last active January 14, 2023 09:48
Papermill Journal Name Generator
genjournal <- function() {
x1 <- sample(c("American Journal of", "Austin Journal of", "Annals of", "Archives of", "International Journal of", "Journal of", "Open Journal of", "World Journal of", "Insights Journal of", "Short Reports of", ""), 1)
x2 <- sample(c("Clinical", "Child & Adolescent", "Family", "Current", "Preventive", "Emergency", "Novel", ""), 1)
x3 <- sample(c("Medicine", "Health Care", "Biomedical Science", "Case Reports", "Nursing Studies", "Surgery", "Medical Case Reports", "Obstetrics", "Gynecology", "Family Medicine", "Primary Care", "Nursing", "Psychiatry", "Pulmonology", "Images", "Biology", "Behavioral Science", "Public Health", "Nursing Practice", "Respiratory Care", "Cancer", "Neurology", "Musculoskeletal Disorders", "Epidemiology", "Cardiology", "Vascular Medicine", "Hematology", "Imaging", "Microbiology", "Infectious Diseases", "Oncology", "Neuroinflammation", "Neurodegenerative Diseases", "Gerontology", "Addiction", "Rehabilitation Medicine", "Translational Medicine", "Images
@wviechtb
wviechtb / Multivariate meta-analysis
Created July 6, 2018 15:15
Some literature on multivariate meta-analysis and other methods to account for dependency in multiple estimates
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 / output.txt
Created May 4, 2022 09:23
Benchmark comparison of for-loops versus apply()/sapply() in 3 different versions of R (2.5.0, 3.0.0, 4.2.0)
> ############################################################################
>
> # A comparison of for-loops versus apply() and sapply() for 1) computing the
> # row means in a matrix and 2) for computing the means of all elements in a
> # list. For task 1), we can also examine the performance of rowMeans() as a
> # specialized / vectorized function and for task 2), we can also compare
> # sapply() with vapply() (note: vapply() was added in version R-2.12.0). Also,
> # for the for-loop, we can examine what the impact is of pre-allocating the
> # vector in which to store the results versus 'growing' the vector in each
> # iteration.
@wviechtb
wviechtb / output.txt
Last active May 4, 2022 08:25
Comparison of apply() versus for-loop in 3 versions of R
############################################################################
R version 2.5.0 (2007-04-23)
Copyright (C) 2007 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.