Skip to contents

Compare two complete substantive scenarios using the same methodological profiles and target weights. The estimand is a standardized difference in fitted mean effects, not a prediction interval for a new study.

Usage

masmr_contrast(
  object,
  substantive,
  methodology,
  target_weights = NULL,
  inference = c("model", "KH", "mKH", "robust"),
  level = 0.95,
  warn_support = TRUE,
  outcome = NULL
)

Arguments

object

A fitted masmr object from the extended implementation.

substantive

A named list of exactly two one-row data frames. The result is the second scenario minus the first. Supply every substantive variable, including substantive covariates held constant.

methodology

A nonempty data frame containing all methodology variables. Each row defines one target profile. A single row defines a reference-profile contrast. No ideal profile is chosen automatically.

target_weights

Nonnegative finite weights, one per target row, with positive sum. Normalized to sum to one; default equal profile weights. These are target weights, not the fitting precision weights. Repeated rows are retained, so study-level rather than effect-level targets must be built explicitly when studies contribute several effects.

inference

One of "model" (normal), "KH", "mKH", or "robust". KH variants require independent univariate fits. Robust inference uses the fitted robust covariance and recalculates degrees of freedom for the requested contrast using the fit's inference setting. No fallback occurs.

level

Confidence level in (0,1).

warn_support

Warn when positively weighted target rows have absent categorical combinations or lie outside observed continuous ranges.

outcome

Outcome name(s) for an outcome-aware fit. NULL returns separate contrasts for every outcome, with cross-outcome covariance. No aggregation.

Value

A masmr_contrast list with result, contrast_matrix, target, support, and covariance of the contrast and two target means. Formula and outcome-aware workflows are supported. Outcome-specific targets require explicit outcome and measure metadata. Target profiles and weights are treated as fixed. Intervals are pointwise.

Details

The contrast is L beta, with variance L V L'. Nonlinear terms and interactions are rebuilt with the fitted terms and factor coding. Unsupported profiles are never removed or reweighted. Diagnostics describe observed support; they do not establish exchangeability or causal effects. Numeric-coded categories are treated as continuous: use factors for categorical support checks. Range checks are necessary but not sufficient for multivariate overlap; leverage is descriptive, with no calibrated cutoff.

Examples

dat <- data.frame(study = 1:18, S = rep(c(0, 1, 0), each = 6),
                  M = rep(c(0, 0, 1), each = 6), vi = .0075)
dat$yi <- .20 + .15 * dat$S - .05 * dat$M + rep(seq(-.02, .02, length.out = 6), 3)
fit <- masmr(dat, "M", "S", formula = yi ~ 1, studyID = "study",
             variance = "vi", varcov_type = "univariate", measure = "SMD",
             structure = "univariate", tau2 = 0)
target <- list(A = data.frame(S = 0), B = data.frame(S = 1))
masmr_contrast(fit, target, data.frame(M = 0))$result
#>   contrast estimate std_error  conf_low conf_high  df     p_value inference
#> B    B - A     0.15      0.05 0.0520018 0.2479982 Inf 0.002699796     model
#>   level scale outcome predictor_inference
#> B  0.95     1  effect observed_predictors