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

## -----------------------------------------------------------------------------
library(gp3bayes)
sim <- simulate_advanced_pupil_timecourse(
  n_participants = 12,
  trials_per_participant = 4,
  time_points = 31,
  seed = 3050
)

base <- specify_advanced_pupil_timecourse_model(sim$data, temporal_structure = "smooth", family = "gaussian")
suite <- create_pupil_advanced_sensitivity_suite(base)
suite

## ----eval=FALSE---------------------------------------------------------------
# robust <- materialize_pupil_advanced_sensitivity_scenario(suite, "likelihood_student")
# gp <- materialize_pupil_advanced_sensitivity_scenario(suite, "temporal_gaussian_process")
# 
# fit_smooth <- fit_advanced_pupil_model_backend(base, backend = "cmdstanr")
# fit_robust <- fit_advanced_pupil_model_backend(robust, backend = "cmdstanr")
# fit_gp <- fit_advanced_pupil_model_backend(gp, backend = "cmdstanr")
# 
# models <- create_pupil_model_set(
#   smooth_gaussian = fit_smooth,
#   smooth_student = fit_robust,
#   gp_gaussian = fit_gp,
#   predictive_target = "future_segment"
# )
# 
# cmp <- compare_pupil_models(models, criterion = "loo")
# pupil_model_comparison_table(cmp)
# plot_pupil_model_comparison(cmp)
# pupil_model_weights(cmp, method = "stacking")

## ----eval=FALSE---------------------------------------------------------------
# lfo_plan <- create_pupil_lfo_plan(
#   fit_smooth,
#   initial_fraction = 0.60,
#   horizon = 5,
#   step = 5,
#   max_refits = 6
# )
# lfo_plan
# 
# # No refit occurs unless execute = TRUE.
# lfo_result <- validate_pupil_leave_future_out(
#   fit_smooth,
#   lfo_plan,
#   execute = TRUE,
#   cores = 1
# )
# plot_pupil_lfo(lfo_result)

