Skip to contents

Compiles an English statistical or simulation study description into a typed spec_ir specification using a pluggable translator backend (translator_rule(), translator_openai(), or translator_ollama()), returns structured clarifying questions for underspecified parameters, and populates transparent plain-language rationales in spec$defaults_rationale.

Usage

nl_to_spec(prompt, translator = translator_rule(), validate = TRUE)

Arguments

prompt

Character scalar describing the desired statistical study or simulation.

translator

A spec_translator backend object (defaults to translator_rule()).

validate

Logical; if TRUE (default), enforces assert_valid_spec_ir().

Value

An S3 object of class spec_translation with elements:

  • spec: the spec_ir object.

  • clarifications: list of structured clarification objects.

  • validation: spec_validation report.

  • backend: character scalar naming the translator backend.

  • prompt: original natural-language prompt.

  • parsed_fields: character vector of IR paths explicitly extracted from prompt.

Examples

res <- nl_to_spec(
  "2-level multilevel power simulation with 60 schools, 25 students per school,
   ICC 0.2, treatment effect 0.35, random slope for x1, 15% MAR missingness,
   500 replications"
)
print(res)
#> 
#> ── spec_translation [backend: rule] ──
#> 
#> ── spec_ir v1.2.0 [valid] ──
#> 
#> Title: 2-Level School Linear Power Simulation (Random Slopes, MAR Missingness)
#> Design: power_analysis | Estimator: lmer
#> Hierarchy: 2-level (60 schools x 25 students = 1500 total; ICC = 0.2)
#> Outcome: y (gaussian, link = identity)
#> Predictors: treatment [L1, binary, beta=0.35], x1 [L1, normal, beta=0.2]
#> Random Slopes: x1 (sd=0.2)
#> Missingness: MAR (15% on outcome)
#> Simulation: 500 reps | alpha = 0.05 | seed = 2026 | grid: none
#> 
#> ── Open Clarifications (2) 
#> ℹ [treatment_level] Is 'treatment' randomized within schools (level 1) or at
#>   the school level (level 2)? (default: 1)
#> ℹ [slope_sd_x1] What random slope standard deviation (SD) should be used for
#>   'x1'? (default: 0.2)