library(lme4)
library(here)
library(tidyverse)
library(stringr) # for parsing r string 
library(jsonlite) # for parsing r string 
library(ggiraphExtra)
library(plotrix)
library(lmerTest)
RT_data <- read_csv(here('data/processed_data/trimmed_RTdata.csv'))
similarity_data <- read_csv(here('data/processed_data/trimmed_similaritydata.csv'))
complexity_data <- read_csv(here('data/processed_data/trimmed_complexitydata.csv'))
demog_data <- read_csv(here('data/processed_data/trimmed_demogdata.csv'))

process the looking time!

RT_data <- RT_data %>% 
  mutate(looking_time = case_when(
    exposure_type == "forced_short" & trial_number == 1 ~ 500, 
    exposure_type == "forced_long" & trial_number == 1 ~ 15000, 
    TRUE ~ 500 + rt
  ))

check verbal feedback:

feedback <- read_csv(here('data/merged_data/merged_data.csv')) %>% 
  filter(stimulus_type == "feedback") %>% 
  select(subject, responses) %>% 
  toJSON() %>% 
  fromJSON() %>% 
    mutate(
      feedback = map(responses, ~ fromJSON(.) %>% as.data.frame())) %>% 
    unnest(feedback) %>% 
  select(subject, Q0) 
## Parsed with column specification:
## cols(
##   .default = col_character(),
##   trial_index = col_double(),
##   time_elapsed = col_double(),
##   trial_stimulus = col_logical(),
##   minimum_viewing_duration = col_double(),
##   trial_looking_time = col_double(),
##   block_number = col_double(),
##   math_correct_answer = col_double()
## )
## See spec(...) for full column specifications.
feedback %>% kableExtra::kable()
subject Q0
SS1619739134468 Study was good! (spore is amazing game :>)
SS1619739156020 Were this creatures by any chance from the game called Spore? They looked identical to things you could make in that game.
SS1619739161714 it worked smoothly
SS1619739185303 No problems at all
SS1619739188870 No, all good !
SS1619739194809 no
SS1619739196799 No, it was all great!!
SS1619739236312 Some animations look rather grotesque/senseless for babies, probably on purpose but still!
SS1619739243666 No
SS1619739270972 nothing
SS1619739299290 No issues and no lag.
SS1619739307054 no lag, good job
SS1619739315680 Everything was good!
SS1619739341056 Some animations of the more complex monsters were a little more laggy
SS1619739341788 no problem, very curious about the purpose of the experiment
SS1619739362581 nope
SS1619739377879 The monster took too much time to disappear
SS1619739395520 no
SS1619739428554 I did not face any problems.
SS1619739432032 no
SS1619739432069 I recognized the creatures from spore. It was one of my favorite games when I was a kid
SS1619739442485 The experiment runs perfect
SS1619739450196 Just i failed a sumatory. I can’t one animation (disappear so fast)
SS1619739450277 none
SS1619739450868 I think that some of the creatures look quite scary (not very appropriate for babies)
SS1619739452993 No
SS1619739457003 Some of the creatures I found very cute, the pink ones :)
SS1619739489473 No it was all fine.
SS1619739490440 no, everything was ok
SS1619739496757 No
SS1619739512117 no
SS1619739516280 Everything went well.
SS1619739526305 no, all good
SS1619739531313 hopr you had fun playing spore
SS1619739535999 No
SS1619739541834 no
SS1619739552633 no
SS1619739570391 Nope, it was not laggy at all
SS1619739580862 no
SS1619739584196 This was fun, thanks for letting me participate!
SS1619739588838 no, it was all plain sailing! :-)
SS1619739600585 There was no issue but the creatures are a little disturbing
SS1619739610144 No
SS1619739610683 None
SS1619739611736 No, everything was fine
SS1619739620491 Oh, this was just amazing!!
SS1619739623165 No
SS1619739623638 I did not encounter any issues with the experiment. There weren’t any lags. It was a pleasante experience.
SS1619739624736 the experiment was perfectly working
SS1619739642555 Nothing
SS1619739656790 No problems
SS1619739660475 Did not seem laggy to me. Neither cute, sorry…
SS1619739661980 no
SS1619739670582 no issue
SS1619739672831 No
SS1619739682451 everything went right, didnt quiet get the relationship the study has with babies, but it was kinda interesting to answer
SS1619739682803 no
SS1619739685705 no
SS1619739687151 i did not have any problem
SS1619739703800 no
SS1619739704103 Didnt have any issue or lag:)
SS1619739705444 (No issues) Some creatures seemed to move like a heartbeat wave, I wonder if that was actually the case
SS1619739706244 i like spore so this was fun
SS1619739713443 no
SS1619739719701 No
SS1619739724256 No issues, experiment was interesting, I think you used “Spore” to make those creatures ;)
SS1619739729654 No issues
SS1619739734513 no
SS1619739740824 You told, in the instructions, that we should press the down arrow key only after the creatures disappear, but you showed an example of what would be a short appearence and a long one. In my case, some creatures just didn’t go away, their appearence was nothing like the example. So I ended up pressing the key after the time I was expecting from a long appearence based on your example. Also, I felt really bad seeing those creatures, I felt sick looking at them and I’m sorry. Thank you.
SS1619739752298 it was all fine
SS1619739753725 no problems at all!
SS1619739754865 n/a
SS1619739756194 No issues, no lag
SS1619739763096 I like the pink one
SS1619739766921 None
SS1619739804274 No
SS1619739807636 Nothing.
SS1619739808620 No, everything was fine
SS1619739808785 Maybe sharing at the end the purpose of the study would be nice, or the criteria for the short/long animations to be there.
SS1619739812145 This was such a cute experiment! Thank you for the opportunity! I am not a baby but I found this super fun and adorable! :)
SS1619739820932 no
SS1619739821314 No
SS1619739821646 All right!
SS1619739822519 It wasn’t laggy at all! Some of animations were really cute and some were quite funky!
SS1619739823278 No, all perfect!
SS1619739824111 no
SS1619739825744 nop
SS1619739830079 No lag, very smooth.
SS1619739833035 no
SS1619739837763 everything was fine
SS1619739838302 Ninguno, solo son demasiadas extrañas las animaciones.
SS1619739843464 None
SS1619739847224 I haven’t problems with the animation. The anomation played correctly.
SS1619739852794 no problem
SS1619739855680 Everything was fine.
SS1619739858329 no, everything worked great
SS1619739859252 The animation was not lagging :)
SS1619739860700 No :)
SS1619739861046 No
SS1619739861779 No problems
SS1619739862515 i didn´t find any problem, not laggy at all
SS1619739875957 Not at all, i was a bit confused with the instructions at first but atfer that nothing wrong.
SS1619739883619 Everthing went well!
SS1619739886734 no, it wasn’t laggy, it was quite fluid
SS1619739888340 Nothing in particular
SS1619739895095 spore is underrated
SS1619739897100 I didn’t see all of the animations in the preview section, I saw some of them for the first time while rating how similar or dissimilar they are.
SS1619739899106 No lag
SS1619739901888 It was a bit laggy, the quality of the animations was not very good, but it was fun, thanks a lot!:)
SS1619739910027 none
SS1619739914991 Everything was fine
SS1619739916640 ningun problema
SS1619739921017 None
SS1619739929640 nop
SS1619739934260 no problems
SS1619739942790 b
SS1619739945294 I didnt found any issue
SS1619739950567 No
SS1619739958178 NOTHING
SS1619739965907 no, everything worked well
SS1619739966649 no
SS1619739968685 None
SS1619739969517 no
SS1619739971179 the experiment was normal
SS1619739975890 all good
SS1619739987589 No issues. Spore was a fun little game.
SS1619739988927 Animations were a bit pixeled. Also, I thought the monochromatic figures looked like dog’s toys or sexual toys.
SS1619739991060 Why are these images so weird, especially the blobs
SS1619739995276 no, no and it was a really interesting experiment
SS1619740006087 None
SS1619740007669 no issues
SS1619740009815 on my part, there were no issues
SS1619740017232 Not laggy at all
SS1619740020203 No lag during the experiment
SS1619740022277 no. Really good animations
SS1619740024427 No
SS1619740029888 No issue whatsoever
SS1619740032953 i did not encounter any issue
SS1619740033074 Everything was good ! Good luck with the experimentation
SS1619740036877 No, the experiment went flawlessly
SS1619740037035 No
SS1619740041688 All good
SS1619740046290 Everything was perfect
SS1619740053610 I did not encounter any issues.
SS1619740055836 all animations are fine
SS1619740056133 no
SS1619740056399 All very smooth.
SS1619740057448 Got the mood to play some Spore again :)
SS1619740057558 no
SS1619740061593 cute
SS1619740068829 everything was fine
SS1619740069780 Everything was fine.
SS1619740071110 there was one unskippable animation that i think transitioned to a skippable one…i didnt notice the swap so i unintentionally sat with the skippable one for a long time
SS1619740071889 n/a
SS1619740073432 No major issues. The animation changed sizes throughout the experiment.
SS1619740074027 No
SS1619740082049 NO
SS1619740082158 no problem
SS1619740088534 no
SS1619740091060 I really liked this study
SS1619740091474 no but i found nice you used spore creatures
SS1619740092344 Sometimes the animation wouldn’t stop so this took me waaay longer than intended
SS1619740095592 No. Thanks for the study. Good luck
SS1619740096922 Everything went well
SS1619740097462 none
SS1619740100683 No
SS1619740102026 Everything was fine
SS1619740104294 the pictures where the animations was furthest away was the best ones in quality.
SS1619740105161 All good!
SS1619740107239 No lag, everything ok.
SS1619740107605 I did not notice any lag, the animation had low fps I guess.
SS1619740108345 No
SS1619740111250 some of the creatures were a little scary :(
SS1619740116547 No, the animation was fluid
SS1619740119977 No, everything went well
SS1619740126590 no
SS1619740126736 I did not face any issues
SS1619740127220 the time to images dissapear was too long
SS1619740129499 I had no problems, everything went well.
SS1619740143704 Any problem
SS1619740152126 looks like the creatures from the game Spore
SS1619740157373 sometimes the arrow down didnt work or worked late
SS1619740178247 No issues encountered
SS1619740197972 everything fine :)
SS1619740209264 It was laggy and the keyboard reaction was low
SS1619740212383 The animation was flawless, no lag whatsoever
SS1619740239084 no
SS1619740244617 No
SS1619740264980 nothing, is war a good experiment no laggy very clear !
SS1619740299665 I didn’t like most of the animations, it was a little bit scary for a child
SS1619740317883 No
SS1619740338605 no
SS1619740396232 As I am a gamer, I assume that all the creatures were created in “Spore” game
SS1619740432849 Simple yet interesting study. You kept the questions simple and straightforward. that’s nice
SS1619740442234 no
SS1619740641851 no, it was okay
SS1619742997298 No issues, no lags. One comment, but it is sort of subjective: if I knew why some objects are basic and others are complex, maybe I would have been more useful in the research feedback. However, it is only how I see it.
SS1619743504951 it was pretty chill
SS1619743511856 The animation wasn’t laggy. However, it was strange to understand when the creatures would disappear or not
SS1619743523358 NO

Descriptive Info

N = 200

RT_data %>% 
  distinct(subject) %>% 
  count()
## # A tibble: 1 x 1
##       n
##   <int>
## 1   200
# reorder
RT_data$trial_complexity = factor(RT_data$trial_complexity, levels=c('simple', 'complex'))
RT_data$item_type = factor(RT_data$item_type, levels=c('background', 'similar deviant', 'dissimilar deviant'))

demographic

age

demog_data %>% 
  ggplot(aes(x = as.numeric(age))) + 
  geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ethnicity

demog_data %>% 
  ggplot(aes(x = ethnicity)) + 
  geom_histogram(stat = "count") + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
## Warning: Ignoring unknown parameters: binwidth, bins, pad

Gender

demog_data %>% 
  ggplot(aes(x = gender)) + 
  geom_histogram(stat = "count") + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
## Warning: Ignoring unknown parameters: binwidth, bins, pad

education

demog_data %>% 
  ggplot(aes(x = education)) + 
  geom_histogram(stat = "count") + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
## Warning: Ignoring unknown parameters: binwidth, bins, pad

RT raw

overall

RT_data %>% 
   ggplot(aes(x = rt)) + 
  geom_histogram() + 
  scale_x_log10()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

by trial type

RT_data %>% 
   ggplot(aes(x = rt)) + 
  geom_histogram() + 
  scale_x_log10() + 
  facet_wrap(~trial_type)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

trial type and block

RT_data %>% 
   ggplot(aes(x = rt)) + 
  geom_histogram() + 
  scale_x_log10() + 
  facet_grid(block_type~trial_type)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

by trial complexity

RT_data %>% 
  ggplot(aes(x = rt)) + 
  geom_histogram() + 
  scale_x_log10() + 
  facet_wrap(~trial_complexity)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

by block type

RT_data %>% 
   ggplot(aes(x = rt)) + 
  geom_histogram() + 
  scale_x_log10() + 
  facet_wrap(~block_type)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

by exposure type

RT_data %>% 
   ggplot(aes(x = rt)) + 
  geom_histogram() + 
  scale_x_log10() + 
  facet_wrap(~exposure_type)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

by item id

simple

RT_data %>% 
  filter(trial_complexity == "simple") %>% 
   ggplot(aes(x = rt)) + 
  geom_histogram() + 
  scale_x_log10() + 
  facet_wrap(~item_id)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

complex

RT_data %>% 
  filter(trial_complexity == "complex") %>% 
   ggplot(aes(x = rt)) + 
  geom_histogram() + 
  scale_x_log10() + 
  facet_wrap(~item_id)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Similarity ratings

Raw

similarity_data %>% 
  ggplot(aes(x = rating))+ 
  geom_histogram(bins = 30)

complexity and similarity

ahhhhhhhhh

similarity_data <- similarity_data %>% 
  mutate(
    complexity = case_when(
      grepl("complex", stimulus_left) | grepl("complex", stimulus_right) ~ "complex", 
      grepl("simple", stimulus_right) | grepl("simple", stimulus_right) ~ "simple"
    ), 
    stimulus_left_number = as.numeric(str_extract(stimulus_left, "[[:digit:]]+")), 
    stimulus_right_number = as.numeric(str_extract(stimulus_right, "[[:digit:]]+")), 
    similarity = case_when(
      stimulus_left_number == stimulus_right_number ~ "similar", 
      TRUE ~ "dissimilar"
    )
  )

similarity_data %>% 
  ggplot(aes(x = similarity, y= rating)) + 
  geom_point(alpha = 0.1, 
             position = position_jitter(width = 0.3)) + 
   stat_summary(fun.data = "mean_cl_boot") + 
  facet_wrap(~complexity)

complexity

Raw

complexity_data %>% 
  ggplot(aes(x = rating))+ 
  geom_histogram(bins = 30)

by intuitive complexity

complexity_data <- complexity_data %>% 
  mutate(
    complexity = case_when(
      grepl("complex", stimulus) ~ "complex", 
      grepl("simple", stimulus) ~ "simple"
    )
  )

complexity_data %>% 
  ggplot(aes(x = complexity, y = rating)) + 
  geom_point(alpha = 0.1, 
             position = position_jitter(width = 0.3)) + 
   stat_summary(fun.data = "mean_cl_boot") 

zoom in on the effect of forced look duration

RT on the first trial (blank space confounding factor? )

RT_data  %>%  
  filter(trial_number == 1) %>% 
ggplot(
       aes(x=exposure_type, y=log(rt), colour=exposure_type)) + 
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .2)) + 
  langcog::scale_color_solarized(name = "Item Type") + 
  theme(legend.position = "bottom") + 
  #facet_wrap(~trial_complexity)+
  ylab("log RT (ms) at the first trial") + 
  xlab("exposure type") 

look at the dynamics of the first trial self paced and the second trial

exposure_comparison_df <- RT_data  %>%  
  mutate(
    exposure_trial_comparison = case_when(
      trial_number == 2 & exposure_type == "forced_long" ~ "forced_long_second", 
      trial_number == 2 & exposure_type == "forced_short" ~ "forced_short_second", 
      trial_number == 1 & exposure_type == "self_paced" ~ "self_paced_first",
      TRUE ~ "irrelevant"
    )
  ) %>% 
  filter(exposure_trial_comparison != "irrelevant")

exposure_comparison_df %>% 
  ggplot(
       aes(x = exposure_trial_comparison, 
           y = log(looking_time), colour=item_type)) +
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .2)) + 
  geom_hline(yintercept = exposure_comparison_df %>% filter(exposure_trial_comparison == "self_paced_first") %>% summarise(mean_lt = mean(log(looking_time))) %>% select(mean_lt) %>%  pull()) + 
  langcog::scale_color_solarized(name = "Item Type") + 
  #facet_wrap(~half)+
  #theme(legend.position = "bottom") + 
  ylab("log looking time (ms) at the second trial for forced block") + 
  xlab("exposure type") + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))

exposure_comparison_df %>% 
ggplot(
       aes(x = block_number, 
           y = log(looking_time), colour=trial_complexity)) +
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .2)) + 
  langcog::scale_color_solarized(name = "Item Type") + 
  facet_wrap(~item_type)+
  #theme(legend.position = "bottom") + 
  ylab("log looking time (ms) at the second trial for forced block") + 
  xlab("exposure type") + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))

complexity?

exposure_comparison_df %>% 
  filter(exposure_trial_comparison != "self_paced_first") %>% 
ggplot(
       aes(x = block_number, 
           y = log(looking_time), colour=exposure_type)) +
  geom_smooth(se = FALSE)+
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .2)) + 
  langcog::scale_color_solarized(name = "Item Type") + 
  facet_grid(trial_complexity~item_type)+
  #theme(legend.position = "bottom") + 
  ylab("log looking time (ms) at the second trial for forced block") + 
  xlab("exposure type") + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning: Removed 1 rows containing missing values (geom_segment).

Within-block change plotting

RT

ggplot(RT_data, 
       aes(x=trial_number, y=log(rt), colour=item_type)) + 
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .2)) + 
  geom_smooth(method = "lm", 
              formula = y ~ I(exp(1)**(-x)), se = FALSE) + 
  facet_grid(exposure_type~trial_complexity) +
  langcog::scale_color_solarized(name = "Item Type") + 
  theme(legend.position = "bottom") + 
  ylab("log RT (ms)") + 
  xlab("Trial Number") 

Looking time

models

prunned_model <-  lmer(log(looking_time) ~ I((exp(1)**(-trial_number))) * item_type * trial_complexity * exposure_type + (1|subject), 
                    data = RT_data)
summary(prunned_model)$coef %>% knitr::kable(digits = 2)
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 7.81 0.05 385.73 159.92 0.00
I((exp(1)^(-trial_number))) 4.71 0.14 12044.59 33.44 0.00
item_typedissimilar deviant 0.26 0.06 12052.30 4.20 0.00
trial_complexitycomplex -0.05 0.04 12047.03 -1.26 0.21
exposure_typeforced_short 0.38 0.04 12047.33 9.99 0.00
exposure_typeself_paced 0.03 0.04 12047.09 0.71 0.48
I((exp(1)^(-trial_number))):item_typedissimilar deviant -2.83 0.83 12051.88 -3.42 0.00
I((exp(1)^(-trial_number))):trial_complexitycomplex 0.15 0.20 12044.53 0.74 0.46
item_typedissimilar deviant:trial_complexitycomplex 0.12 0.09 12053.75 1.40 0.16
I((exp(1)^(-trial_number))):exposure_typeforced_short -9.61 0.20 12044.64 -48.39 0.00
I((exp(1)^(-trial_number))):exposure_typeself_paced -3.18 0.20 12044.70 -15.92 0.00
item_typedissimilar deviant:exposure_typeforced_short -0.49 0.09 12052.97 -5.67 0.00
item_typedissimilar deviant:exposure_typeself_paced -0.03 0.09 12052.12 -0.34 0.74
trial_complexitycomplex:exposure_typeforced_short 0.18 0.05 12047.20 3.30 0.00
trial_complexitycomplex:exposure_typeself_paced 0.14 0.05 12047.10 2.57 0.01
I((exp(1)^(-trial_number))):item_typedissimilar deviant:trial_complexitycomplex 0.89 1.19 12053.62 0.75 0.45
I((exp(1)^(-trial_number))):item_typedissimilar deviant:exposure_typeforced_short 9.93 1.16 12051.72 8.58 0.00
I((exp(1)^(-trial_number))):item_typedissimilar deviant:exposure_typeself_paced 2.13 1.17 12052.83 1.81 0.07
I((exp(1)^(-trial_number))):trial_complexitycomplex:exposure_typeforced_short -0.40 0.28 12044.68 -1.41 0.16
I((exp(1)^(-trial_number))):trial_complexitycomplex:exposure_typeself_paced 0.32 0.28 12044.64 1.12 0.26
item_typedissimilar deviant:trial_complexitycomplex:exposure_typeforced_short 0.04 0.12 12053.46 0.33 0.74
item_typedissimilar deviant:trial_complexitycomplex:exposure_typeself_paced -0.10 0.12 12054.12 -0.83 0.41
I((exp(1)^(-trial_number))):item_typedissimilar deviant:trial_complexitycomplex:exposure_typeforced_short -0.65 1.68 12052.88 -0.39 0.70
I((exp(1)^(-trial_number))):item_typedissimilar deviant:trial_complexitycomplex:exposure_typeself_paced -0.29 1.67 12054.61 -0.18 0.86
prunned_model_second_trial <-  lmer(log(looking_time) ~ exposure_type * trial_complexity + (1|subject), data = RT_data %>% filter(trial_number == 2))

summary(prunned_model_second_trial)$coeff %>% knitr::kable(digits = 2)
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 8.22 0.07 504.22 123.12 0.00
exposure_typeforced_short -0.03 0.06 2174.54 -0.39 0.69
exposure_typeself_paced -0.20 0.06 2174.34 -3.17 0.00
trial_complexitycomplex 0.02 0.06 2174.40 0.34 0.74
exposure_typeforced_short:trial_complexitycomplex 0.18 0.09 2174.36 1.96 0.05
exposure_typeself_paced:trial_complexitycomplex 0.19 0.09 2174.15 2.15 0.03

critical comparison

RT_data %>% 
  filter(trial_type == "background") %>% 
  filter(trial_number %in% c(1, 2)) %>% 
  ggplot(aes(x = trial_number, y = looking_time, colour = exposure_type)) + 
  stat_summary(fun.data = "mean_cl_boot", geom = "line", position = position_dodge(width = .1))  + 
  stat_summary(fun.data = "mean_cl_boot", geom = "pointrange", position = position_dodge(width = .1)) +
  langcog::scale_color_solarized(name = "Exposure Type") + 
  scale_x_continuous(breaks = seq(1,2,1)) + 
  facet_wrap(~trial_complexity)+
  theme_classic() + 
  xlab("Trial Number") + 
  ylab("Looking time (ms)") + 
  labs(title = "Looking time at critical trials (Second trial background only)")

RT_data %>% 
  filter((trial_number == 1 & item_type == "background") | 
           trial_number == 2 & item_type == "dissimilar deviant") %>% 
  ggplot(aes(x = trial_number, y = looking_time, colour = exposure_type)) + 
  stat_summary(fun.data = "mean_cl_boot", geom = "line", position = position_dodge(width = .1))  + 
  stat_summary(fun.data = "mean_cl_boot", geom = "pointrange", position = position_dodge(width = .1)) +
  langcog::scale_color_solarized(name = "Exposure Type") + 
  scale_x_continuous(breaks = seq(1,2,1)) + 
  facet_wrap(~trial_complexity)+
  theme_classic() + 
  xlab("Trial Number") + 
  ylab("Looking time (ms)") +
  labs(title = "Looking time at critical trials (Second trial deviants only)")

compare looking time at the second trial

RT_data %>% 
  filter(trial_number == 2) %>% 
  ggplot(aes(x = exposure_type, y = looking_time, color = item_type)) + 
  stat_summary(fun.data = "mean_cl_boot", geom = "pointrange", position = position_dodge(width = .1)) +
   langcog::scale_color_solarized(name = "Item Type") + 
  theme_classic() + 
  labs(title = "Looking time at the second trial")

ggplot(RT_data %>% filter(trial_number != 1), 
       aes(x=trial_number, y=log(looking_time), colour=item_type)) + 
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .2)) + 
  geom_smooth(method = "lm", 
              formula = y ~ I(exp(1)**(-x)), se = FALSE) + 
  facet_grid(~trial_complexity) +
  langcog::scale_color_solarized(name = "Item Type") + 
  theme(legend.position = "bottom") + 
  ylab("Looking time)") + 
  xlab("Trial Number") 

ggplot(RT_data %>% filter(trial_number != 1), 
       aes(x=trial_number, y=log(looking_time), colour=item_type)) + 
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .2)) + 
  geom_smooth(method = "lm", 
              formula = y ~ I(exp(1)**(-x)), se = FALSE) + 
  facet_grid(trial_complexity~exposure_type) +
  langcog::scale_color_solarized(name = "Item Type") + 
  theme(legend.position = "bottom") + 
  ylab("Looking time)") + 
  xlab("Trial Number") 

first block only

compare critical trials

exposure_comparison_df %>% 
  filter(block_number == 0) %>% 
  ggplot(
       aes(x = exposure_trial_comparison, 
           y = log(looking_time), colour=item_type)) +
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .2)) + 
  langcog::scale_color_solarized(name = "Item Type") + 
  facet_wrap(~trial_complexity)+
  #theme(legend.position = "bottom") + 
  ylab("log looking time (ms) at the second trial for forced block") + 
  xlab("exposure type") + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))

within block dynamic

ggplot(RT_data %>% filter(trial_number != 1) %>% filter(block_number == 0), 
       aes(x=trial_number, y=log(looking_time), colour=item_type)) + 
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .2)) + 
  geom_smooth(method = "lm", 
              formula = y ~ I(exp(1)**(-x)), se = FALSE) + 
  facet_grid(trial_complexity~exposure_type) +
  langcog::scale_color_solarized(name = "Item Type") + 
  theme(legend.position = "bottom") + 
  ylab("Looking time)") + 
  xlab("Trial Number") 
## Warning: Removed 1 rows containing missing values (geom_segment).

Across block

RT_data %>% 
  filter(trial_number != 1) %>% 
  mutate(block_number = block_number + 1) %>%  #block number starts with 0
ggplot(
       aes(x=block_number, y=log(looking_time), colour=trial_complexity)) + 
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .2)) + 
  geom_smooth(method = "lm", 
              formula = y ~ log(x), se = FALSE) + 
  facet_wrap(~exposure_type)+
  scale_x_continuous(breaks = seq(1, 12, 1))+
  langcog::scale_color_solarized(name = "Item Type") + 
  theme(legend.position = "bottom") + 
  theme_classic()+
  ylab("Looking time)") + 
  xlab("Block Number") + 
  labs("Across block looking time change (exclude first trial)")

some very exploratory stuff

temp_block_length <- RT_data %>% 
  mutate(temp_id = paste0(subject, block_number)) %>% 
  group_by(temp_id) %>% 
  summarise(n = max(trial_number))%>% 
  rename(block_length = n)


RT_data_block <- RT_data %>% 
  mutate(temp_id = paste0(subject, block_number)) %>% 
  left_join(temp_block_length, by = "temp_id")
ggplot(RT_data_block %>% filter(trial_number != 1), 
       aes(x=trial_number, y=log(looking_time), colour=item_type)) + 
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .2)) + 
  geom_smooth(method = "lm", 
              formula = y ~ I(exp(1)**(-x)), se = FALSE) + 
  facet_grid(block_length ~ exposure_type) +
  langcog::scale_color_solarized(name = "Item Type") + 
  theme(legend.position = "bottom") + 
  ylab("Looking time)") + 
  xlab("Trial Number") 
## Warning: Removed 2 rows containing missing values (geom_segment).
## Warning: Removed 1 rows containing missing values (geom_segment).

ggplot(RT_data_block %>% filter(trial_number != 1), 
       aes(x=trial_number, y=log(looking_time), colour=item_type)) + 
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .2)) + 
  geom_smooth(method = "lm", 
              formula = y ~ I(exp(1)**(-x)), se = FALSE) + 
  facet_grid(block_deviant_number~exposure_type) +
  langcog::scale_color_solarized(name = "Item Type") + 
  theme(legend.position = "bottom") + 
  ylab("Looking time)") + 
  xlab("Trial Number") 

what if we just look at the first deivant

RT_data_block %>% 
  filter(trial_number != 1) %>% 
  filter(trial_type_index == "background" | trial_type_index == "first_deviant") %>% 
ggplot(
       aes(x=trial_number, y=log(looking_time), colour=item_type)) + 
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .2)) + 
  geom_smooth(method = "lm", 
              formula = y ~ I(exp(1)**(-x)), se = FALSE) + 
  facet_grid(~exposure_type) +
  langcog::scale_color_solarized(name = "Item Type") + 
  theme(legend.position = "bottom") + 
  ylab("Looking time)") + 
  xlab("Trial Number") 

how about throwing out all the background trials after the first deviant?

RT_data %>% 
  group_by(subject, block_number) %>% 
  filter(
    is.na(first_dev_position) |
    trial_number < first_dev_position | 
    trial_number ==  first_dev_position
  ) %>% 
  filter(trial_number != 1) %>% 
ggplot(
       aes(x=trial_number, y=log(looking_time), colour=item_type)) + 
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .2)) + 
  geom_smooth(method = "lm", 
              formula = y ~ I(exp(1)**(-x)), se = FALSE) + 
  facet_grid(~exposure_type) +
  langcog::scale_color_solarized(name = "Item Type") + 
  theme(legend.position = "bottom") + 
  ylab("Looking time)") + 
  xlab("Trial Number")