Session 1 preprocessing

details.ellrep = file.info(list.files(path = "C:\\Users\\saptaf1\\Documents local\\ellrep-ti-task\\session1\\data",     
                       pattern = "*.csv", full.names = TRUE)) 
details.filtered.ellrep <- details.ellrep

data_all <- rownames(details.filtered.ellrep) %>%
  map_df(~read_csv(.x, col_types = cols(slider.response = col_character(),slider.rt = col_character(),fixation_cross.stopped = col_character(),stopFeedback.started =  col_character(),blockPerformance.started = col_character(), block_avg=col_number(), block_avg_middlepair=col_number())))
## New names:
## * `` -> `...51`
session1.ellrep <- bind_rows(data_all) %>% mutate(stimCategory = case_when(
                                                                                          grepl(pattern = "faces", x = Image1) ~ "faces",
                                                                                          grepl(pattern = "objects", x = Image1) ~ "objects",
                                                                                          grepl(pattern = "scenes", x = Image1) ~ "scenes")) %>% filter(!is.na(Rank1))
## New names:
## * `...51` -> `...129`
session1.ellrep %>% group_by(participant) %>% summarise(blockcount = ifelse(sum(!is.na(key_resp_learning.keys))/10>10,10,sum(!is.na(key_resp_learning.keys)/10))) %>% filter(blockcount>=30) -> avgBlocks
hist(avgBlocks$blockcount)

session1.ellrep %>% group_by(participant) %>% summarise(blockcount = sum(!is.na(key_resp_learning.keys))/10) %>% filter(blockcount<=10)-> tmp



session1.avgs.ellrep <- session1.ellrep %>% select(participant,group, session, stimCategory, key_resp_im.corr, Rank1, Rank2) %>% mutate(cRank= paste0(pmin(Rank1,Rank2),pmax(Rank1,Rank2))) %>% group_by(participant,group, session,cRank,stimCategory) %>% summarise_each(funs(mean(key_resp_im.corr, na.rm = TRUE))) %>% filter(!is.na(session)) %>% select(-Rank1,-Rank2)

#immediate recall performance
print(head(session1.avgs.ellrep))
## # A tibble: 6 x 6
## # Groups:   participant, group, session, cRank [6]
##   participant group session cRank stimCategory key_resp_im.corr
##   <chr>       <chr>   <dbl> <chr> <chr>                   <dbl>
## 1 AFERQVTO    wake        1 12    faces                   0.52 
## 2 AFERQVTO    wake        1 23    faces                   0.52 
## 3 AFERQVTO    wake        1 34    faces                   0.52 
## 4 AFERQVTO    wake        1 45    faces                   0.52 
## 5 AFERQVTO    wake        1 56    faces                   0.5  
## 6 BLGZDEFW    wake        1 12    faces                   0.875

Session 2 preprocessing

details.ellrep = file.info(list.files(path = "C:\\Users\\saptaf1\\Documents local\\ellrep-ti-task\\session2\\data",     
                       pattern = "*.csv", full.names = TRUE))
details.filtered.ellrep <- details.ellrep

data_all <- rownames(details.filtered.ellrep) %>%
  map_df(~read_csv(.x, col_types = cols(slider.response = col_character(),slider.rt = col_character(),fixation_cross.stopped = col_character(),stopFeedback.started =  col_character(),blockPerformance.started = col_character(), block_avg=col_number(), block_avg_middlepair=col_number())))

session2.ellrep <- bind_rows(data_all) %>% mutate(stimCategory = case_when(
                                                                                          grepl(pattern = "faces", x = Image1) ~ "faces",
                                                                                          grepl(pattern = "objects", x = Image1) ~ "objects",
                                                                                          grepl(pattern = "scenes", x = Image1) ~ "scenes")) %>% filter(!is.na(Rank1))

# session2.ellrep %>% group_by(participant) %>% summarise(blockcount = ifelse(sum(!is.na(key_resp_learning.keys))/10>10,10,sum(!is.na(key_resp_learning.keys)/10))) %>% filter(blockcount>=30) -> avgBlocks
# hist(avgBlocks$blockcount)

# session2.ellrep %>% group_by(participant) %>% summarise(blockcount = sum(!is.na(key_resp_learning.keys))/10) %>% filter(blockcount<=10)-> tmp



session2.avgs.ellrep <- session2.ellrep %>% select(participant,group, session, stimCategory, key_resp_im.corr, Rank1, Rank2) %>% mutate(cRank= paste0(pmin(Rank1,Rank2),pmax(Rank1,Rank2))) %>% group_by(participant,group, session,cRank,stimCategory) %>% summarise_each(funs(mean(key_resp_im.corr, na.rm = TRUE))) %>% filter(!is.na(session)) %>% select(-Rank1,-Rank2)

#for some reason there are 2s and 3s in this column.. investigate
session2.avgs.ellrep$session <-2

#immediate recall performance
print(length(unique(session2.avgs.ellrep$participant)))
## [1] 38
#immediate recall performance
print(head(session2.avgs.ellrep))
## # A tibble: 6 x 6
## # Groups:   participant, group, session, cRank [6]
##   participant group session cRank stimCategory key_resp_im.corr
##   <chr>       <chr>   <dbl> <chr> <chr>                   <dbl>
## 1 AFERQVTO    wake        2 12    faces                     0.5
## 2 AFERQVTO    wake        2 16    faces                     0.5
## 3 AFERQVTO    wake        2 23    faces                     0.5
## 4 AFERQVTO    wake        2 24    faces                     0.5
## 5 AFERQVTO    wake        2 25    faces                     0.5
## 6 AFERQVTO    wake        2 34    faces                     0.5
library(qualtRics)

# qualtrics_api_credentials(api_key = "ysZ6HezYt3Wc43hoFcwSG82LoMSbFHTqb0x1FWdW", 
#                           base_url = "cardiffunipsych.fra1.qualtrics.com",
#                           install = TRUE)


awareness_survey.ellrep <-fetch_survey(surveyID = "SV_7armt1volf3zVfE", 
                         verbose = TRUE)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%
## 
## -- Column specification --------------------------------------------------------
## cols(
##   .default = col_double(),
##   StartDate = col_datetime(format = ""),
##   EndDate = col_datetime(format = ""),
##   Status = col_character(),
##   IPAddress = col_character(),
##   Finished = col_logical(),
##   RecordedDate = col_datetime(format = ""),
##   ResponseId = col_character(),
##   RecipientLastName = col_character(),
##   RecipientFirstName = col_character(),
##   RecipientEmail = col_character(),
##   ExternalReference = col_character(),
##   LocationLatitude = col_character(),
##   LocationLongitude = col_character(),
##   DistributionChannel = col_character(),
##   UserLanguage = col_character(),
##   Q2 = col_character(),
##   Q4 = col_character(),
##   Q5 = col_character(),
##   Q6 = col_character(),
##   Q7 = col_character()
##   # ... with 12 more columns
## )
## i Use `spec()` for the full column specifications.
## 'StartDate', 'EndDate', and 'RecordedDate' were converted without a specific timezone
## * To set a timezone, visit https://www.qualtrics.com/support/survey-platform/managing-your-account/
## * Timezone information is under 'User Settings'
## * See https://api.qualtrics.com/instructions/docs/Instructions/dates-and-times.md for more
s1start.ellrep <-fetch_survey(surveyID = "SV_6lJ6YCFlcjdao8S", 
                         verbose = TRUE)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%
## 
## -- Column specification --------------------------------------------------------
## cols(
##   StartDate = col_datetime(format = ""),
##   EndDate = col_datetime(format = ""),
##   Status = col_character(),
##   Progress = col_double(),
##   `Duration (in seconds)` = col_double(),
##   Finished = col_logical(),
##   RecordedDate = col_datetime(format = ""),
##   ResponseId = col_character(),
##   DistributionChannel = col_character(),
##   UserLanguage = col_character(),
##   Q1_1 = col_double(),
##   code = col_character(),
##   group = col_character()
## )
s1start.starttime.ellrep <- s1start.ellrep %>% group_by(code) %>% summarise(starttime=max(EndDate))

s1finish.ellrep <-fetch_survey(surveyID = "SV_2rTYD8fdqbPRWJM", 
                         verbose = TRUE)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%
## 
## -- Column specification --------------------------------------------------------
## cols(
##   .default = col_character(),
##   StartDate = col_datetime(format = ""),
##   EndDate = col_datetime(format = ""),
##   Progress = col_double(),
##   `Duration (in seconds)` = col_double(),
##   Finished = col_logical(),
##   RecordedDate = col_datetime(format = "")
## )
## i Use `spec()` for the full column specifications.
s1finish.starttime.ellrep <- s1finish.ellrep %>% group_by(code) %>% summarise(endtime=max(EndDate))


s1start.starttime.ellrep %>% left_join(s1finish.starttime.ellrep) %>% mutate(total = endtime-starttime) %>% filter(code %in% awareness_survey.ellrep$code ) -> totalTimes
## Joining, by = "code"
s2start.ellrep <-fetch_survey(surveyID = "SV_9phc9enBGE9abbg", 
                         verbose = TRUE)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%
## 
## -- Column specification --------------------------------------------------------
## cols(
##   StartDate = col_datetime(format = ""),
##   EndDate = col_datetime(format = ""),
##   Status = col_character(),
##   Progress = col_double(),
##   `Duration (in seconds)` = col_double(),
##   Finished = col_logical(),
##   RecordedDate = col_datetime(format = ""),
##   ResponseId = col_character(),
##   DistributionChannel = col_character(),
##   UserLanguage = col_character(),
##   Q1_1 = col_double(),
##   code = col_character(),
##   group = col_character()
## )
s2start.starttime.ellrep <- s2start.ellrep %>% group_by(code) %>% summarise(starttime=max(EndDate))

s2finish.ellrep <-fetch_survey(surveyID = "SV_7armt1volf3zVfE", 
                         verbose = TRUE)
## Found an earlier download for survey with id SV_7armt1volf3zVfE. Loading this file.
## Set 'force_request' to TRUE if you want to override this.
s2finish.starttime.ellrep <- s2finish.ellrep %>% group_by(code) %>% summarise(endtime=max(EndDate))

s2start.starttime.ellrep %>% left_join(s2finish.starttime.ellrep) %>% mutate(total = endtime-starttime) %>% filter(code %in% awareness_survey.ellrep$code ) -> totalTimes
## Joining, by = "code"
#check whether time between S1.end and S2.start is approx 12h
s2start.starttime.ellrep %>% left_join(s1finish.starttime.ellrep) %>% mutate(total = difftime(starttime, endtime, units='hours')) %>% filter(code %in% awareness_survey.ellrep$code ) -> totaltimebetweensessions
## Joining, by = "code"
hist(as.numeric(totaltimebetweensessions$total))

awareness_survey.ellrep %>% select(code,SC0) %>% rename("awareness"="SC0") -> awareness_score.ellrep

hist(awareness_score.ellrep$awareness)

ellrep.lab.learning <- read_csv("lorena-ti-pilot-ellrep/Learning_Beh2.csv") %>% filter(Condition=="pre")
## Rows: 8730 Columns: 11
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr (7): ID, Group, Condition, Pair, Stim, session, PairType
## dbl (4): acc, RT, Distance, Block
## 
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
ellrep.lab.tmp <- read_delim("lorena-ti-pilot-ellrep/T_premises_pre - copia.csv",delim =';')
## Rows: 2880 Columns: 22
## -- Column specification --------------------------------------------------------
## Delimiter: ";"
## chr (16): ID_S1, Group_S1, Condition_S1, RT_S1, Pair_S1, Stim_S1, session_S1...
## dbl  (6): acc_S1, Distance_S1, Block_S1, acc_S2, Distance_S2, Block_S2
## 
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
ellrep.lab.tmp %>%  pivot_longer(
    cols = contains("_"), 
    names_to = c('.value', 'session'),
    values_drop_na = TRUE,
    names_pattern = '(.*)\\_(S\\d+)',
    names_repair = "unique"
  ) %>% rename(session = "session...1") %>% select(-session...9) -> ellrep.lab.tmp 
## New names:
## * `session` -> `session...1`
## * `session` -> `session...9`
ellrep.lab <- rbind(ellrep.lab.tmp ,read_delim("lorena-ti-pilot-ellrep/T_inferences_pre - copia.csv",delim =';'),read_delim("lorena-ti-pilot-ellrep/T_anchor_pre - copia.csv",delim =';'))
## Rows: 1728 Columns: 11
## -- Column specification --------------------------------------------------------
## Delimiter: ";"
## chr (8): ID, Group, Condition, RT, Pair, Stim, session, PairType
## dbl (3): acc, Distance, Block
## 
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 576 Columns: 11
## -- Column specification --------------------------------------------------------
## Delimiter: ";"
## chr (8): ID, Group, Condition, RT, Pair, Stim, session, PairType
## dbl (3): acc, Distance, Block
## 
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
ellrep.lab %>% rename(participant=ID, group=Group, pair=Pair, pairType=PairType,stimCategory=Stim) %>% mutate(session = factor( readr::parse_number(as.character(session))),stimCategory = ifelse(stimCategory=="F","faces",ifelse(stimCategory=="O","objects","scenes")), pairType=tolower(pairType)) %>% group_by(participant,session,group,pairType,pair,stimCategory) %>% summarise(corr=mean(acc)) -> combined.ellrep.lab
## `summarise()` has grouped output by 'participant', 'session', 'group',
## 'pairType', 'pair'. You can override using the `.groups` argument.
library(raincloudplots)
library(ggplot2)
library(cowplot)
library(dplyr)
library(readr)
library(forcats)
library(PupillometryR) #for geom_flat_violin
## Warning: package 'PupillometryR' was built under R version 4.1.3
## Loading required package: rlang
## 
## Attaching package: 'rlang'
## 
## The following object is masked from 'package:gtools':
## 
##     chr
## 
## The following objects are masked from 'package:purrr':
## 
##     %@%, as_function, flatten, flatten_chr, flatten_dbl, flatten_int,
##     flatten_lgl, flatten_raw, invoke, splice
combined.ellrep.lab$pairType <- factor(combined.ellrep.lab$pairType, levels = c("premise", "inference", "anchor"))


ggplot(combined.ellrep.lab, aes(x = session, y = corr, fill = group)) +
  geom_flat_violin(aes(fill = group),position = position_nudge(x = .1, y = 0), adjust = 1.5, trim = FALSE, alpha = .5, colour = NA)+
  geom_point(aes(x = session, y = corr, colour = group),position = position_jitter(width = .05), size = .25, shape = 20)+
  geom_boxplot(aes(x = session, y = corr, fill = group),outlier.shape = NA, alpha = .5, width = .1, colour = "black")+
  stat_summary(aes(session,corr, group = group, colour = group),geom = "line", linetype = 3, position = position_nudge(x = .1, y = 0) )+  
  stat_summary(aes(session,corr, group = group, colour = group),geom = "point", shape = 18, position = position_nudge(x = .1, y = 0))+
  stat_summary(aes(session,corr, group = group, colour = group),geom = "errorbar",width = .05,position = position_nudge(x = .1, y = 0))+
  scale_colour_brewer(palette = "Dark2")+
  scale_fill_brewer(palette = "Dark2")+ 
  ggtitle("Performance split by pairtype (lab)") + facet_wrap(~pairType, scales = "free_x")
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

ggplot(combined.ellrep.lab, aes(x = interaction(pair, session), y = corr, fill = group)) +
  geom_flat_violin(aes(fill = group),position = position_nudge(x = .1, y = 0), adjust = 1.5, trim = FALSE, alpha = .5, colour = NA)+
  geom_point(aes(x = interaction(pair, session), y = corr, colour = group),position = position_jitter(width = .05), size = .25, shape = 20)+
  geom_boxplot(aes(x = interaction(pair, session), y = corr, fill = group),outlier.shape = NA, alpha = .5, width = .1, colour = "black")+
  stat_summary(aes(interaction(pair, session),corr, group = group, colour = group),geom = "line", linetype = 3,position = position_nudge(x = .1, y = 0))+  
  stat_summary(aes(interaction(pair, session),corr, group = group, colour = group),geom = "point", shape = 18, position = position_nudge(x = .1, y = 0))+
  stat_summary(aes(interaction(pair, session),corr, group = group, colour = group),geom = "errorbar",width = .05, position = position_nudge(x = .1, y = 0))+
  scale_colour_brewer(palette = "Dark2")+
  scale_fill_brewer(palette = "Dark2")+ 
  ggtitle("Performance split by rank (lab)") + facet_wrap(~pairType, scales = "free_x")
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

combined.ellrep.online <- rbind(session1.avgs.ellrep,session2.avgs.ellrep) %>% filter(participant %in% awareness_survey.ellrep$code) %>% mutate(pairType= ifelse(cRank %in% c("12","23","34","45","56"),"premise", ifelse(cRank %in% c("24","25","35"), "inference","anchor"))) %>% rename( corr = key_resp_im.corr) %>% mutate(session = as.factor(session)) %>% mutate(pair=sapply(strsplit(paste(cRank),''), function(y) paste(LETTERS[as.numeric(y)], collapse = '')))

combined.ellrep.online$pairType <- factor(combined.ellrep.online$pairType, levels = c("premise", "inference", "anchor"))

summary <- combined.ellrep.online %>% group_by(session,group,pairType,pair) %>% summarise(meanPerf=mean(corr))
## `summarise()` has grouped output by 'session', 'group', 'pairType'. You can
## override using the `.groups` argument.
print(summary)
## # A tibble: 28 x 5
## # Groups:   session, group, pairType [8]
##    session group pairType pair  meanPerf
##    <fct>   <chr> <fct>    <chr>    <dbl>
##  1 1       sleep premise  AB       0.725
##  2 1       sleep premise  BC       0.75 
##  3 1       sleep premise  CD       0.508
##  4 1       sleep premise  DE       0.625
##  5 1       sleep premise  EF       0.742
##  6 1       wake  premise  AB       0.742
##  7 1       wake  premise  BC       0.672
##  8 1       wake  premise  CD       0.625
##  9 1       wake  premise  DE       0.664
## 10 1       wake  premise  EF       0.836
## # ... with 18 more rows
source("summarySE.R")
sumrepdat <- summarySE(combined.ellrep.online, measurevar = "corr", groupvars=c("group", "session","pairType"))


library(raincloudplots)
library(ggplot2)
library(cowplot)
library(dplyr)
library(readr)
library(forcats)
library(PupillometryR) #for geom_flat_violin


ggplot(combined.ellrep.online, aes(x = session, y = corr, fill = group)) +
  geom_flat_violin(aes(fill = group),position = position_nudge(x = .1, y = 0), adjust = 1.5, trim = FALSE, alpha = .5, colour = NA)+
  geom_point(aes(x = session, y = corr, colour = group),position = position_jitter(width = .05), size = .25, shape = 20)+
  geom_boxplot(aes(x = session, y = corr, fill = group),outlier.shape = NA, alpha = .5, width = .1, colour = "black")+
  stat_summary(aes(session,corr, group = group, colour = group),geom = "line", linetype = 3,position = position_nudge(x = .1, y = 0))+  
  stat_summary(aes(session,corr, group = group, colour = group),geom = "point", shape = 18,position = position_nudge(x = .1, y = 0))+
  stat_summary(aes(session,corr, group = group, colour = group),geom = "errorbar",width = .05,position = position_nudge(x = .1, y = 0))+
  scale_colour_brewer(palette = "Dark2")+
  scale_fill_brewer(palette = "Dark2")+ 
  ggtitle("Performance split by pairtype (online)") + facet_wrap(~pairType, scales = "free_x")
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

ggplot(combined.ellrep.online, aes(x = interaction(pair, session), y = corr, fill = group)) +
  geom_flat_violin(aes(fill = group),position = position_nudge(x = .1, y = 0), adjust = 1.5, trim = FALSE, alpha = .5, colour = NA)+
  geom_point(aes(x = interaction(pair, session), y = corr, colour = group),position = position_jitter(width = .05), size = .25, shape = 20)+
  geom_boxplot(aes(x = interaction(pair, session), y = corr, fill = group),outlier.shape = NA, alpha = .5, width = .1, colour = "black")+
  stat_summary(aes(interaction(pair, session),corr, group = group, colour = group),geom = "line", linetype = 3,position = position_nudge(x = .1, y = 0))+  
  stat_summary(aes(interaction(pair, session),corr, group = group, colour = group),geom = "point", shape = 18,position = position_nudge(x = .1, y = 0))+
  stat_summary(aes(interaction(pair, session),corr, group = group, colour = group),geom = "errorbar",width = .05,position = position_nudge(x = .1, y = 0))+
  scale_colour_brewer(palette = "Dark2")+
  scale_fill_brewer(palette = "Dark2")+ 
  ggtitle("Performance split by rank (online)") + facet_wrap(~pairType, scales = "free_x")
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

ellrep.master <- rbind(combined.ellrep.lab %>% mutate(location="lab"),combined.ellrep.online %>% ungroup()%>% mutate(location="online") %>% select(-cRank) )

ggplot(ellrep.master, aes(x = session, y = corr, fill = interaction(group,location))) +
  geom_flat_violin(aes(fill = interaction(group,location)),position = position_nudge(x = .1, y = 0), adjust = 1.5, trim = FALSE, alpha = .5, colour = NA)+
  geom_point(aes(x = session, y = corr, colour = interaction(group,location)),position = position_jitter(width = .05), size = .25, shape = 20)+
  geom_boxplot(aes(x = session, y = corr, fill = interaction(group,location)),outlier.shape = NA, alpha = .5, width = .1, colour = "black")+
  stat_summary(aes(session,corr, group = interaction(group,location), colour = interaction(group,location)),geom = "line", linetype = 3,position = position_nudge(x = .1, y = 0))+  
  stat_summary(aes(session,corr, group = interaction(group,location), colour = interaction(group,location)),geom = "point", shape = 18,position = position_nudge(x = .1, y = 0))+
  stat_summary(aes(session,corr, group = interaction(group,location), colour = interaction(group,location)),geom = "errorbar",width = .05,position = position_nudge(x = .1, y = 0))+
  scale_colour_brewer(palette = "Dark2")+
  scale_fill_brewer(palette = "Dark2")+ 
  ggtitle("Performance split by pairtype (combined)") + facet_wrap(~pairType, scales = "free_x")
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

ggplot(ellrep.master%>%filter(pairType=="inference"), aes(x = session, y = corr, fill = interaction(group,location))) +
  geom_flat_violin(aes(fill = interaction(group,location)),position = position_nudge(x = .1, y = 0), adjust = 1.5, trim = FALSE, alpha = .5, colour = NA)+
  geom_point(aes(x = session, y = corr, colour = interaction(group,location)),position = position_jitter(width = .05), size = .25, shape = 20)+
  geom_boxplot(aes(x = session, y = corr, fill = interaction(group,location)),outlier.shape = NA, alpha = .5, width = .1, colour = "black")+
  stat_summary(aes(session,corr, group = interaction(group,location), colour = interaction(group,location)),geom = "line", linetype = 3,position = position_nudge(x = .1, y = 0))+  
  stat_summary(aes(session,corr, group = interaction(group,location), colour = interaction(group,location)),geom = "point", shape = 18,position = position_nudge(x = .1, y = 0))+
  stat_summary(aes(session,corr, group = interaction(group,location), colour = interaction(group,location)),geom = "errorbar",width = .05,position = position_nudge(x = .1, y = 0))+
  scale_colour_brewer(palette = "Dark2")+
  scale_fill_brewer(palette = "Dark2")+ 
  ggtitle("Performance split by pairtype (combined)") + facet_grid(pairType~pair, scales = "free_x")
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

look at some stats for online and lab

Sleep-inference effect is driven largely by BE in both dataset - significant difference in BE (for lab data) - CE seems to trend toward lower than chance performance for some reason for online data

library(ggstatsplot)
## You can cite this package as:
##      Patil, I. (2021). Visualizations with statistical details: The 'ggstatsplot' approach.
##      Journal of Open Source Software, 6(61), 3167, doi:10.21105/joss.03167
## plot
ggbetweenstats(
  data  = combined.ellrep.online %>%filter(pairType=="inference"),
  x     = group,
  y     = corr,
  title = "Distribution of inferential performance between groups (online)"
)
## Adding missing grouping variables: `participant`, `session`, `cRank`

 grouped_ggbetweenstats(
      data  = combined.ellrep.online %>%filter(pairType=="inference"),
      x     = group,
      y     = corr,
      grouping.var = pair,
      annotation.args = list(title = "Distribution of inferential performance between groups split by pair (online)"),
 )

 ## plot
ggbetweenstats(
  data  = combined.ellrep.lab %>%filter(pairType=="inference"),
  x     = group,
  y     = corr,
  title = "Distribution of inferential performance between groups (lab)"
)
## Adding missing grouping variables: `participant`, `session`, `pairType`, `pair`

 grouped_ggbetweenstats(
      data  = combined.ellrep.lab %>%filter(pairType=="inference"),
      x     = group,
      y     = corr,
      grouping.var = pair,
      annotation.args = list(title = "Distribution of inferential performance between groups split by pair (lab)"),
 )

look at some stats for online and lab split by category

grouped_ggbetweenstats(
      data  = combined.ellrep.online %>%filter(pairType=="inference"),
      x     = group,
      y     = corr,
      grouping.var = stimCategory,
      annotation.args = list(title = "Distribution of inferential performance between groups split by pair (online)"),
 )

grouped_ggbetweenstats(
      data  = combined.ellrep.lab %>%filter(pairType=="inference"),
      x     = group,
      y     = corr,
      grouping.var = stimCategory,
      annotation.args = list(title = "Distribution of inferential performance between groups split by pair (lab)"),
 )

look at some stats for online and lab split by categoryXpair in lab dataset

## for reproducibility
library(ggstatsplot)
set.seed(123)

## let's split the dataframe and create a list by stimuli of interest
category_list <- combined.ellrep.lab %>% filter(pairType=="inference") %>%
  split(f = .$stimCategory, drop = TRUE)

## checking the length of the list and the names of each element
length(category_list)
## [1] 3
names(category_list)
## [1] "faces"   "objects" "scenes"
## for reproducibility
set.seed(123)
library(ggstatsplot)

## creating a list of plots
plot_list <- purrr::pmap(
  .l = list(
    data = category_list,
    x = "group",
    y = "corr",
    grouping.var = "pair",
    outlier.tagging = TRUE,
    xlab = "Pair",
    ylab = "Mean performance",
    annotation.args = list(title = "faces",title = "objects",title = "scenes" )
  ),
  .f = grouped_ggbetweenstats
)

plot_list
## $faces

## 
## $objects

## 
## $scenes

look at some stats for online and lab split by category in online dataset

## for reproducibility
library(ggstatsplot)
set.seed(123)

## let's split the dataframe and create a list by stimuli of interest
category_list <- combined.ellrep.online %>% filter(pairType=="inference") %>%
  split(f = .$stimCategory, drop = TRUE)

## checking the length of the list and the names of each element
length(category_list)
## [1] 3
names(category_list)
## [1] "faces"   "objects" "scenes"
## for reproducibility
set.seed(123)
library(ggstatsplot)

## creating a list of plots
plot_list <- purrr::pmap(
  .l = list(
    data = category_list,
    x = "group",
    y = "corr",
    grouping.var = "pair",
    outlier.tagging = TRUE,
    xlab = "Pair",
    ylab = "Mean performance",
    annotation.args = list(title = "faces",title = "objects",title = "scenes" )
  ),
  .f = grouped_ggbetweenstats
)

plot_list
## $faces

## 
## $objects

## 
## $scenes