Skip to contents

Serialize a spec_ir object to JSON

Usage

as_spec_json(spec, pretty = TRUE)

Arguments

spec

A spec_ir object.

pretty

Logical; whether to pretty-print the JSON output.

Value

A character scalar containing JSON text.

Examples

spec <- new_spec_ir()
cat(as_spec_json(spec))
#> {
#>   "schema_version": "1.2.0",
#>   "metadata": {
#>     "title": "Untitled Statistical Study",
#>     "description": "",
#>     "source_prompt": null,
#>     "tags": []
#>   },
#>   "design_type": "monte_carlo_lm",
#>   "hierarchy": {
#>     "levels": 1,
#>     "n_obs": 200,
#>     "n_clusters": null,
#>     "cluster_size": null,
#>     "cluster_size_dist": null,
#>     "cluster_size_sd": null,
#>     "time_points": null,
#>     "time_spacing": null,
#>     "cluster_name": null,
#>     "unit_name": "observation",
#>     "icc": null
#>   },
#>   "predictors": [
#>     {
#>       "name": "x1",
#>       "level": 1,
#>       "distribution": "normal",
#>       "mean": 0,
#>       "sd": 1,
#>       "prob": null,
#>       "min": null,
#>       "max": null,
#>       "centering": "none",
#>       "role": "focal"
#>     }
#>   ],
#>   "predictor_corr": null,
#>   "outcome": {
#>     "name": "y",
#>     "family": "gaussian",
#>     "link": "identity",
#>     "residual_sd": 1,
#>     "error_dist": "normal",
#>     "error_df": null,
#>     "error_skew": null,
#>     "ar1_rho": null
#>   },
#>   "effects": {
#>     "intercept": 0,
#>     "fixed": {
#>       "x1": 0.3
#>     },
#>     "interactions": [],
#>     "focal_predictor": "x1",
#>     "random": {
#>       "intercept": false,
#>       "intercept_sd": null,
#>       "slopes": [],
#>       "corr_matrix": null
#>     }
#>   },
#>   "missingness": {
#>     "mechanism": "none",
#>     "rate": 0,
#>     "target": "outcome",
#>     "auxiliary": null,
#>     "strength": null
#>   },
#>   "estimator": {
#>     "engine": "lm",
#>     "reml": true,
#>     "conf_level": 0.95,
#>     "missing_handling": "complete_case"
#>   },
#>   "simulation": {
#>     "n_reps": 200,
#>     "seed": 2026,
#>     "alpha": 0.05,
#>     "parameter_grid": {}
#>   },
#>   "defaults_rationale": {
#>     "hierarchy.levels": "Defaulted to 1-level hierarchy based on design_type 'monte_carlo_lm'.",
#>     "hierarchy.n_obs": "Defaulted sample size to 200 observations for adequate single-level precision.",
#>     "predictors": "Added a default standardized normal focal predictor 'x1' (mean = 0, sd = 1).",
#>     "outcome.family": "Defaulted outcome family to 'gaussian' for a continuous response.",
#>     "outcome.residual_sd": "Defaulted level-1 residual SD to 1.0 so fixed effects are on a standardized scale.",
#>     "effects.fixed.x1": "Defaulted fixed effect for 'x1' to 0.30.",
#>     "missingness.mechanism": "Defaulted to complete data ('none'); enable MCAR or MAR to study attrition.",
#>     "estimator.engine": "Selected 'lm' estimator matching the 1-level gaussian model.",
#>     "simulation.n_reps": "Defaulted to 200 Monte Carlo replications for responsive prototyping; increase to 500-2000 for publication precision.",
#>     "simulation.seed": "Set deterministic random seed to 2026 for full reproducibility.",
#>     "simulation.alpha": "Defaulted nominal Type I error rate (alpha) to 0.05 (two-sided)."
#>   }
#> }