Skip to contents

Creates a versioned S3 spec_ir object describing a statistical or Monte Carlo simulation study. Missing subsections are populated with statistically sensible defaults, and plain-language explanations are recorded in defaults_rationale.

Usage

new_spec_ir(
  design_type = "monte_carlo_lm",
  title = "Untitled Statistical Study",
  description = "",
  source_prompt = NULL,
  tags = character(),
  hierarchy = list(),
  predictors = NULL,
  predictor_corr = NULL,
  outcome = list(),
  effects = list(),
  missingness = list(),
  estimator = list(),
  simulation = list(),
  defaults_rationale = list(),
  schema_version = SPEC_SCHEMA_VERSION,
  validate = TRUE
)

Arguments

design_type

Character scalar, one of spec_design_types().

title

Character scalar title for the specification.

description

Character scalar description.

source_prompt

Optional character scalar capturing the originating NL prompt.

tags

Optional character vector of descriptive tags.

hierarchy

Optional named list specifying data hierarchy (levels, n_obs, n_clusters, cluster_size, cluster_name, unit_name, icc).

predictors

Optional list of predictor specifications (see spec_predictor()).

predictor_corr

Optional numeric positive-definite correlation matrix of dimension length(predictors) x length(predictors) specifying correlations among same-level predictors (defaults to NULL for independent predictors).

outcome

Optional named list specifying name, family, link, and residual_sd.

effects

Optional named list specifying intercept, fixed, focal_predictor, and random (intercept, intercept_sd, slopes, corr_matrix).

missingness

Optional named list specifying mechanism ("none", "MCAR", "MAR"), rate, target, auxiliary, and strength.

estimator

Optional named list specifying engine, reml, conf_level, and missing_handling.

simulation

Optional named list specifying n_reps, seed, alpha, and parameter_grid.

defaults_rationale

Optional named list mapping dotted IR paths to plain-language explanations of inferred defaults.

schema_version

Character schema version (defaults to "1.0.0").

validate

Logical; if TRUE (default), validates the resulting IR with assert_valid_spec_ir().

Value

An S3 object of class c("spec_ir", "list").

Examples

spec <- new_spec_ir(
  design_type = "multilevel_sim",
  title = "School Achievement Study",
  hierarchy = list(levels = 2L, n_clusters = 40L, cluster_size = 20L, icc = 0.2),
  simulation = list(n_reps = 100L, seed = 42L)
)
print(spec)
#> 
#> ── spec_ir v1.2.0 [valid] ──
#> 
#> Title: School Achievement Study
#> Design: multilevel_sim | Estimator: lmer
#> Hierarchy: 2-level (40 clusters x 20 observations = 800 total; ICC = 0.2)
#> Outcome: y (gaussian, link = identity)
#> Predictors: x1 [L1, normal, beta=0.3]
#> Simulation: 100 reps | alpha = 0.05 | seed = 42 | grid: none