## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 7,
  fig.height = 4.5
)
library(gp3bayes)

## ----fit-spec-----------------------------------------------------------------
sim <- simulate_pupil_timecourse(
  n_participants = 5,
  trials_per_participant = 4,
  sampling_frequency = 20,
  time_window = c(-0.4, 1.2),
  baseline_window = c(-0.4, 0),
  blink_trial_probability = 0,
  seed = 2026
)
contract <- create_pupil_contract(
  outcome_col = "pupil_mm",
  participant_col = "participant_id",
  trial_col = "trial_id",
  item_col = "item_id",
  condition_col = "condition",
  time_col = "event_time",
  pupil_unit = "millimetres",
  sampling_frequency = 20,
  eye = "combined"
)
prepared <- prepare_pupil_timecourse(sim$data, contract)
spec <- specify_pupil_timecourse_model(
  prepared,
  temporal_structure = "smooth",
  smooth_basis_dimension = 5,
  condition_trajectory = TRUE,
  autocorrelation = "none"
)
spec

## ----brms-translation, eval=FALSE---------------------------------------------
# translation <- translate_pupil_model_to_brms(spec)
# translation$formula
# translation$prior

## ----prior-plan---------------------------------------------------------------
prior_plan <- check_pupil_prior_predictive(
  spec,
  execute = FALSE,
  draws = 100,
  chains = 2,
  iter = 200,
  warmup = 100
)
as.data.frame(prior_plan)

## ----backend-fit, eval=FALSE--------------------------------------------------
# fit_rstan <- fit_pupil_model_backend(
#   spec,
#   backend = "rstan",
#   chains = 2,
#   iter = 1000,
#   warmup = 500,
#   cores = 2,
#   seed = 20260814
# )
# 
# fit_cmdstanr <- fit_pupil_model_backend(
#   spec,
#   backend = "cmdstanr",
#   chains = 2,
#   iter = 1000,
#   warmup = 500,
#   cores = 2,
#   seed = 20260814
# )

