
Multilevel Random Forest Meta-Analysis
mars_rf_multilevel.RdConvenience wrapper around mars_rf() for formula-based multilevel models.
Usage
mars_rf_multilevel(
data,
formula,
studyID,
variance,
structure = NULL,
varcov_type = "multilevel",
missing = "remove",
num_trees = 500L,
mtry = NULL,
minsplit = 10L,
minbucket = 5L,
cp = 0.001,
maxdepth = 30L,
sample_fraction = 1,
seed = NULL,
importance = TRUE,
weighting = c("sampling", "uniform", "random"),
selection = c("node", "tree"),
min_studies = 2L,
prediction_scale = c("fisher_z", "raw"),
...
)Arguments
- data
Data used for analysis.
- formula
Predictor formula for univariate models. Multilevel models additionally require one nested random-intercept term, such as
(1 | district/study), withstudyIDnaming the outermost group. Random slopes and crossed random terms are currently rejected.- studyID
Character string representing the study ID.
- variance
Character string naming the variance column for formula-based fits.
- structure
Structure label. Use
"univariate"or"multilevel"for formula-based models. Multivariate models are inferred fromeffectsize_type.- varcov_type
Type of within-study sampling covariance. Correlation forests require raw-correlation
simple,weighted, oraveragecovariance (including theircor_aliases). Sampling covariance must be positive definite; invalid variances are rejected.- missing
Missing-data handling mode. Use
"remove","keep", or"em". EM completes continuous missing moderators, using one record per study when moderators are study-level invariant. Within-study variation with missingness requires external multilevel imputation. EM completion does not propagate imputation uncertainty, and disables OOB evaluation. Withkeep, missing predictors follow a direction learned at each split; all observations contribute to split loss. Terminal linear models fill missing predictors using their training-leaf median or modal level.- num_trees
Number of trees in the forest.
- mtry
Number of candidate moderators selected at each node (default) or once per tree. Defaults to \(\max(1,\lfloor\sqrt{p}\rfloor)\) for \(p\) moderators, or zero for multivariate models without moderators. Effect identity is retained separately and does not consume this budget. Explicit interaction columns count as predictors.
- minsplit, minbucket
Tree-growing control parameters.
- cp
Nonnegative fraction of the root weighted squared error required for a split. The same absolute penalty is used for cost-complexity pruning.
- maxdepth
Maximum tree depth.
- sample_fraction
Fraction of studies sampled with replacement for each tree.
- seed
Optional random seed; the caller's RNG state is restored afterward.
- importance
Logical; if
TRUE, aggregate split-based variable importance across trees.- weighting
Split-loss weights:
"sampling"(default) uses inverse sampling variances;"uniform"weights each observation equally;"random"is univariate-only and uses inverse sampling variance plus a nonnegative profiled ML intercept-model heterogeneity estimate, fitted separately to each in-bag sample. A sample with fewer than two distinct studies uses sampling weights and records an unavailable weight_tau. Terminal covariance fits retain the specified sampling covariance regardless of split weighting.- selection
"node"selects candidates at each split;"tree"selects a subset once for the entire tree. Terminal linear models use all available tree predictors, so node selection also yields a model-tree ensemble.- min_studies
Minimum distinct original resampling groups in each child node and for leaf variance estimation (which also requires at least two). Bootstrap copies do not count as additional independent groups.
- prediction_scale
Correlation-only fitting scale:
"fisher_z"(default) fits \(\operatorname{atanh}(r)\), using the delta covariance \(JSJ^T\), with diagonal \(J=1/(1-r^2)\), and returns \(\tanh(\hat z)\). This is a back-transformed location, not an integrated raw-scale random-effects expectation."raw"fits r directly and can extrapolate beyond[-1,1].- ...
Additional arguments are rejected.
Examples
# \donttest{
rf_fit <- mars_rf_multilevel(
data = teacher_expectancy,
formula = yi ~ year + (1 | study),
studyID = "study",
variance = "vi",
num_trees = 25,
seed = 123
)
summary(rf_fit)
#> Random forest meta-analysis
#> Structure: multilevel
#> Trees: 25
#> Predictor selection: node ; split weighting: sampling
#> Predictors: year
#> OOB predictions hold out complete resampling units; preprocessing is conditional on the prepared predictor representation.
#> Leaf fits with fallback: 2
#> OOB coverage: 100 %
#> OOB RMSE: 0.3283
#> OOB R-squared: -1.2622
#>
#> Top variable importance:
#> predictor importance
#> year 0.1034488
# }