Skip to contents

What this option does

missing = "em" estimates a multivariate-normal distribution for continuous moderators from their observed entries, then completes each missing entry with its conditional mean. It fits MARS to that single completed dataset.

This is deterministic single completion, not multiple imputation or a full-information likelihood for the meta-regression. The subsequent standard errors, confidence intervals, tests and heterogeneity estimates condition on the completed predictors. They do not account for imputation uncertainty. MARS warns when completion is applied and records this limitation in missing_data$em. Cluster-robust standard errors alone do not remedy imputation uncertainty.

Use this option for explicitly conditional or exploratory analyses under an appropriate normal imputation model. For missing-data-adjusted inference, use proper multiple imputation with pooling or a suitable joint missing-data model. A workflow for the former is outlined below.

Independent-study example

set.seed(41)
n <- 50
dat <- data.frame(study=seq_len(n), age=rnorm(n,50,8), duration=runif(n,2,12))
dat$yi <- .2 + .01*(dat$age-50) + rnorm(n,sd=.25)
dat$vi <- .04
dat$age[c(3,7,20,29)] <- NA_real_
fit <- mars(
  dat, formula=yi~age+duration, studyID="study", variance="vi",
  varcov_type="univariate", structure="univariate",
  estimation_method="MLE", missing="em"
)
#> Warning: EM uses deterministic single completion; downstream standard errors
#> and tests condition on completed moderators and do not account for imputation
#> uncertainty. Use multiple imputation with pooling for missing-data-adjusted
#> inference.
fit$missing_data$em[c("applied","converged","iterations","unit",
                     "n_units","inference","uncertainty_accounted")]
#> $applied
#> [1] TRUE
#> 
#> $converged
#> [1] TRUE
#> 
#> $iterations
#> [1] 8
#> 
#> $unit
#> [1] "row"
#> 
#> $n_units
#> [1] 50
#> 
#> $inference
#> [1] "conditional_single_completion"
#> 
#> $uncertainty_accounted
#> [1] FALSE
fit$data[c(3,7,20,29),c("study","age","duration")]
#>    study      age duration
#> 3      3 51.31448 6.372963
#> 7      7 50.64952 8.197986
#> 20    20 50.81971 7.730889
#> 29    29 51.57218 5.665703

The warning is intentional. Observed moderator entries remain unchanged. Complete numeric and categorical moderators can help condition the imputations; complete factors are represented by contrast columns. Missing moderators must be continuous. Variables with only two observed values, logical variables, factors, and numeric columns used inside factor(), as.factor(), or ordered() are rejected when missing. Coding categories as integers does not make them continuous; declare categorical variables as factors.

The model conditions on detected moderators, not automatically on the outcome, precision or auxiliary variables outside the model. Assess whether that imputation model is adequate for your missingness mechanism. Normality, linearity, ignorable missingness and sufficient observed overlap are substantive assumptions; EM convergence does not verify them.

Repeated effects and study-level moderators

With repeated studyID values, EM is supported only when every moderator is invariant within each study among observed entries. MARS reduces the imputation model to one row per study. A known study-level value is reused for that study’s missing entries; a wholly missing study value is completed once and copied back. Studies with more reported effects therefore do not receive extra imputation weight. This assumes that the variables really are study-level quantities; a single observed entry cannot establish invariance by itself.

set.seed(42)
study_age <- rnorm(20,50,8)
dat_rep <- data.frame(study=rep(1:20,each=2),effect=rep(1:2,20),
                      age=rep(study_age,each=2),vi=.04)
dat_rep$yi <- .2 + .01*(dat_rep$age-50) + rnorm(40,sd=.2)
dat_rep$age[2] <- NA_real_       # known value in the other row of study 1
dat_rep$age[dat_rep$study==5] <- NA_real_ # entirely missing for study 5
fit_rep <- mars(
  dat_rep, formula=yi~age+(1|study), studyID="study", variance="vi",
  varcov_type="multilevel", structure="multilevel",
  estimation_method="MLE", missing="em"
)
#> Warning: EM uses deterministic single completion; downstream standard errors
#> and tests condition on completed moderators and do not account for imputation
#> uncertainty. Repeated rows were completed at the study level. Use multiple
#> imputation with pooling for missing-data-adjusted inference.
#> Warning: MARS optimization did not converge (code 52): ERROR:
#> ABNORMAL_TERMINATION_IN_LNSRCH. Increase control$maxit or inspect the model
#> before inference.
fit_rep$data[fit_rep$data$study %in% c(1,5),c("study","age")]
#>    study      age
#> 1      1 60.96767
#> 2      1 60.96767
#> 9      5 51.44595
#> 10     5 51.44595
fit_rep$missing_data$em[c("unit","n_units")]
#> $unit
#> [1] "study"
#> 
#> $n_units
#> [1] 20

If any moderator varies within a repeated study, completion stops. Mixed study-level/effect-level imputation requires an external multilevel imputation model; MARS does not silently pool dependent effect rows. The same safeguards apply to multivariate and random-forest entry points using this EM helper.

Algorithm and diagnostics

For row i, EM computes the conditional mean m_i and covariance C_i given observed entries. The updates are

\mu^{new}=n^{-1}\sum_i m_i,\qquad \Sigma^{new}=n^{-1}\sum_i(m_i m_i^T+C_i)-\mu^{new}(\mu^{new})^T.

The conditional-covariance contribution is essential: it represents variation in missing predictor entries given their observed values. Computing the update from conditional means alone would omit that contribution and would not maximize the stated observed-data normal likelihood. This contribution estimates the predictor distribution; downstream single-completion regression still excludes imputation uncertainty.

Variables are standardized using observed means and standard deviations before iteration. This makes the stopping criteria invariant to changes in units. There is no fixed ridge added in the original units. Convergence requires small changes in both standardized parameters and observed-data log likelihood. The implementation permits at most 1,000 iterations with tolerance 1e-8. The ordinary mars(tol=...) argument controls model optimization, not EM.

ll <- fit$missing_data$em$loglik_trace
plot(seq_along(ll)-1,ll,type="b",xlab="EM iteration",
     ylab="Observed-data moderator log likelihood")

A decrease beyond numerical tolerance, singular/unidentified covariance or failure to converge stops completion; no unconverged filled dataset is fitted. Entirely missing columns, infinite values and insufficient pairwise observed overlap are rejected. The numerical guard requires at least two observations per model column, three per pair, and a positive, well-conditioned standardized covariance. These guards do not prove statistical identifiability in every missingness pattern. Constant complete auxiliary variables are omitted.

Missing effect sizes and variances are not completed and remaining incomplete rows are removed afterward. Missing study IDs are rejected when completion is needed. A row with all moderators missing contributes no observed moderator likelihood information, although conditional-mean completion can still fill it.

Shared predictor completion in MASMR

masmr(missing="em") uses the same EM preparation as mars(), but completes all substantive and methodological source predictors together once before either fit. It also includes scale predictors if supplied. Both models receive identical completed values. Interaction and transformation columns are computed from those values; they are not imputed as separate predictors.

set.seed(1030)
em_dat <- data.frame(study=seq_len(60), M=rnorm(60))
em_dat$S <- .5*em_dat$M + rnorm(60, sd=.8)
em_dat$yi <- .2 + .25*em_dat$S - .10*em_dat$M + rnorm(60, sd=.2)
em_dat$vi <- .04
em_dat$M[c(4,13,26,45)] <- NA_real_
em_dat$S[c(8,13,31,52)] <- NA_real_
em_fit <- masmr(em_dat, "M", "S", formula=yi~1, studyID="study",
  variance="vi", varcov_type="univariate", structure="univariate",
  measure="SMD", tau2=.02, missing="em")
#> Warning: EM uses deterministic single completion; downstream standard errors
#> and tests condition on completed moderators and do not account for imputation
#> uncertainty. Use multiple imputation with pooling for missing-data-adjusted
#> inference.
em_fit$substantive_coefficients
#>   term  estimate  std_error  conf_low conf_high      p_value
#> 1    S 0.2631199 0.04027923 0.1841741 0.3420658 6.472523e-11
em_fit$missing_data$em[c("applied","converged","completion_runs",
  "shared_across_models","inference","uncertainty_accounted")]
#> $applied
#> [1] TRUE
#> 
#> $converged
#> [1] TRUE
#> 
#> $completion_runs
#> [1] 1
#> 
#> $shared_across_models
#> [1] TRUE
#> 
#> $inference
#> [1] "conditional_single_completion"
#> 
#> $uncertainty_accounted
#> [1] FALSE
stopifnot(identical(em_fit$joint$data, em_fit$baseline$data))
# Original-order values and mask, before fitting removes or sorts records:
em_fit$missing_data$em$missing_mask
#>           M     S
#>  [1,] FALSE FALSE
#>  [2,] FALSE FALSE
#>  [3,] FALSE FALSE
#>  [4,]  TRUE FALSE
#>  [5,] FALSE FALSE
#>  [6,] FALSE FALSE
#>  [7,] FALSE FALSE
#>  [8,] FALSE  TRUE
#>  [9,] FALSE FALSE
#> [10,] FALSE FALSE
#> [11,] FALSE FALSE
#> [12,] FALSE FALSE
#> [13,]  TRUE  TRUE
#> [14,] FALSE FALSE
#> [15,] FALSE FALSE
#> [16,] FALSE FALSE
#> [17,] FALSE FALSE
#> [18,] FALSE FALSE
#> [19,] FALSE FALSE
#> [20,] FALSE FALSE
#> [21,] FALSE FALSE
#> [22,] FALSE FALSE
#> [23,] FALSE FALSE
#> [24,] FALSE FALSE
#> [25,] FALSE FALSE
#> [26,]  TRUE FALSE
#> [27,] FALSE FALSE
#> [28,] FALSE FALSE
#> [29,] FALSE FALSE
#> [30,] FALSE FALSE
#> [31,] FALSE  TRUE
#> [32,] FALSE FALSE
#> [33,] FALSE FALSE
#> [34,] FALSE FALSE
#> [35,] FALSE FALSE
#> [36,] FALSE FALSE
#> [37,] FALSE FALSE
#> [38,] FALSE FALSE
#> [39,] FALSE FALSE
#> [40,] FALSE FALSE
#> [41,] FALSE FALSE
#> [42,] FALSE FALSE
#> [43,] FALSE FALSE
#> [44,] FALSE FALSE
#> [45,]  TRUE FALSE
#> [46,] FALSE FALSE
#> [47,] FALSE FALSE
#> [48,] FALSE FALSE
#> [49,] FALSE FALSE
#> [50,] FALSE FALSE
#> [51,] FALSE FALSE
#> [52,] FALSE  TRUE
#> [53,] FALSE FALSE
#> [54,] FALSE FALSE
#> [55,] FALSE FALSE
#> [56,] FALSE FALSE
#> [57,] FALSE FALSE
#> [58,] FALSE FALSE
#> [59,] FALSE FALSE
#> [60,] FALSE FALSE
em_fit$missing_data$em$completed_predictors
#>              M           S
#> 1   1.11842821  1.99538946
#> 2  -0.07928996  1.47041199
#> 3   1.48112728  0.65710545
#> 4   0.27927857  0.50922989
#> 5   2.26309406  1.41330792
#> 6   2.07001276  1.96457193
#> 7   2.63272016  1.25163520
#> 8  -0.32249421 -0.15664302
#> 9   0.39943586  0.11430013
#> 10 -0.45747674  0.67154608
#> 11 -0.62328849 -0.87126664
#> 12 -0.25439159  1.68178339
#> 13 -0.11137236 -0.03377987
#> 14  1.17771088  2.00970217
#> 15 -0.20335753 -0.58391978
#> 16 -0.64027666 -1.30964613
#> 17  0.17837282  0.57961032
#> 18 -0.54769688 -0.13183125
#> 19 -0.59993416 -0.25394675
#> 20  0.21179313  0.23410732
#> 21  0.77709664 -0.71649182
#> 22  1.34238067  1.03885412
#> 23  0.75121782  1.10635312
#> 24 -0.10858484 -0.77981615
#> 25  1.54203194  0.98263000
#> 26  0.81414037  1.25269460
#> 27 -2.02128286 -1.64602045
#> 28  1.28185206  0.78366965
#> 29 -1.15272108 -1.31438819
#> 30 -0.70518346  0.34836553
#> 31  1.49680736  0.90210637
#> 32 -1.77759977 -0.49423774
#> 33  0.80225568 -1.04370751
#> 34 -1.32074739  0.36476313
#> 35 -0.48679659  0.46641711
#> 36 -1.53984929 -1.21696535
#> 37 -0.92829713 -1.06721050
#> 38 -1.71323722 -0.20133567
#> 39  0.17534830 -0.82520345
#> 40 -2.94867899 -1.56809719
#> 41  0.59375861  0.59047330
#> 42 -1.16940767 -1.10990301
#> 43 -0.16982486 -0.38797355
#> 44  1.35094961  0.66525266
#> 45  0.83966202  1.28817002
#> 46 -1.64244694 -0.52359583
#> 47 -1.20100172 -0.84227517
#> 48 -1.63875060 -2.37509127
#> 49 -0.32992997 -0.96266667
#> 50  0.52485030 -0.92098810
#> 51 -0.65254314 -2.04800864
#> 52 -2.58284553 -1.47206297
#> 53 -0.60782368 -0.45267721
#> 54  0.01857104 -0.91933914
#> 55 -0.13694281 -0.82375236
#> 56 -0.99251148 -0.18541561
#> 57 -0.31884052 -0.08287999
#> 58 -1.08219691  1.33801715
#> 59  1.10844969  0.01619091
#> 60 -0.84606420 -0.40231400
# Reproduce the joint fit directly with mars() on the same completion:
em_completed <- em_dat
em_completed[c("M","S")] <- em_fit$missing_data$em$completed_predictors
em_direct <- mars(em_completed, formula=yi~M+S, studyID="study",
  variance="vi", varcov_type="univariate", structure="univariate", tau2=.02)
stopifnot(isTRUE(all.equal(coef(em_direct), coef(em_fit$joint))))

The substantive coefficient compares a one-unit change in S at common M under the additive working surface. Its normal interval conditions on the one completed predictor dataset. The EM warning is intentional: this is neither multiple imputation nor a likelihood integrating over missing predictors. The fixed heterogeneity in this example isolates completion; applied reviews must justify their covariance assumptions.

missing_data$em records convergence and original/completed predictors, a missingness mask, original input study IDs, and row_order="original_input". Both fitted models carry the shared record. Subsequent sensitivity refits hold completed predictors fixed. Contrasts report predictor_inference="conditional_single_completion"; sensitivity results report the same label in inference_status, even with known total covariance. Support output has data_basis="completed_predictors": it describes geometry of completed data, not evidence that missing study characteristics were observed.

Missing continuous predictors are supported; missing categorical predictors, nonconverged EM models and unsupported within-study variation are rejected. Outcomes and sampling variances are not imputed. The imputation model does not automatically condition on outcome values, precision, or unlisted auxiliary variables. A common completed dataset ensures consistent fits but does not make the imputation model scientifically adequate or propagate its uncertainty. Use proper multiple imputation and pooling when missing-data-adjusted inference is required; integrated MI support is a separate development task.

Multiple imputation for inference

Proper multiple imputation creates several plausible completed datasets, including uncertainty in both missing values and imputation-model parameters. Impute using a model compatible with the analysis: account for study clustering, categorical variables, transformations and interactions. For stochastic covariate imputation, include relevant outcome information and variables needed to make the missingness assumption credible. Do not simply add the outcome to this deterministic EM procedure and assume that solves inference; deterministic and stochastic imputation have different properties. See the discussion of outcome inclusion and the mice methodology paper.

The following template starts with a list of properly imputed data frames from an external imputation tool. It is not executed because the imputation model must be chosen for your study design. Use at least two imputations; substantially more may be needed to stabilize estimates and Monte Carlo error.

completed_data <- your_imputed_datasets
fits <- lapply(completed_data,function(d) mars(
  d, formula=yi~age+duration, studyID="study", variance="vi",
  varcov_type="univariate", structure="univariate",
  estimation_method="REML", missing="keep"
))
m <- length(fits)
stopifnot(m>=2)
terms <- colnames(fits[[1]]$design_matrix)
stopifnot(all(vapply(fits,function(f)
  identical(colnames(f$design_matrix),terms),logical(1))))
# Inspect convergence, identifiability and diagnostics in every fit first.
# Do not silently discard failed imputations or pool incompatible coefficients.
Q <- do.call(cbind,lapply(fits,function(f) as.numeric(f$beta_r)))
U <- lapply(fits,function(f) f$varcov_beta)
stopifnot(all(is.finite(Q)),all(vapply(U,function(v) all(is.finite(v)),logical(1))))
Qbar <- rowMeans(Q)
Ubar <- Reduce(`+`,U)/m
B <- cov(t(Q))
Tpool <- Ubar+(1+1/m)*B
r <- (1+1/m)*diag(B)/diag(Ubar)
df <- ifelse(r>0,(m-1)*(1+1/r)^2,Inf)
se <- sqrt(diag(Tpool))
data.frame(term=terms,estimate=Qbar,std_error=se,df=df,
           conf_low=Qbar-qt(.975,df)*se,conf_high=Qbar+qt(.975,df)*se)

This is Rubin pooling for the common regression coefficients, using the large-complete-sample degrees-of-freedom approximation. Small-study analyses need an appropriate finite-sample adjustment and compatible within-imputation inference. Do not pool p-values directly, apply these formulas blindly to heterogeneity parameters, or treat this template as integrated MI support in MARS. The validity of pooled inference depends on both the imputation and analysis models.