diff --git a/ccn2019.Rmd b/ccn2019.Rmd index 02322ca..d01e020 100644 --- a/ccn2019.Rmd +++ b/ccn2019.Rmd @@ -8,6 +8,7 @@ library(ggplot2) library(stringi) library(GA) +library(dbscan) ``` # Introduction @@ -147,7 +148,7 @@ with_targets_ratio <- function(stimulus_type, history) { sapply(1:length(history), function(i) { - trials <- stimulus_type[(i-str_length(history[i])):i] + trials <- stimulus_type[(i-stri_length(history[i])):i] trials <- unlist(trials, use.names=FALSE) length(trials[trials=="target"]) }) @@ -177,11 +178,12 @@ }) } -with_history <- function(stims, max=8) { +with_history <- function(stims, size=16) { res <- c('') for (i in 2:length(stims)) { - res[i] <- stri_sub(paste(res[i-1], stims[i], sep=''),from=-max,length=max) + res[i] <- stri_sub(paste(res[i-1], stims[i], sep=''),from=-size,length=size) } + #res <- ifelse(stri_length(res)==size, res, NA) res } @@ -191,8 +193,6 @@ } NB_modified <- NB %>% - #filter(participant=='P4') %>% - #filter(participant %in% c('P1','P2','P3','P5'), !is.na(correct)) %>% group_by(participant, condition, block) %>% mutate(history = with_history(stimulus)) %>% #mutate(stimulus_type = map_chr(.x=stimulus, stim_type=stimulus_type, history=history,.f=with_lures)) @@ -201,18 +201,70 @@ mutate(l = with_lures_ratio(stimulus_type_2, history)) %>% mutate(s = with_skewness_score(stimulus, history)) %>% mutate(u = with_lumpiness_score(stimulus, history)) %>% + filter(stri_length(history)==16) %>% #normalize_scores(targets_ratio, lures_ratio, skewness, lumpiness) %>% ungroup() +NB_modified %>% + mutate(correct = ifelse(stimulus_type=='burn-in',NA,correct)) +## group-level averaged NB, a single row represent an observation for a single subject +## in a single condition + +NB_avg <- NB_modified %>% + group_by(participant, condition) %>% + mutate(correct = ifelse(stimulus_type=='burn-in',NA,correct)) %>% + summarise(targets=sum(t), lures=sum(l), skewness=sum(s), lumpiness=sum(u), rts = mean(rt, na.rm=T), accuracy=sum(correct,na.rm=T)/90) %>% + ungroup() + # print # NB_modified %>% # filter(participant=='P1') %>% # View() # -pca=prcomp(NB_modified[,c('t','l','s','u')], center = TRUE,scale. = TRUE) +pca <- prcomp(NB_modified[,c('t','l','s','u')], center = TRUE,scale. = TRUE) -# rt/accuracy and lures +NB_modified <- NB_modified %>% mutate(pc1=pca$x[,'PC1'], pc2=pca$x[,'PC2']) + +fit <- lm(correct ~ t * s, NB_modified) + +``` + + +```{r} + +# DBSCAN Clustering (RT+ACCURACY against skewness) +NB_avg %>% + mutate(cluster = dbscan(cbind(accuracy,rts), eps = 0.5, minPts = 3)$cluster) %>% + ggplot(aes(skewness, accuracy, color=factor(cluster))) + + ggtitle("targets (window = 16 trials)", "NOTE: each point is a single participant") + + geom_point(alpha=0.3) + + #geom_smooth(method='lm', se = F) + + facet_wrap(~condition) + +``` + + +```{r} +## single-subject figures +NB_modified %>% + ggplot(aes(t,s,color=correct)) + + geom_jitter() + + geom_point() + + stat_summary(fun.y="mean") +NB_modified %>% + filter(!is.na(correct)) %>% + ggplot(aes(jitter(s),jitter(t),color=correct)) + + geom_jitter() + + geom_point(alpha=0.1) + +NB_modified %>% + filter(!is.na(correct)) %>% + ggplot(aes(jitter(s),jitter(u),color=correct)) + + geom_jitter() + + geom_point() + + facet_wrap(~condition) + # rt/accuracy and lures NB_modified %>% filter(!is.na(correct)) %>% @@ -220,15 +272,30 @@ geom_jitter() + geom_point(shape=16) + geom_smooth(method="lm",se = F) + - facet_wrap(~condition, scales="free") -# -# NB_modified %>% -# mutate(pc1=pca$x[,'PC1'], pc2=pca$x[,'PC2']) %>% -# filter(!is.na(correct)) %>% -# ggplot(aes(jitter(pc1),jitter(pc2),color=rt)) + -# geom_jitter() + -# geom_point() + -# geom_smooth(method="lm",se = F) #+ facet_wrap(~correct, scales="free") + facet_wrap(~condition, scales="free") + + +NB_modified %>% + filter(!is.na(correct)) %>% + ggplot(aes(pc1,pc2,color=correct)) + + geom_point() + + geom_smooth(method="lm",se = F) + + facet_wrap(~condition, scales="free") + +NB_modified %>% + filter(!is.na(correct)) %>% + ggplot(aes(pc1,rt,color=correct)) + + geom_point() + + geom_smooth(method="lm",se = F) + + facet_wrap(~condition, scales="free") + +NB_modified %>% + filter(!is.na(correct)) %>% + ggplot(aes(pc1,correct,color=correct)) + + geom_point() + + geom_smooth(method="lm",se = F) + + facet_wrap(~condition, scales="free") + ```