## ----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 = 10,
  trials_per_participant = 4,
  time_points = 31,
  heteroskedastic_strength = 0.8,
  outlier_fraction = 0.03,
  seed = 3001
)
plot_advanced_pupil_simulation(sim)

## -----------------------------------------------------------------------------
gaussian_constant <- specify_pupil_distribution("gaussian", "constant")
gaussian_time <- specify_pupil_distribution("gaussian", "condition_time")
student_time <- specify_pupil_distribution("student", "condition_time")

pupil_distribution_table(gaussian_constant)
pupil_distribution_table(gaussian_time)
pupil_distribution_table(student_time)

## -----------------------------------------------------------------------------
spec_constant <- specify_advanced_pupil_timecourse_model(
  sim$data,
  family = "gaussian",
  residual_scale = "constant",
  autocorrelation = "none"
)

spec_distributional <- specify_advanced_pupil_timecourse_model(
  sim$data,
  family = "gaussian",
  residual_scale = "condition_time",
  autocorrelation = "none"
)

spec_robust <- specify_advanced_pupil_timecourse_model(
  sim$data,
  family = "student",
  residual_scale = "condition_time",
  autocorrelation = "none"
)

## ----eval=FALSE---------------------------------------------------------------
# fit_distributional <- fit_advanced_pupil_model_backend(
#   spec_distributional,
#   backend = "cmdstanr",
#   cores = 2
# )
# 
# sigma <- estimate_pupil_residual_scale(fit_distributional)
# pupil_residual_scale_table(sigma)
# plot_pupil_residual_scale(sigma)

