## ----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 = 35,
  ar = c(0.55, -0.12),
  ma = 0.10,
  seed = 3010
)

## -----------------------------------------------------------------------------
audit <- audit_pupil_temporal_dependence(sim$data, max_lag = 8)
pupil_autocorrelation_table(audit, "summary")
plot_pupil_temporal_dependence(audit)

## -----------------------------------------------------------------------------
create_pupil_arma_spec(1, 0)
create_pupil_arma_spec(2, 0)
create_pupil_arma_spec(1, 1)

## -----------------------------------------------------------------------------
spec_ar1 <- specify_advanced_pupil_timecourse_model(sim$data, family = "gaussian", autocorrelation = "ar1")
spec_ar2 <- specify_advanced_pupil_timecourse_model(sim$data, family = "gaussian", autocorrelation = "ar2")
spec_arma11 <- specify_advanced_pupil_timecourse_model(sim$data, family = "gaussian", autocorrelation = "arma11")

## ----eval=FALSE---------------------------------------------------------------
# fit_ar1 <- fit_advanced_pupil_model_backend(spec_ar1, backend = "cmdstanr")
# fit_ar2 <- fit_advanced_pupil_model_backend(spec_ar2, backend = "cmdstanr")
# fit_arma11 <- fit_advanced_pupil_model_backend(spec_arma11, backend = "cmdstanr")
# 
# acf_cmp <- compare_pupil_autocorrelation(
#   ar1 = fit_ar1,
#   ar2 = fit_ar2,
#   arma11 = fit_arma11
# )
# plot_pupil_autocorrelation_comparison(acf_cmp)
# 
# spectrum <- pupil_residual_spectrum(fit_arma11)
# plot_pupil_residual_spectrum(spectrum)

