library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2     ✓ purrr   0.3.4
## ✓ tibble  3.0.4     ✓ dplyr   1.0.2
## ✓ tidyr   1.1.1     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.4.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(patchwork)
library(here)
## here() starts at /Users/caoanjie/Desktop/projects/looking_time/adult_analysis
source(here("scripts/poli_model_wave2.R"))

reproducing poli: https://rpubs.com/anjiecao/729261

single block using example sequence

example_seq <- c(1,1,1,1,2,1)
single_block_dissimilar <- poli_model_pokebaby(example_seq, similar = FALSE) %>% 
  mutate(similarity = "dissimilar")
## Note: Using an external vector in selections is ambiguous.
## ℹ Use `all_of(curr_bin_column)` instead of `curr_bin_column` to silence this message.
## ℹ See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
## This message is displayed once per session.
single_block_similar <- poli_model_pokebaby(example_seq, similar = TRUE) %>% 
  mutate(similarity = "similar") 

single_block_similarity <- bind_rows(single_block_similar, single_block_dissimilar)
 df.plot <- single_block_similarity %>% 
    select(trials, surprisal, predictability, learning_progress, similarity) %>% 
    pivot_longer(cols = c("surprisal", "predictability", "learning_progress"), 
                 names_to = "measure", 
                 values_to = "value") %>% 
    filter(trials != 0)
  
  surprise_plot <- df.plot %>% 
    filter(measure == "surprisal") %>% 
    ggplot(aes(x = trials, y = value, color = similarity)) + 
    geom_point() + 
    geom_line() + 
    ylab("surprise") #+ 
  #scale_x_continuous(breaks =seq(1,12,1))
  
  predictability_plot <- df.plot %>% 
    filter(measure == "predictability") %>% 
    ggplot(aes(x = trials, y = value, color = similarity)) + 
    geom_point() + 
    geom_line() + 
    ylab("predictability") #+ 
  #scale_x_continuous(breaks =seq(1,12,1))
  
  learning_progress_plot <- df.plot %>% 
    filter(measure == "learning_progress") %>% 
    ggplot(aes(x = trials, y = value, color = similarity)) + 
    geom_point() + 
    geom_line() + 
    ylab("learning_progress") #+ 
  #scale_x_continuous(breaks =seq(1,12,1))
  
  surprise_plot+predictability_plot+learning_progress_plot + plot_layout(ncol = 1)