Provide task-oriented recipes for common DSAMbayes operational workflows. Each guide starts from a user objective, gives minimal reproducible steps, and includes expected output artefacts and quick verification checks.
Audience
Users who know the concepts but need execution steps.
Metadata artefacts are written only if you supply --run-dir or set outputs.run_dir.
If validation fails:
Check the error message for missing data paths, invalid YAML keys, or formula errors.
Remember that the authored v2 schema does not expose model.formula; the runner compiles it from target, media, controls, and optional hierarchy / effects.
Fix the config and re-run validate before proceeding.
3. Run the model
Rscript scripts/dsambayes.R run --config config/cre_geo_panel.yaml
Expected outcome:
Exit code 0.
Full staged artefact tree under the run directory.
4. Locate the run directory
The runner prints the run directory path during execution. It follows the pattern:
results/YYYYMMDD_HHMMSS_<run_label>/
5. Verify artefacts
Check that the following stage folders are populated:
model.rds, optional deployment_model.rds, fit plots
Post-run
30_post_run/
posterior_summary.csv, observed.csv, fitted.csv, plus decomposition tables/plots when enabled and available
Diagnostics
40_diagnostics/
diagnostics_report.csv, diagnostic plots
Model selection
50_model_selection/
LOO summary, Pareto-k plot (if MCMC)
Optimisation
60_optimisation/
Allocation summary, response curves (if enabled)
Optional deployment artifact:
Set outputs.save_deployment_model_rds: true to write 20_model_fit/deployment_model.rds.
This artifact is a compact deployment package for explicit predict(newdata = ...) and explicit-data decomposition; it does not replace model.rds.
Supported for model.type: blm, model.type: pooled with fit.method: mcmc, or hierarchical model.type: re / cre with fit.method: mcmc.
Pooled deployment artifacts score on authored terms and do not require pooling columns in deployment-time newdata / data = ... unless those columns are also ordinary formula terms.
Hierarchical deployment artifacts are seen-groups-only. Explicit newdata / data = ... must include the raw grouping columns, and decomposition also requires the response source column(s).
Diagnostics overall status is fail, diagnostics publish-gate enforcement failed, or a post-fit artifact write failed
Review diagnostics and 00_run_metadata/run_status.yaml if present; the fit completed but the outcome is not publishable
Exit code 2 during run
Stan compilation, sampling, config, or environment failure before a completed run result was returned
Check the CLI error message, Stan cache, and local setup
Missing 20_model_fit/model.rds
Fit did not complete
Review runner log for Stan errors
Missing 20_model_fit/deployment_model.rds
outputs.save_deployment_model_rds is false, model type / fit method is unsupported, or fit did not complete
Check resolved config and confirm either model.type: blm, model.type: pooled with fit.method: mcmc, or hierarchical model.type: re/cre with fit.method: mcmc
Missing 40_diagnostics/
Diagnostics writer failed
Check for upstream fit failures; review tryCatch messages
Programmatic API note:
DSAMbayes::run_from_yaml() can now return a completed runner_result with outcome: completed_with_artifact_write_fail when the fit succeeded but a later artifact-writing step failed, including TSCV artifact writes.
For automation, inspect outcome, postfit_issue, and postfit_message instead of assuming every non-error return is fully successful.
Diagnostics publish-gate failures still raise dsambayes_runtime_error, with the same runner_result attached as condition$result.
Read and act on the diagnostics report produced by a DSAMbayes runner execution, understanding which checks matter most and what remediation steps to take.
Compare multiple DSAMbayes runner executions and select a candidate model for reporting or decision-making, using predictive scoring and diagnostic summaries.
This page is a late-stage selection aid, not a full workflow. Use it only after
the candidate runs are computationally trustworthy enough to compare. In the
principled workflow, that means Stage 4 and Stage 5 work has already been done:
the sampler is behaving acceptably, and the model is at least adequate enough
to remain a candidate. For the surrounding methodology, see
Stage 4: Computation and Sampler
and Stage 5: Model Adequacy.
Prerequisites
Two or more completed runner run executions (MCMC fit method).
Artefacts under 50_model_selection/ for each run (LOO summary, ELPD outputs).
The output ranks runs by ELPD (higher is better) and reports Pareto-k
diagnostics. When TSCV summaries are present, the table also carries
tscv_method, tscv_horizon_weeks, tscv_stride_weeks,
tscv_min_train_weeks, and tscv_gap_weeks so you can see whether holdout
policies actually match. When 00_run_metadata/artifact_schema.yaml is
present, the table also carries artifact_schema_version. Treat this as
ranking among plausible candidates, not as an automatic winner-selection rule.
3. Check Pareto-k reliability
Examine the loo_summary.csv in each run’s 50_model_selection/ folder:
Observations with k > 0.7 indicate unreliable LOO estimates
If many observations have high Pareto-k values, the LOO approximation is unreliable for that run. Consider time-series cross-validation as an alternative.
4. Review time-series CV (if available)
If diagnostics.time_series_selection.enabled: true was configured, check:
This provides blocked-CV or leave-future-out scores (holdout ELPD, RMSE, SMAPE), optionally with an embargo gap when gap_weeks is configured, and is usually more appropriate for time-series data than standard LOO.
compare_runs() warns if candidate runs used different TSCV policies. When
that happens, rank_tscv and delta_tscv_elpd are left NA. Treat those
fields as comparable only when method, horizon_weeks, stride_weeks,
min_train_weeks, and gap_weeks match.
compare_runs() also warns when explicit artifact_schema_version values
differ across runs. That warning does not block ranking, but it means the
helper is reading known artifacts on a best-effort basis across evolving run
contracts.
Time-series selection is advisory in the current runner contract. It is useful for model comparison, but it does not change publish-gate status.
5. Cross-reference diagnostics
For each candidate run, check the diagnostics overall status:
head -1 results/<run_dir>/40_diagnostics/diagnostics_report.csv
A model with better ELPD but failing diagnostics should not be preferred over a model with slightly lower ELPD and passing diagnostics.
If a run is computationally untrustworthy, remove it from contention before you
start arguing about small predictive-score differences.
6. Compare fit quality visually
Review the fit time series and scatter plots in 20_model_fit/ for each run:
Fit time series — does the model track the observed KPI?
Fit scatter — is the predicted-vs-observed relationship close to the diagonal?
Posterior forest — are coefficient estimates reasonable and well-identified?
7. Selection decision matrix
Criterion
Weight
Run A
Run B
Eligible after diagnostics review?
Gate
yes/no
yes/no
ELPD (higher is better)
High
value
value
Pareto-k reliability (fewer high-k)
High
value
value
Diagnostics overall status
High
pass/warn/fail
pass/warn/fail
TSCV holdout RMSE (if available)
Medium
value
value
Coefficient plausibility
Medium
judgement
judgement
Fit visual quality
Low
judgement
judgement
Use the matrix in order:
Remove runs that are not computationally trustworthy enough to compare.
Rank the remaining candidates by predictive evidence.
Prefer the run whose coefficients, decomposition, and fit behaviour remain
most defensible for the business question.
8. Record the selection
Document the selected run directory and rationale. If using the runner for release evidence, the selected run’s artefacts form part of the evidence pack.
Caveats
ELPD is not causal validation. Predictive scoring measures in-sample predictive quality, not whether the model identifies causal media effects correctly.
ELPD is not a substitute for adequacy. Stronger predictive ranking does
not rescue a run that is diagnostically broken or substantively implausible.
Pooled models do not support time-series CV (rejected by config validation).
Adstock/Hill media transforms are not supported by time-series CV; lower-level scoring aborts if transformed-media paths are used.
MAP-fitted models do not produce LOO diagnostics. Use MCMC for model comparison.
Inspect run_status.yaml if present for the message, keep the fitted run directory, then fix the file-system or payload issue and rerun artifact generation
Fit completed but diagnostics publish-gate enforcement rejected the run
Review diagnostics outputs before treating the run as publishable
Missing decomposition files under 30_post_run/
Decomposition failed or was skipped
Check formula compatibility with model.matrix(), confirm the fitted model retained original data, and inspect 40_diagnostics/artifact_status.csv for response_decomposition skip details
Missing 40_diagnostics/ files
Diagnostics writer error
Check for upstream issues in model object; review tryCatch messages in log
Missing 50_model_selection/ files
LOO computation failed
Ensure MCMC fit (not MAP); check for valid posterior
Missing 60_optimisation/ files
Allocation not enabled or failed
Check allocation.enabled: true in config; review scenario specification
Symptoms: CSV artefacts are present but PNG plot files are missing.
Error pattern
Cause
Fix
“cannot open connection” for PNG
Graphics device issue
Check that grDevices is available; ensure sufficient disk space
Plot function error for hierarchical model
Group-level coefficient draws are vectors, not scalars
This has been fixed in recent releases; ensure you are running the latest version
General debugging steps
Read the full error message. DSAMbayes uses cli::cli_abort() with descriptive messages that identify the failing function and parameter.
Check the terminal run status first. If a run directory was created, inspect 00_run_metadata/run_status.yaml if present to see whether the run ended as fit_failed, completed, completed_with_publish_gate_fail, or completed_with_artifact_write_fail.
Check the resolved and compiled configs. Inspect 00_run_metadata/config.resolved.yaml to see what defaults were applied and 00_run_metadata/config.compiled.yaml to see the internal runner config that was actually passed downstream.
Check session info. Inspect 00_run_metadata/session_info.txt for package version mismatches.
Clear the Stan cache. Stale compiled models can cause unexpected failures:
rm -rf .cache/dsambayes/
Run validate before run. Always validate first to catch config errors before committing to a full MCMC run.
Reduce iterations for debugging. Use a small fit.mcmc block or switch temporarily to fit.method: optimise to iterate quickly on schema and data issues.