This page documents some miscellaneous options and features that do not fit very well elsewhere.

## Details

### Specifying the Confidence Level

Several functions in the metafor package have a level argument for specifying the confidence level when calculating confidence (and prediction) intervals. The default is to use a 95% level throughout the package by convention. Note that values $$>=1$$ are treated as coverage percentages, values between 0.5 and 1 as coverage proportions, and values below 0.5 as (two-sided) alpha values, so level=95 is the same as level=.95 and level=.05 (but level=0 is always treated as a 0% confidence level).

### Controlling the Number of Digits in the Output

Many functions in the metafor package have a digits argument, which can be used to control the number of digits that are displayed in the output when printing numeric values. For more control over the displayed output, one can set this argument to a named vector of the form:

digits=c(est=2, se=3, test=2, pval=3, ci=2, var=3, sevar=3, fit=3, het=3)

where the elements control the displayed number of digits for various aspects of the output, namely:

• est for estimates (e.g., effect sizes, model coefficients, predicted values),

• se for standard errors,

• test for test statistics,

• pval for p-values,

• ci for confidence/prediction interval bounds,

• var for sampling variances and variance components,

• sevar for standard errors thereof,

• fit for fit statistics,

• het for heterogeneity statistics.

Instead of setting this argument in each function call, one can use setmfopt(digits = ...) to set the desired number of digits for the various elements (see mfopt for getting and setting package options). For example, setmfopt(digits = c(est=2, se=3, test=2, pval=3, ci=2, var=3, sevar=3, fit=3, het=3)) could be a sensible choice when analyzing various types of standardized effect size measures.

### Styled Output with the crayon Package

The crayon package provides a way to create colored output. The metafor package is designed to automatically make use of this feature when the crayon package is installed (install.packages("crayon")) and loaded (library(crayon)). Note that this only works on terminals that support ‘ANSI’ color/highlight codes (e.g., not under RGui on Windows or R.app on macOS, but the RStudio console and all modern terminals should support this).

The default color style that is used is quite plain, but should work with a light or dark colored background. One can modify the color style with setmfopt(style = ...), where ... is a list whose elements specify the styles for various parts of the output (see below for some examples and the documentation of the crayon package for the syntax to specify styles). The following elements are recognized:

• header for the header of tables (underlined by default),

• body1 for odd numbered rows in the body of tables,

• body2 for even numbered rows in the body of tables,

• na for missing values in tables,

• section for section headers (bold by default),

• text for descriptive text in the output,

• result for the corresponding result(s),

• stop for errors (bold red by default),

• warning for warnings (yellow by default),

• message for messages (green by default),

• verbose for the text in verbose output (cyan by default),

• legend for legends (gray by default).

Elements not specified are styled according to their defaults. For example, one could use:

setmfopt(style = list(header  = combine_styles("gray20", "underline"),
body1   = make_style("gray40"),
body2   = make_style("gray40"),
na      = bold,
section = combine_styles("gray15", "bold"),
text    = make_style("gray50"),
result  = make_style("gray30"),
legend  = make_style("gray70")))

or

setmfopt(style = list(header  = combine_styles("gray80", "underline"),
body1   = make_style("gray60"),
body2   = make_style("gray60"),
na      = bold,
section = combine_styles("gray85", "bold"),
text    = make_style("gray50"),
result  = make_style("gray70"),
legend  = make_style("gray30")))

for a light or dark colored background, respectively. A slightly more colorful style could be:

setmfopt(style = list(header  = combine_styles("snow", make_style("royalblue4", bg=TRUE)),
body1   = combine_styles("gray10", make_style("gray95", bg=TRUE)),
body2   = combine_styles("gray10", make_style("gray85", bg=TRUE)),
na      = combine_styles("orange4", "bold"),
section = combine_styles("black", "bold", make_style("gray90", bg=TRUE)),
text    = make_style("gray40"),
result  = make_style("blue"),
legend  = make_style("gray70")))

or

setmfopt(style = list(header  = combine_styles("snow", make_style("royalblue4", bg=TRUE)),
body1   = combine_styles("gray90", make_style("gray10", bg=TRUE)),
body2   = combine_styles("gray90", make_style("gray15", bg=TRUE)),
na      = combine_styles("orange1", "bold"),
section = combine_styles("snow", "bold", make_style("gray10", bg=TRUE)),
text    = make_style("gray60"),
result  = make_style("steelblue1"),
legend  = make_style("gray30")))

for a light and dark colored background, respectively.

The following code snippet includes all output elements (except for an error) and can be used to test out a chosen color style:

# calculate log risk ratios and corresponding sampling variances
dat <- escalc(measure="RR", ai=tpos, bi=tneg,
ci=cpos, di=cneg, data=dat.bcg)

### Model Object Sizes

The objects returned by model fitting functions like rma.uni, rma.mh, rma.peto, rma.glmm, and rma.mv contain information that is needed by some of the method functions that can be applied to such objects, but that can lead to objects that are relatively large in size. As an example, the model objects that are created as part of the example code for dat.moura2021 are approximately 120MB in size. To reduce the object size, one can make use of the (undocumented) argument outlist. When setting outlist="minimal", the resulting object contains only the minimal information needed to print the object (which results in an object that is around 13KB in size). Alternatively, one can set outlist to a string that specifies what objects that are created within the model fitting function should be returned (and under which name). For example, outlist="coef=beta, vcov=vb" would indicate that only the model coefficient(s) (with name coef) and the corresponding variance-covariance matrix (with name vcov) should be returned (the resulting object then is only around 2KB in size). Note that this requires knowledge of how objects within the model fitting function are named, so inspection of the source code of a function will then be necessary. Also, there is no guarantee that method functions will still work when including only a subset of the information that is typically stored in model objects.

Several functions in the metafor package can make use of parallel processing (e.g., profile) to speed up intensive computations on machines with multiple cores. When using parallel="snow", the default is to use the parLapply function from the parallel package for this purpose. In some cases (especially when the parallelized computations take up quite variable amounts of time to complete), using ‘load balancing’ may help to speed things up further (by using the parLapplyLB function). This can be enabled with pbapply::pboptions(use_lb=TRUE) before running the function that makes use of parallel processing. Whether this really does speed things up depends on many factors and is hard to predict.