Skip to contents

Run the same structural analysis under named covariance scenarios. Measurement models are fitted at most once per call. Each scenario uses repair() and its existing estimator, regularization, and conditional inference unchanged.

Usage

repair_sensitivity(
  formula,
  models,
  data,
  id,
  scenarios,
  na_action = c("fail", "omit"),
  regularization = c("minimum", "none", "step_up", "custom"),
  alpha = NULL,
  backend = c("auto", "r", "rcpp"),
  step_up_control = list(),
  conf.level = 0.95
)

Arguments

formula

An additive structural formula with at least one re() marker. Observed predictors may be numeric, logical, or factors. The outcome must be numeric or a random effect. An intercept is always included.

models

A fitted Gaussian lme4::lmer() or linear nlme::lme() model, an experimental repair_bayes_plugin() snapshot, or named list. Bayesian support is restricted to the snapshot's documented scope; its structural inference conditions on posterior summaries, does not propagate step-1 uncertainty, and has unvalidated full-workflow coverage. Select one target grouping factor per model. Gaussian lmer models may also contain nuisance groups whose every fitted level belongs to exactly one target level; nlme models must have one grouping factor. Grouping column names may differ, but their values must identify the same units. Alternatively supply a repair_mlm() specification, or a named list mixing specifications and fitted models. Each specification is fitted once per call through its native engine before the usual validation and extraction.

data

A data frame with one row per analysis ID, containing the observed structural variables. Its ID values must match the model's grouping levels.

id

Name of the ID column in data; need not equal the grouping name.

scenarios

Nonempty uniquely named list. Each entry is a cross_model_error value: "independent" or complete prediction-error covariance blocks, for example from repair_cross_covariance().

na_action

"fail" (default) or "omit". Omission covers missing or nonfinite observed values, unmatched IDs, and failed prediction blocks; it warns and records every excluded ID and reason.

regularization

Moment regularization: "minimum" (default), "none", "step_up", or "custom". "none" still subtracts measurement error; it disables only stabilization. The same setting is used for preliminary and final moments.

alpha

Custom regularization constant, at least the number of structural predictor columns plus two. Required for regularization = "custom".

backend

M-MOM computation backend: "auto", "r", or "rcpp".

step_up_control

Named list of search settings for regularization = "step_up". See fit_mmom() for defaults, guards, and fallback behavior. The same search settings are used in both stages; the selected alphas can differ.

conf.level

Confidence level for successful coefficient tables.

Value

A plain list with scenarios (one summary row per assumption), coefficients (successful coefficient tables prefixed by scenario), fits (named results, NULL for errors), assumptions (original scenario inputs), and conf.level. Summary columns include status, message, warnings, nobs, selected preliminary/final alphas, and step-up fallback flags (NA when not applicable). Full diagnostic histories are in fits.

Details

Scenarios are assumptions supplied by the analyst, not estimates, model selection candidates, confidence limits for a correlation, or a probability distribution. Choose a scientifically defensible range before inspecting results and report all scenarios. Intervals are conditional on each scenario and fitted measurement parameters; they do not include uncertainty in cross-model covariance or replace bootstrap inference.

Common formula, model, scope, and fitting-argument errors stop the call. Scenario-specific validation errors (including inadmissible covariance) are recorded as "error"; numerical structural failures as "failed". Neither yields coefficient rows. Successful minimum-alpha fallbacks remain "ok" with explicit fallback flags. Scenario warnings are collected in the summary rather than signaled repeatedly. No scenario is silently discarded. Covariance construction errors occur before this function is called: retain those separately when generating a grid, as shown in the multiple-model guide.

Examples

if (requireNamespace("nlme", quietly = TRUE)) {
  case <- readRDS(system.file("extdata", "multimodel-workflow-reference.rds",
                             package = "repair"))$cases$supplied
  models <- list(growth = nlme::lme(y ~ z, random = ~ z | id, data = case$a),
    response = nlme::lme(q ~ w, random = ~ w | subject, data = case$b))
  result <- repair_sensitivity(re(w, "response") ~ re(z, "growth"),
    models, case$people, "person", scenarios = list(
      independent = "independent",
      assumed_nonzero = list(list(models = c("growth", "response"),
        covariance = case$cross_model_error[[1]]$covariance["z", , , drop = FALSE]))))
  result$scenarios
  result$coefficients
}
#>          scenario                      term     estimate  std.error   statistic
#> 1     independent               (Intercept) -0.002309334 0.08930490 -0.02585899
#> 2     independent re("z", model = "growth")  0.215135996 0.09974852  2.15678382
#> 3 assumed_nonzero               (Intercept) -0.005505154 0.08995677 -0.06119778
#> 4 assumed_nonzero re("z", model = "growth")  0.163991926 0.10012949  1.63779844
#>      p.value    conf.low conf.high conf.level
#> 1 0.97936981 -0.17734373 0.1727251       0.95
#> 2 0.03102251  0.01963249 0.4106395       0.95
#> 3 0.95120170 -0.18181717 0.1708069       0.95
#> 4 0.10146375 -0.03225827 0.3602421       0.95