Read in data

data_path <- here("data-analysis","data","pilot-v1","processed", "emogo-pilot-v1-alldata-anonymized.csv")
d <- read_csv(data_path)
## Rows: 824 Columns: 43
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (30): trial_type, internal_node_id, subject, hitId, assignmentId, struct...
## dbl (11): trial_index, time_elapsed, rt, start_time, end_time, choice_index,...
## lgl  (2): success, timeout
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
d <- d %>%
  filter(
    !(trial_type %in% c("show-reward"))
  )

Adding some useful columns

Adding columns to characterize participant choices.

d <- d %>%
  mutate(
    trial_number = case_when(
      trial_index<7 ~ trial_index,
      trial_index<199 ~ 6+(trial_index-6)/2,
      TRUE ~ trial_index-96
    )
  ) %>%
  relocate(trial_number,.after=trial_index) %>%
  mutate(
    test_trial_number = case_when(
      trial_number<6 ~ NA_real_,
      trial_number<102 ~ trial_number-5,
      TRUE ~ NA_real_
    )
  ) %>%
  relocate(test_trial_number,.after=trial_number) %>%
  mutate(
    explore_block = case_when(
      test_trial_number<9 ~ 1,
      test_trial_number<17 ~ 2,
      test_trial_number<25 ~ 3,
      test_trial_number<33 ~ 4,
      test_trial_number < 41 ~ 5,
      test_trial_number < 49 ~ 6,
      test_trial_number < 57 ~ 7,
      test_trial_number<65 ~ 8,
      test_trial_number<73 ~ 9,
      test_trial_number<81 ~ 10,
      test_trial_number <89 ~ 11,
      test_trial_number <97 ~ 12,
      TRUE ~ NA_real_
    )
  ) %>%
  mutate(
    max_reward_choice = case_when(
      reward_score_unadjusted ==8 ~ 1,
      !is.na(test_trial_number) ~ 0,
      TRUE ~ NA_real_
    )
  )

Summarize

subject_by_block <- d %>%
  filter(!is.na(explore_block)) %>%
  group_by(subject,match_condition,structure_condition,explore_block) %>%
  summarize(
    max_choice_percent=mean(max_reward_choice)
  )
## `summarise()` has grouped output by 'subject', 'match_condition',
## 'structure_condition'. You can override using the `.groups` argument.
summarize_by_block <- subject_by_block %>%
  group_by(explore_block) %>%
  summarize(
    N=n(),
    max_choice = mean(max_choice_percent),
    se = sqrt(var(max_choice_percent, na.rm = TRUE)/N),
    ci=qt(0.975, N-1)*sd(max_choice_percent,na.rm=TRUE)/sqrt(N),
    lower_ci=max_choice-ci,
    upper_ci=max_choice+ci,
    lower_se=max_choice-se,
    upper_se=max_choice+se
  )

summarize_by_block_by_condition <- subject_by_block %>%
  group_by(match_condition,structure_condition,explore_block) %>%
  summarize(
    max_choice = mean(max_choice_percent)
  )
## `summarise()` has grouped output by 'match_condition', 'structure_condition'.
## You can override using the `.groups` argument.

Plots

ggplot(subject_by_block,aes(explore_block,max_choice_percent, color=subject))+
  geom_point(size=1.5,alpha=0.5)+
  geom_line(alpha=0.5)+
  geom_point(data=summarize_by_block,aes(y=max_choice),size=2,color="black")+
  geom_line(data=summarize_by_block,aes(y=max_choice),size=1.2,color="black")+
  geom_errorbar(data=summarize_by_block,aes(y=max_choice,ymin=lower_se,ymax=upper_se),width=0,color="black")+
  geom_vline(xintercept=6.5,linetype="dotted")+
  geom_hline(yintercept=0.25,linetype="dashed")+
  theme(legend.position="none")+
  scale_x_continuous(breaks=seq(1,12))+
  xlab("Block (8 Trials = 1 Block)")+
  ylab("Percent reward-maximizing choices")

ggplot(subject_by_block,aes(explore_block,max_choice_percent, color=subject))+
  geom_point(size=1.5)+
  geom_line()+
  geom_vline(xintercept=6.5,linetype="dotted")+
  geom_hline(yintercept=0.25,linetype="dashed")+
  theme(legend.position="none")+
  facet_wrap(~structure_condition+match_condition)+
  scale_x_continuous(breaks=seq(1,12))+
  xlab("Block (8 Trials = 1 Block)")+
  ylab("Percent reward-maximizing choices")