library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.6     ✓ dplyr   1.0.8
## ✓ tidyr   1.2.0     ✓ stringr 1.4.0
## ✓ readr   2.1.2     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(here)
## here() starts at /Users/caoanjie/Desktop/projects/MB5_AP/data_analysis
library(jsonlite)
## 
## Attaching package: 'jsonlite'
## The following object is masked from 'package:purrr':
## 
##     flatten
lt_df <- read_csv(here("data/02_processed_lt_data.csv"))
## Rows: 228843 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): subject, complexity, gaze_location, phase, gaze_location_type
## dbl (8): window_width, window_height, block_number, exposure_time, x, y, t, ...
## 
## ℹ 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.
rating_df <- read_csv(here("data/02_processed_rating_data.csv"))
## Rows: 984 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): subject, complexity, left_stimulus_type, right_stimulus_type
## dbl (3): adjusted_rating, left_exposure_time, right_exposure_time
## 
## ℹ 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.

final sample size

lt_df %>% 
  distinct(subject) %>% 
  count()
## # A tibble: 1 × 1
##       n
##   <int>
## 1    82

dwell time at familiarization stage

lt_df %>% 
 filter(phase == "fam") %>% 
  group_by(block_number, gaze_location, exposure_time,
           complexity, subject) %>% 
  summarise(sum_dwell_time = sum(dwell_time, na.rm = TRUE)) %>% 
  ggplot(aes(x = gaze_location, 
              y = sum_dwell_time, 
             color = complexity)) + 
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .3)) + 
  geom_jitter(width = 0.2, alpha = .1) + 
  theme_classic() + 
facet_grid(~exposure_time)
## `summarise()` has grouped output by 'block_number', 'gaze_location',
## 'exposure_time', 'complexity'. You can override using the `.groups` argument.

dwell time at pref phase

raw looking time

lt_df %>% 
  filter(phase == "pref") %>% 
  group_by(block_number, exposure_time,
           complexity, gaze_location_type, subject) %>% 
  summarise(sum_dwell_time = sum(dwell_time, na.rm = TRUE)) %>% 
  filter(gaze_location_type != "not_on_target") %>% 
  ggplot(aes(x = gaze_location_type, 
              y = sum_dwell_time, 
             color = complexity)) + 
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .3)) + 
  geom_jitter(width = 0.2, alpha = .1) + 
  theme_classic() + 
facet_grid(~exposure_time)
## `summarise()` has grouped output by 'block_number', 'exposure_time',
## 'complexity', 'gaze_location_type'. You can override using the `.groups`
## argument.

lt_df <- lt_df %>% 
  filter(phase == "pref") %>% 
  group_by(block_number, exposure_time,
           complexity, gaze_location_type, subject) %>% 
  summarise(sum_dwell_time = sum(dwell_time, na.rm = TRUE)) %>% 
  pivot_wider(names_from = gaze_location_type, 
              values_from = sum_dwell_time) %>% 
  mutate(familiar = ifelse(is.na(familiar), 0, familiar), 
         novel = ifelse(is.na(novel), 0, novel)) %>% 
  mutate(novelty_looking_proportion = novel / (familiar+novel))
## `summarise()` has grouped output by 'block_number', 'exposure_time',
## 'complexity', 'gaze_location_type'. You can override using the `.groups`
## argument.

proportion

lt_df %>% 
  ggplot(aes(x = as.factor(exposure_time), y = novelty_looking_proportion, color = complexity)) + 
  geom_jitter(alpha = .3, width = .2) + 
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .2)) + 
  geom_hline(yintercept = 0.5) + 
  theme_classic() 
## Warning: Removed 12 rows containing non-finite values (stat_summary).
## Warning: Removed 12 rows containing missing values (geom_point).

looking at by block trend?

lt_df %>% 
  ggplot(aes(x = as.factor(exposure_time), y = novelty_looking_proportion, color = complexity)) + 
  geom_jitter(alpha = .3, width = .2) + 
  stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .2)) + 
  geom_hline(yintercept = 0.5) + 
  facet_wrap(~block_number) + 
  theme_classic() 
## Warning: Removed 12 rows containing non-finite values (stat_summary).
## Warning: Removed 12 rows containing missing values (geom_point).

ratings

0 is no pref, negative represents the preference for familiar, positive represents the preference for novel

rating_df %>% 
  mutate(exposure_time = ifelse(left_exposure_time == 0, right_exposure_time, left_exposure_time)) %>% 
  ggplot(aes(x = as.factor(exposure_time), 
              y = adjusted_rating, 
              color = complexity)) + 
    geom_jitter(alpha = .3) + 
    stat_summary(fun.data = "mean_cl_boot", position = position_dodge(width = .2)) + 
  geom_hline(yintercept = 0) + 
  theme_classic()