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

## ----sensitivity--------------------------------------------------------------
sim <- simulate_pupil_timecourse(
  n_participants = 5,
  trials_per_participant = 4,
  sampling_frequency = 20,
  time_window = c(-0.6, 1.4),
  include_gaze = TRUE,
  include_luminance = TRUE,
  seed = 73
)
contract <- create_pupil_contract(
  outcome_col = "pupil_mm",
  participant_col = "participant_id",
  trial_col = "trial_id",
  condition_col = "condition",
  time_col = "event_time",
  pupil_unit = "millimetres",
  sampling_frequency = 20,
  blink_col = "blink",
  interpolation_col = "interpolated",
  gaze_x_col = "gaze_x",
  gaze_y_col = "gaze_y",
  luminance_col = "luminance",
  baseline_window = c(-0.6, 0),
  pfe_corrected = FALSE
)
prepared <- prepare_pupil_timecourse(sim$data, contract)

spec_for_sensitivity <- specify_pupil_timecourse_model(
  prepared,
  autocorrelation = "none",
  smooth_basis_dimension = 5
)
suite <- create_pupil_sensitivity_suite(
  spec_for_sensitivity,
  baseline_windows = list(c(-0.6, -0.1), c(-0.4, -0.1)),
  baseline_window_operation = "subtract",
  baseline_operations = c("none", "subtract"),
  interpolation_policy = c("retain", "exclude_flagged"),
  gaze_adjustment = c("none", "declared_covariates"),
  luminance_adjustment = c("none", "declared_covariate"),
  smooth_basis_dimensions = c(5, 7),
  autocorrelation = c("none", "ar1"),
  analysis_windows = list(c(0.2, 1.0))
)
pupil_sensitivity_table(suite)

## ----materialize--------------------------------------------------------------
scenario_id <- pupil_sensitivity_table(suite)$scenario_id[1]
scenario <- materialize_pupil_sensitivity_scenario(suite, scenario_id)
scenario$scenario_id
scenario$specification

