## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
library(gp3bayes)

## -----------------------------------------------------------------------------
simulation <- simulate_hierarchical_binary_data(
  n_participants = 10,
  trials_per_participant = 8,
  n_items = 5,
  random_slope_sd = 0,
  seed = 42
)

contract <- create_model_contract(
  "binary", "selected", "participant_id",
  item_col = "item_id",
  trial_col = "trial_id",
  condition_col = "condition"
)

prepared <- prepare_hierarchical_binary_data(
  simulation$data,
  contract,
  condition_levels = c("control", "treatment")
)

specification <- specify_binary_model(prepared, baseline = 0.35)

manifest <- create_analysis_manifest(
  specification = specification,
  estimands = "standardized_probability_contrast",
  seed = 2026,
  label = "Synthetic binary release case"
)

manifest
analysis_manifest_table(manifest)
validate_analysis_manifest(manifest)

## -----------------------------------------------------------------------------
frozen <- freeze_analysis_manifest(manifest)
frozen

## -----------------------------------------------------------------------------
manifest_file <- tempfile(fileext = ".rds")
report_file <- tempfile(fileext = ".md")

freeze_analysis_manifest(manifest, file = manifest_file)
restored <- read_analysis_manifest(manifest_file)
write_reproducibility_report(restored, report_file)

file.exists(manifest_file)
file.exists(report_file)

unlink(c(manifest_file, report_file))

## -----------------------------------------------------------------------------
alternative <- create_analysis_manifest(
  specification = specification,
  estimands = "standardized_probability_contrast",
  seed = 2027,
  label = "Alternative seed"
)

comparison <- compare_analysis_manifests(manifest, alternative)
comparison
plot(comparison)

