library(samplr)
library(tidyverse)
library(patchwork)

# Make an instance of ABS (Example in the slides) -------------------------------------------------
myModel <- Zhu23ABS$new(
  ## MC3 parameters
  width = 25, # proposal width
  n_chains = 6, 
  distr_name = "norm", 
  distr_params = 30, # sd of the target distribution
  
  ## Reaction time parameters
  lambda = 4, # lambda for Erlang distr.
  nd_time = 1, # seconds of non-decision time
  s_nd_time = 0 # variability of non-decision time (ndt ~ Unif(nd_time, nd_time + s_nd_time))
)

# Simulate from the model
myModel$simulate(
  stopping_rule = "fixed",
  n_sample=4,
  trial_stim=c(24, 22, 27),
  start_point=12
)

# Examine results
myModel$sim_results

# Add confidence intervals
myModel$confidence_interval(.5)
myModel$sim_results

# Forget simulation (so that we can re-simulate)
myModel$reset_sim_results()


# Practice: Anchoring with ABS --------------------------------------------
true_height <- 127
start_point <- 320

# Insert code here:


# Practice: Speed-Accuracy Trade-off --------------------------------------
set.seed(1)
stimuli <- factor(
  sample(c("left", "right"), 100, T)
)
myModel <- Zhu23ABS$new(
  width = 2,
  n_chains = 6,
  distr_name = "norm",
  distr_params = 2,
  lambda = 4,
  nd_time = 1,
  s_nd_time = 0
)

# Which parameters below do you need to change to be 
# - slow+accurate
# - fast but more inaccurate
myModel$simulate(
  stopping_rule = "relative",
  delta = , # Fill this field
  dec_bdry = , # Fill this field
  discrim = , # Fill this field
  prior_on_resp=c(0,0), 
  trial_stim = stimuli
)

# Check results
mean(myModel$sim_results$rt); mean(myModel$sim_results$accuracy)

# Reset sampling so that we can simulate again
myModel$reset_sim_results()




