diff --git a/ccn2019.rev2.Rmd b/ccn2019.rev2.Rmd index 3e8cfd9..ef37de0 100644 --- a/ccn2019.rev2.Rmd +++ b/ccn2019.rev2.Rmd @@ -18,6 +18,57 @@ - Global: No lures, large vocabulary -> pattern repeats implies a target +## Formulating Generating the N-Back Sequences as a CSP instance + +$P=\langle V,D,C,W\rangle$ + +$V=\{x_N,x_{T},x_{T,local},x_L,x_{L,local},x_V,x_U,x_S,x_{S,local},x_G\}$ + +$D=\{\}$ + + +Constraints: + +$$ +\\ + +x_n = N, W_n = 1 - |10 \times dnorm(x_n-N,sd=4)| + +\\\\ + +x_t = T \times trials, W_t = 1 - |10\times dnorm(T\times trials-x_t,sd=4)| + +\\\\ + +x_{tl} = {T \times w \over trials}, W_{tl} = 1 - |10\times dnorm(x_{tl} - {T \over trials} \times w,sd=4)| + +\\\\ + +x_{l} = L \times trials +\\\\ + +x_{ll} = L \times w +\\\\ + +x_{v} = |V| +\\ + +x_{ul} = w +\\\\ + +x_{s} = {trials \over |V|} +\\\\ + +x_{sl} = max(1, {w \over |V|}) +\\\\ + +x_{g} = {trials \over w} + +\\\\ + +x_{vl} = min(|V|, w) +$$ + ```{r libraries, message=FALSE, include=FALSE, paged.print=FALSE} library(ggplot2) library(tidyverse) @@ -34,13 +85,6 @@ ``` -$P=\{V,D,C,W\}$ - -$V=\{x_N,x_{T},x_{T,local},x_L,x_{L,local},x_V,x_U,x_S,x_{S,local},x_G\}$ - -$D=\{\}$ - - ```{r history} diff --git a/ccn2019.rev2.Rmd b/ccn2019.rev2.Rmd index 3e8cfd9..ef37de0 100644 --- a/ccn2019.rev2.Rmd +++ b/ccn2019.rev2.Rmd @@ -18,6 +18,57 @@ - Global: No lures, large vocabulary -> pattern repeats implies a target +## Formulating Generating the N-Back Sequences as a CSP instance + +$P=\langle V,D,C,W\rangle$ + +$V=\{x_N,x_{T},x_{T,local},x_L,x_{L,local},x_V,x_U,x_S,x_{S,local},x_G\}$ + +$D=\{\}$ + + +Constraints: + +$$ +\\ + +x_n = N, W_n = 1 - |10 \times dnorm(x_n-N,sd=4)| + +\\\\ + +x_t = T \times trials, W_t = 1 - |10\times dnorm(T\times trials-x_t,sd=4)| + +\\\\ + +x_{tl} = {T \times w \over trials}, W_{tl} = 1 - |10\times dnorm(x_{tl} - {T \over trials} \times w,sd=4)| + +\\\\ + +x_{l} = L \times trials +\\\\ + +x_{ll} = L \times w +\\\\ + +x_{v} = |V| +\\ + +x_{ul} = w +\\\\ + +x_{s} = {trials \over |V|} +\\\\ + +x_{sl} = max(1, {w \over |V|}) +\\\\ + +x_{g} = {trials \over w} + +\\\\ + +x_{vl} = min(|V|, w) +$$ + ```{r libraries, message=FALSE, include=FALSE, paged.print=FALSE} library(ggplot2) library(tidyverse) @@ -34,13 +85,6 @@ ``` -$P=\{V,D,C,W\}$ - -$V=\{x_N,x_{T},x_{T,local},x_L,x_{L,local},x_V,x_U,x_S,x_{S,local},x_G\}$ - -$D=\{\}$ - - ```{r history} diff --git a/ccn2019_diagrams.R b/ccn2019_diagrams.R new file mode 100644 index 0000000..7da6569 --- /dev/null +++ b/ccn2019_diagrams.R @@ -0,0 +1,51 @@ +NB_avg %>% + mutate(cluster = dbscan::dbscan(cbind(accuracy,rts), eps = 0.5, minPts = 3)$cluster) %>% + ggplot(aes(targets, accuracy, color=factor(cluster))) + + ggtitle("targets (window = 8 trials)", "NOTE: each point is a single participant") + + geom_point(alpha=0.3) + + #geom_smooth(method='lm', se = F) + + facet_wrap(~condition) + + +NB_avg %>% + ggplot(aes(lures, accuracy, color=condition)) + + ggtitle("lures (window = 8 trials)", "NOTE: each point is a single participant") + + geom_point(alpha=0.3) + + geom_smooth(method='lm', se = F) + +NB_avg %>% + ggplot(aes(skewness, accuracy, color=condition)) + + ggtitle("skewness (window = 8 trials)", "NOTE: each point is a single participant") + + geom_point(alpha=0.3) + + geom_smooth(method='lm', se = F) + +NB_avg %>% + ggplot(aes(lumpiness, accuracy, color=condition)) + + ggtitle("lumpiness", "NOTE: each point is a single participant") + + geom_point(alpha=0.3) + + geom_smooth(method='lm', se = F) + +NB_avg %>% + ggplot(aes(lumpiness, rts, color=condition)) + + ggtitle("lumpiness (window = 8 trials)", "NOTE: each point is a single participant") + + xlab("lumpiness") + + ylab("Average RT") + + geom_point(alpha=0.3) + + geom_smooth(method='lm', se = F) + +nback <- NB_modified + +nback %>% + mutate(block=as.factor(block)) %>% + mutate(trial=as.factor(trial)) %>% + mutate(condition=ifelse(condition=='2-back',2,3)) %>% + #filter(condition=='3-back') %>% + #mutate(correct=as.numeric(correct)) %>% + inspect_cor(show_plot = T) + +averaged_nback <- NB_avg + +averaged_nback %>% + mutate(condition=ifelse(condition=='2-back',2,3)) %>% + inspect_cor(show_plot = T) + diff --git a/ccn2019.rev2.Rmd b/ccn2019.rev2.Rmd index 3e8cfd9..ef37de0 100644 --- a/ccn2019.rev2.Rmd +++ b/ccn2019.rev2.Rmd @@ -18,6 +18,57 @@ - Global: No lures, large vocabulary -> pattern repeats implies a target +## Formulating Generating the N-Back Sequences as a CSP instance + +$P=\langle V,D,C,W\rangle$ + +$V=\{x_N,x_{T},x_{T,local},x_L,x_{L,local},x_V,x_U,x_S,x_{S,local},x_G\}$ + +$D=\{\}$ + + +Constraints: + +$$ +\\ + +x_n = N, W_n = 1 - |10 \times dnorm(x_n-N,sd=4)| + +\\\\ + +x_t = T \times trials, W_t = 1 - |10\times dnorm(T\times trials-x_t,sd=4)| + +\\\\ + +x_{tl} = {T \times w \over trials}, W_{tl} = 1 - |10\times dnorm(x_{tl} - {T \over trials} \times w,sd=4)| + +\\\\ + +x_{l} = L \times trials +\\\\ + +x_{ll} = L \times w +\\\\ + +x_{v} = |V| +\\ + +x_{ul} = w +\\\\ + +x_{s} = {trials \over |V|} +\\\\ + +x_{sl} = max(1, {w \over |V|}) +\\\\ + +x_{g} = {trials \over w} + +\\\\ + +x_{vl} = min(|V|, w) +$$ + ```{r libraries, message=FALSE, include=FALSE, paged.print=FALSE} library(ggplot2) library(tidyverse) @@ -34,13 +85,6 @@ ``` -$P=\{V,D,C,W\}$ - -$V=\{x_N,x_{T},x_{T,local},x_L,x_{L,local},x_V,x_U,x_S,x_{S,local},x_G\}$ - -$D=\{\}$ - - ```{r history} diff --git a/ccn2019_diagrams.R b/ccn2019_diagrams.R new file mode 100644 index 0000000..7da6569 --- /dev/null +++ b/ccn2019_diagrams.R @@ -0,0 +1,51 @@ +NB_avg %>% + mutate(cluster = dbscan::dbscan(cbind(accuracy,rts), eps = 0.5, minPts = 3)$cluster) %>% + ggplot(aes(targets, accuracy, color=factor(cluster))) + + ggtitle("targets (window = 8 trials)", "NOTE: each point is a single participant") + + geom_point(alpha=0.3) + + #geom_smooth(method='lm', se = F) + + facet_wrap(~condition) + + +NB_avg %>% + ggplot(aes(lures, accuracy, color=condition)) + + ggtitle("lures (window = 8 trials)", "NOTE: each point is a single participant") + + geom_point(alpha=0.3) + + geom_smooth(method='lm', se = F) + +NB_avg %>% + ggplot(aes(skewness, accuracy, color=condition)) + + ggtitle("skewness (window = 8 trials)", "NOTE: each point is a single participant") + + geom_point(alpha=0.3) + + geom_smooth(method='lm', se = F) + +NB_avg %>% + ggplot(aes(lumpiness, accuracy, color=condition)) + + ggtitle("lumpiness", "NOTE: each point is a single participant") + + geom_point(alpha=0.3) + + geom_smooth(method='lm', se = F) + +NB_avg %>% + ggplot(aes(lumpiness, rts, color=condition)) + + ggtitle("lumpiness (window = 8 trials)", "NOTE: each point is a single participant") + + xlab("lumpiness") + + ylab("Average RT") + + geom_point(alpha=0.3) + + geom_smooth(method='lm', se = F) + +nback <- NB_modified + +nback %>% + mutate(block=as.factor(block)) %>% + mutate(trial=as.factor(trial)) %>% + mutate(condition=ifelse(condition=='2-back',2,3)) %>% + #filter(condition=='3-back') %>% + #mutate(correct=as.numeric(correct)) %>% + inspect_cor(show_plot = T) + +averaged_nback <- NB_avg + +averaged_nback %>% + mutate(condition=ifelse(condition=='2-back',2,3)) %>% + inspect_cor(show_plot = T) + diff --git a/pls_playground.Rmd b/pls_playground.Rmd index 22d877f..83c79a7 100644 --- a/pls_playground.Rmd +++ b/pls_playground.Rmd @@ -12,25 +12,43 @@ library(pls) ## 1. load sample data -drinks <- read.csv("http://wiki.q-researchsoftware.com/images/d/db/Stacked_colas.csv") -#str(drinks) +#data <- read.csv("http://wiki.q-researchsoftware.com/images/d/db/Stacked_colas.csv") + +rm(NB) +load("./data/CL2015.RData") +data <- NB +str(data) ## 2. clean data (remove brand and URLID) -drinks <- drinks %>% - select(-URLID, -brand) +data <- data %>% + mutate(n=ifelse(condition=='2-back', 2, 3)) %>% + select(-condition, + -stimulus, + -block, + -trial) +# %>% +# rename( +# ev.participant=participant, +# ev.n=n, +# ev.block=block, +# ev.stimulus_type=stimulus_type, +# rv.choice=choice, +# rv.rt=rt, +# rv.correct=correct +# ) ## 3. use cross validatation to find the optimal number of dimensions -pls.model = plsr(pref ~ ., data = drinks, validation = "CV") +pls.model = plsr(rt ~ ., data = data, validation = "CV") ## 3.1. find the model with lowest cv error cv <- RMSEP(pls.model) best_dims <- which.min(cv$val[estimate = "adjCV", , ]) - 1 ## 4. rebuild the model -pls.model <- plsr(pref ~ ., data = drinks, ncomp = best_dims) +pls.model <- plsr(rt ~ ., data = data, ncomp = best_dims) ## 5. Sort, and visualize top coefficients coefs <- coef(pls.model) -barplot(tail(sort(coefs[,1,1]))) +barplot(sort(coefs[,1,1], decreasing = T)[1:4]) ``` \ No newline at end of file