Provide task-oriented recipes for common dsambayesplus 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.
A YAML config file (see Config Schema for structure).
Data file(s) referenced by the config are accessible.
Steps
1. Set up the environment
Complete the environment setup in Install and Setup (selecting the host library, creating the cache directory, and exporting XDG_CACHE_HOME) before continuing.
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/dsambayesplus.R run --config config/cre_geo_panel.yaml
Expected outcome:
Exit code 0.
Full staged artefact tree under the run directory.
For the bounded fixed-effects runner path:
Rscript scripts/dsambayesplus.R run --config config/fe_panel.yaml
This runs the coefficient-only FE MCMC estimator and writes only the dedicated
FE files documented under Output Artefacts. It does
not run generic level-scale diagnostics, PSIS model selection, scenario analysis,
optimisation, forecasting, or deployment. To add seen-unit expanding-window
validation, enable diagnostics.time_series_selection; every fold must contain
only holdout units already seen in training and at least two training rows per
unit. A completed FE run is not a
production qualification; its diagnostics summary records
qualification_status: not_assessed.
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:
The runner files retain legacy decomp_* names, but they are not the
mapping/reference-point result returned by interactive decomp(). They fail
closed for hierarchical, offset-bearing, and probabilistic-media-transform
models, with the reason recorded in artifact_status.csv.
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).
FE does not support deployment_model.rds. Its optional posterior.rds is a
compact extracted posterior table, while model.rds is the fitted
same-environment analysis object.
Diagnostics overall status is fail, requested scenario analysis failed, diagnostics publish-gate enforcement failed, or a post-fit artefact 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
Missing 60_scenario_analysis/
Scenario analysis is disabled or failed
Check scenario_analysis.enabled, input paths, and 00_run_metadata/run_status.yaml
For FE runs, missing generic observed.csv, fitted.csv,
diagnostics_report.csv, PSIS model-selection, scenario, optimisation, forecast, or
deployment files is expected. Use within_design.csv,
contrast_residuals.csv, contrast_ppc.csv, level_diagnostics.csv, and
diagnostics_summary.txt for the bounded FE runner reporting contract.
level_diagnostics.csv is an in-sample conditional diagnostic for retained
units, not held-out validation. When FE time-series validation is enabled, use
50_model_selection/tscv_summary.csv and, if requested,
tscv_pointwise.csv for held-out seen-unit scoring. The direct R API separately supports conditional
retained-unit intercepts, fitted level values, observed level data, and
retained-unit prediction after MCMC.
Programmatic API note:
dsambayesplus::run_from_yaml() can return outcome: completed_with_scenario_analysis_fail when the fit succeeded but the requested scenario analysis failed, or completed_with_artifact_write_fail when a later artefact-writing step failed, including TSCV artefact 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 dsambayesplus_runtime_error, with the same runner_result attached as condition$result.
Read and act on the diagnostics report produced by a dsambayesplus runner execution, understanding which checks matter most and what remediation steps to take.
Each row is one diagnostic check. The key columns are:
Column
What to look at
check_id
Identifies the specific diagnostic
status
pass, warn, fail, or skipped
value
The observed metric value
threshold
The threshold that was applied
message
Human-readable explanation
2. Check the overall status
The overall status follows a simple rule:
Any fail → overall fail.
Any warn (no fails) → overall warn.
All pass → overall pass.
If the overall status is pass, no enabled check breached its configured threshold. Continue with substantive fit, predictive, sensitivity, identifiability and intended-use review. A pass is not model approval.
3. Triage failing checks
Focus on fail rows first, then warn rows. Use the check phase to prioritise:
Phase
Priority
Meaning
P0
Highest
Data integrity or critical MCMC reliability, fix before interpretation
P1
High
Conditioning, residual or identifiability concerns, review before use
P2
Supplementary
Predictive scoring and influence evidence, never causal validation
4. Common diagnostics and actions
The phase assignments below match the emitted phase field:
Check ID
Phase
pre_response_finite
P0
pre_design_constants_duplicates
P0
pre_design_rank_deficit
P0
post_rhat_max
P0
post_ess_bulk_min
P0
post_ess_tail_min
P0
post_divergences
P0
post_treedepth_saturation
P0
post_ebfmi
P0
pre_design_condition_number
P1
post_residual_ljung_box_p_min
P1
post_residual_max_abs_acf
P1
post_boundary_hit_rate_max
P1
pre_within_variation_ratio_min
P1
pre_identifiability_baseline_media_corr
P1
Design integrity (P0)
Check
Symptom
Action
pre_response_finite fails
Non-finite values in response
Clean data; remove or impute NA/Inf rows
pre_design_constants_duplicates fails
Constant or duplicate columns
Remove redundant terms from formula
pre_design_rank_deficit warns/fails
Rank-deficient design
Remove redundant terms; review whether the specification can identify separate effects
Design conditioning (P1)
Check
Symptom
Action
pre_design_condition_number warns/fails
High collinearity
Reduce correlated predictors; simplify formula
Sampler quality (P0, MCMC only)
Check
Symptom
Action
post_rhat_max warns/fails
Poor convergence
Increase fit.mcmc.iter and fit.mcmc.warmup; simplify model
post_ess_bulk_min or post_ess_tail_min warns/fails
Compare multiple dsambayesplus 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).
Use identical response transformations and observation sets, and require
likelihood_scale = unstandardised_model_response in newly generated
loo_summary.csv files. Regenerate schema 3 and earlier scores from retained
full fits; refit affected scaled no-intercept models first.
compare_runs() requires matching model_comparison metadata in
artifact_schema.yaml: response expression, response scale, observation count,
density units and a fingerprint of the ordered raw model response plus date
and group labels. Numerical scaling and predictor selection do not change that
fingerprint when the retained response rows remain identical. Changing the
response, retained rows, row order or grouping labels prevents ranking.
The table reports comparison_status: compatible, missing_metadata,
incompatible_data, inconsistent_metadata, or unscored. If any otherwise
eligible candidate lacks compatible provenance, all candidate ranks and deltas
remain NA. Restrict run_dirs to a compatible comparison set. Failed or
unscored runs do not receive a rank or delta.
The writer needs the optional digest package and raw-response metadata retained
by current fit preparation. Older fits without that metadata remain readable
and scoreable, but regenerating their scores alone does not make them eligible
for automatic ranking. Refit to establish current provenance; do not add a
schema version or fingerprint by hand. loo_compare_models() applies the same
provenance requirement to fitted models and precomputed LOO objects.
3. Compare ELPD scores
The compare_runs() helper ranks runs by expected log predictive density (ELPD):
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.
4. 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
Default PSIS-LOO uses chain-aware likelihood relative efficiency. Public
loo(model, r_eff = ...) accepts an explicit override; WAIC needs no relative
efficiency. Runner diagnostics.model_selection.max_draws is an upper bound: it retains
balanced chronological prefixes from every chain and requires at least six
draws per chain. An insufficient budget produces a skipped diagnostic. See the
loo relative-efficiency reference.
If many observations have high Pareto-k values, the LOO approximation is unreliable for that run. Consider time-series cross-validation as an alternative.
5. 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() ranks a TSCV result only when every scheduled fold succeeded.
It conservatively requires the same full retained response dataset across
candidates, as well as the same method, horizon_weeks,
stride_weeks, min_train_weeks, gap_weeks, number of folds, and realised
holdout start and end dates. If these conditions do not hold, rank_tscv and
delta_tscv_elpd remain NA; the helper warns when otherwise eligible runs
are not comparable.
compare_runs() also warns when explicit artifact_schema_version values
differ across runs. The version warning is separate from the provenance guard:
matching version numbers alone never establish comparability.
Time-series selection is advisory in the current runner contract. It is useful for model comparison, but it does not change publish-gate status.
6. 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.
7. 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?
8. 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.
9. 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 80_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. dsambayesplus 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_scenario_analysis_fail, 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/dsambayesplus/
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.