metafor is an R package by Wolfgang Viechtbauer that provides a comprehensive collection of functions for fitting fixed-effect, random-effects, and mixed-effects meta-analytic models, including standard univariate, multivariate, multilevel, and meta-regression analyses. The package is distributed free of charge through the Comprehensive R Archive Network, is documented in the foundational Journal of Statistical Software article from 2010, and has become the de facto reference implementation for meta-analytic methods in the open-source statistical community. This guide is a package reference: install instructions, the function index by purpose, the data structures the package expects, troubleshooting for the errors that most commonly stop a fit from converging, and the connections to surrounding R packages that handle the cases metafor was not designed for.
The treatment that follows assumes a working R installation and familiarity with data frames, formulas, and the basic statistical concepts of effect size, weighted mean, and confidence interval. Readers who need the surrounding methodology rather than the package mechanics should follow the complete meta-analysis workflow in R and the step-by-step meta-analysis guides, which cover study selection, data extraction, and interpretation of pooled estimates in a way that this reference deliberately does not.
Installing metafor, Its Dependencies, and Verifying the Environment
The released version of metafor installs from CRAN with a single call: install.packages("metafor"). The current release is version 4.6 series as of 2026, and CRAN keeps the source plus pre-compiled binaries for Windows and macOS for the two most recent major R versions. The development version, which receives bug fixes and new features before they are released to CRAN, lives on the maintainer's repository and installs with remotes::install_github("wviechtb/metafor") after the remotes package itself is installed. The development version is generally safe for production work and is what package contributors test against; users who need a feature added in the last six months should install from GitHub rather than wait for the next CRAN cycle.
Two upstream dependencies deserve attention. Matrix is the workhorse linear algebra package on which metafor's matrix-based estimators depend, and it is a CRAN recommended package that ships with R, so installation rarely fails. mathjaxr is used by the package documentation system to render mathematical notation in help pages and is also pulled automatically by CRAN. The optimizer-related packages nlme, numDeriv, CompQuadForm, and minqa are suggested rather than required, meaning the core fitting functions work without them but specific advanced features (Knapp-Hartung adjustments, certain generalized linear mixed-model fits, score tests) will not work until they are installed. After installation, library(metafor) followed by sessionInfo() confirms the loaded version, the underlying R version, and the BLAS and LAPACK libraries the linear algebra is running against. For reproducibility the BLAS library matters: an OpenBLAS or Intel MKL installation gives different floating-point results in the final decimal places than the reference BLAS shipped with base R, and serious projects should record which one was used.
History, Author, and the Citation You Owe
The metafor package was first released to CRAN on June 5, 2009 by Wolfgang Viechtbauer, then a researcher at Maastricht University in the Netherlands. The foundational paper, "Conducting Meta-Analyses in R with the metafor Package," appeared in the Journal of Statistical Software in 2010, volume 36, issue 3, pages 1 to 48. The paper documents the package architecture, lists the model classes, and walks through worked examples with the Bacillus Calmette-Guerin vaccine data and the cardiovascular morbidity data that are now standard teaching examples. The citation that any peer-reviewed manuscript using metafor must include is reachable inside R itself by typing citation("metafor"), which prints the BibTeX entry alongside the human-readable form.
Viechtbauer has continued as sole maintainer through the entire history of the package, which by 2026 has accumulated more than 250 reverse imports and suggests on CRAN, meaning that many downstream meta-analysis packages depend on it. The size, longevity, and citation footprint of metafor make it the closest thing the meta-analysis community has to a reference implementation, and methodological papers that introduce new estimators routinely include metafor code alongside the mathematical derivation.
Function Index by Purpose
The metafor namespace contains over 90 exported functions. Most analyses use a small subset of those, and the rest exist for specialized cases or as utility helpers. The functional groupings below cover what reviewers actually need.
Effect size computation: escalc. The function escalc() is the entry point for converting raw study data (event counts, means and standard deviations, correlations, proportions, hazard ratios) into the effect-size metrics used by meta-analytic models, paired with the sampling variance of that estimate. The measure argument controls which metric is calculated: "RR" for the log risk ratio, "OR" for the log odds ratio, "PETO" for the Peto odds ratio, "SMD" for the standardized mean difference (Hedges' g by default), "ROM" for the log ratio of means, "ZCOR" for Fisher's z-transformed correlation, "PLO" for the logit-transformed proportion, "PR" for the raw proportion, "IR" for the incidence rate, and so on, with more than 50 metrics supported overall. escalc() returns a data frame with two new columns, yi and vi, holding the effect size estimate and its sampling variance, which are the standard inputs to the model-fitting functions.
Univariate models: rma.uni and the rma shortcut. The function rma() is an alias for rma.uni() and is the function most reviewers call. It fits fixed-effect, random-effects, and mixed-effects meta-analyses (the last when moderators are added) using either weighted least squares with known weights for fixed-effect, or one of several between-study variance estimators for random-effects: method = "DL" (DerSimonian-Laird), "REML" (restricted maximum likelihood, the default and recommended in modern guidance), "ML" (maximum likelihood), "HE" (Hedges), "HS" (Hunter-Schmidt), "SJ" (Sidik-Jonkman), "PM" (Paule-Mandel), "GENQ" (generalized Q-statistic), and "FE" (fixed-effect). The Knapp-Hartung adjustment to standard errors is requested via test = "knha". The methodological reasoning behind the choice of estimator is treated in the REML versus DerSimonian-Laird guide.
Sparse data and 2x2 tables: rma.mh and rma.peto. The rma.mh() function implements the Mantel-Haenszel method for pooling odds ratios, risk ratios, and risk differences from 2x2 tables without the inverse-variance assumption that rma.uni makes. It is appropriate when the number of events in either arm is small, where the inverse-variance weighting can become unstable. The rma.peto() function fits the Peto odds ratio, which is recommended for very rare events and balanced trial arms but is known to be biased when treatment effects are large or arms are unbalanced.
Generalized linear mixed models: rma.glmm. The rma.glmm() function fits binomial-normal and Poisson-normal meta-analytic models, treating the within-study likelihood exactly rather than approximating it with normality on a transformed scale. This is the recommended approach for meta-analysis of proportions, incidence rates, and rare-event 2x2 tables when sample sizes are small. The function uses lme4 internally for the random-effects fit and can take noticeably longer to run than rma.uni.
Multivariate and multilevel models: rma.mv. The rma.mv() function fits multivariate, multilevel, and hierarchical meta-analytic models, including models with correlated outcomes within studies, multiple effect sizes per study, and three- or higher-level hierarchies (effects nested within studies nested within research groups). The variance-covariance structure of the random effects is fully customizable through the random argument, allowing compound symmetric, autoregressive, heteroscedastic compound symmetric, and arbitrary user-specified structures. This is the function used for dependence modeling when robust variance estimation alone is insufficient.
Forest plots: forest. The function forest() is a method dispatcher with class-specific implementations for rma objects, escalc objects, and raw input vectors. The rma method draws the classic Cochrane-style forest plot with study weights, individual confidence intervals, a pooled diamond at the bottom, and optional heterogeneity statistics in the bottom-left corner. Heavy customization is supported through the xlim, alim, ilab, header, mlab, addfit, and addpred arguments; subtotals and grouping are accomplished by repeated calls to addpoly() after the main plot.
Funnel plots: funnel. The function funnel() draws funnel plots from rma objects with three style options: the classic funnel with theoretical confidence-interval pseudo-bounds, the contour-enhanced funnel that overlays significance regions (the contour-enhanced variant is the one Peters and Sterne recommend for visual diagnosis of asymmetry caused by publication bias rather than heterogeneity), and the funnel of standardized residuals. The y-axis variable is configurable: standard error, sampling variance, inverse standard error, or sample size.
Asymmetry tests: regtest and ranktest. The regtest() function performs Egger's regression test for funnel-plot asymmetry, with options for the predictor (predictor = "sei", the standard error, is the original Egger specification; "vi", the sampling variance; "ninv", the inverse sample size, and others). The function ranktest() performs Begg and Mazumdar's rank correlation test, which is less powerful than the regression test but does not assume linearity of the asymmetry relationship.
Trim and fill: trimfill. The trimfill() function implements Duval and Tweedie's trim-and-fill procedure for imputing studies that are "missing" from one side of the funnel and recomputing a publication-bias-corrected pooled estimate. The method is now generally considered useful only as a sensitivity analysis rather than a definitive correction; selection-model approaches and PET-PEESE are increasingly preferred in 2026 practice.
Influence diagnostics: influence, leave1out, baujat, gosh. The influence() function returns DFBETAS, DFFITS, Cook's distances, hat values, and standardized residuals on a per-study basis. The leave1out() function refits the model excluding each study in turn, returning a data frame of pooled estimates and heterogeneity statistics with one row per study; useful for identifying influential outliers. The baujat() function draws Baujat plots, which scatter each study's contribution to the overall Q statistic against its influence on the pooled estimate, making outliers visually obvious. The gosh() function performs a graphical display of study heterogeneity, fitting models to many random subsets of the studies and plotting the resulting pooled-estimate distribution against the heterogeneity distribution, revealing whether outliers shift the entire pooled estimate or merely the heterogeneity.
Prediction intervals: predict. The predict() method on an rma object returns the pooled point estimate, its confidence interval, and the prediction interval for the true effect in a future setting drawn from the same distribution as the included studies. The prediction interval is wider than the confidence interval and is the more honest quantity for clinical decision-making in heterogeneous meta-analyses.
Permutation tests: permutest. The permutest() function runs permutation-based inference for model coefficients in fixed-effects and mixed-effects meta-analyses, which is useful when small numbers of studies cast doubt on the validity of large-sample chi-squared approximations.