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

## -----------------------------------------------------------------------------
simulation <- simulate_hierarchical_binary_data(
  n_participants = 12,
  trials_per_participant = 8,
  n_items = 6,
  random_slope_sd = 0,
  seed = 2026
)

contract <- create_model_contract(
  family = "binary",
  outcome_col = "selected",
  participant_col = "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
)

## -----------------------------------------------------------------------------
validate_gp3bayes_object(contract)
validate_gp3bayes_object(specification)

## -----------------------------------------------------------------------------
workflow <- model_workflow_status(specification)
workflow
plot(workflow)

## ----eval=FALSE---------------------------------------------------------------
# fit <- fit_binary_model_backend(
#   specification,
#   backend = "cmdstanr", # or "rstan"
#   chains = 2,
#   iter = 2000,
#   warmup = 1000,
#   cores = 2,
#   seed = 2026
# )

## ----eval=FALSE---------------------------------------------------------------
# diagnostics <- diagnose_model_fit(fit)
# posterior <- summarise_model_posterior(fit)
# ppc <- check_model_ppc(fit, draws = 400, seed = 2026)
# estimands <- estimate_model_estimands(fit)
# 
# plot_sampling_diagnostics(fit, type = "trace")

