diff --git a/ccn2019.rev2.nb.html b/ccn2019.rev2.nb.html new file mode 100644 index 0000000..b44e02a --- /dev/null +++ b/ccn2019.rev2.nb.html @@ -0,0 +1,444 @@ + + + + +
+ + + + + + + + +Statistical properties of n-back sequences bias behaviors. These bias, under specified structure, allows multiple cognitive strategies, producing heterogeneous behavior in a “gold standard” cognitive task.
+load('./data/CL2015.RData')
+window_size <- 8
+
+
+
+\(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=\{\}\)
+ + + +with_lures <- function(stimulus, stimulus_type, n) {
+ sapply(1:length(stimulus), function(i) {
+ lures <- c(as.character(stimulus[i-n-1]), as.character(stimulus[i-n+1]))
+ are_valid_trials <- i>n && all(!is.na(c(lures,stimulus[i])))
+ ifelse(are_valid_trials && stimulus[i] %in% lures,
+ "lure",
+ as.character(stimulus_type[i]))
+ })
+}
+with_history <- function(stimuli, length=16, fixed=F) {
+ seq <- paste(stimuli, collapse = '')
+
+ sapply(1:length(stimuli), function(i) {
+ stri_reverse(str_sub(seq, max(1,i-length+1), i))
+ })
+ #ifelse(fixed, h[str_length(h)==size], h)
+}
+# $x_{s,local}$
+with_skewness <- function(history) {
+ sapply(history, function(h) {
+ freqs <- table(unlist(str_split(h,"")))
+ sum(sort(freqs, decreasing = T)[1:2]) - 1
+ })
+}
+# $x_{u,local}$
+with_lumpiness <- function(history) {
+ sapply(history, function(h) {
+ freqs <- table(unlist(str_split(h,"")))
+ max(freqs) - 1
+ })
+}
+with_targets_ratio <- function(stimulus_type, length=16) {
+ sapply(1:length(stimulus_type), function(i) {
+ trials <- stimulus_type[max(1,i-length):i]
+ length(trials[trials=="target"]) / length(trials)
+ })
+}
+with_lures_ratio <- function(stimulus_type, length=16) {
+ sapply(1:length(stimulus_type), function(i) {
+ trials <- stimulus_type[max(1,i-length):i]
+ length(trials[trials=="lure"]) / length(trials)
+ })
+}
+NB2 <- NB %>%
+ filter(participant=="P13") %>%
+ group_by(participant, condition, block) %>%
+ mutate(n = ifelse(condition=='2-back',2,3)) %>%
+ mutate(stimulus_type = with_lures(stimulus, stimulus_type, n)) %>%
+ mutate(history = with_history(stimulus, window_size)) %>%
+ mutate(x_sl = with_skewness(history)) %>%
+ mutate(x_ul = with_lumpiness(history)) %>%
+ mutate(x_t = with_targets_ratio(stimulus_type, window_size)) %>%
+ mutate(x_l = with_lures_ratio(stimulus_type, window_size)) %>%
+ ungroup()
+
+pca <- prcomp(~x_sl+x_ul+x_t+x_l, NB2, center = TRUE,scale. = TRUE, na.action=na.exclude)
+NB2 <- NB2 %>% mutate(pc1=pca$x[,'PC1'], pc2=pca$x[,'PC2'])
+# caret
+library(caret)
+# Compile cross-validation settings
+any(is.na(NB2))
+
+
+[1] TRUE
+
+
+NB2 <- na.omit(NB2)
+# set.seed(100)
+# trainingfold <- createMultiFolds(NB2@correct, k = 5, times = 10)
+#
+# # PLS
+# mod1 <- train(correct ~ ., data = NB2[,c("correct","x_sl","x_ul","x_t","x_l")],
+# method = "pls",
+# metric = "Accuracy",
+# tuneLength = 20,
+# trControl = trainControl("repeatedcv", index = trainingfold, selectionFunction = "oneSE"),
+# preProc = c("zv","center","scale"))
+#
+# # Check CV
+# plot(mod1)
+plsResult <- plsR(correct ~ ., data=NB2[,c("correct","x_sl","x_ul","x_t","x_l")],3)
+
+
+____************************************************____
+____Component____ 1 ____
+____Component____ 2 ____
+____Component____ 3 ____
+____Predicting X without NA neither in X nor in Y____
+****________________________________________________****
+
+
+plsResult
+
+
+Number of required components:
+[1] 3
+Number of successfully computed components:
+[1] 3
+Coefficients:
+ [,1]
+Intercept 1.008159108
+x_sl -0.012385995
+x_ul 0.019020579
+x_t -0.009732895
+x_l 0.015588407
+Information criteria and Fit statistics:
+ AIC RSS_Y R2_Y R2_residY RSS_residY AIC.std DoF.dof
+Nb_Comp_0 -400.8879 0.9942529 NA NA 173.0000 496.7877 1.000000
+Nb_Comp_1 -399.2749 0.9920439 0.002221709 0.002221709 172.6156 498.4007 4.020014
+Nb_Comp_2 -397.5844 0.9902807 0.003995089 0.003995089 172.3088 500.0912 5.000000
+Nb_Comp_3 -396.2011 0.9867774 0.007518680 0.007518680 171.6993 501.4745 5.000000
+ sigmahat.dof AIC.dof BIC.dof GMDL.dof DoF.naive sigmahat.naive
+Nb_Comp_0 0.07580980 0.005780156 0.005884498 -441.1050 1 0.07580980
+Nb_Comp_1 0.07617155 0.005969500 0.006392969 -427.5293 2 0.07594536
+Nb_Comp_2 0.07632287 0.006026049 0.006554844 -423.3755 3 0.07609938
+Nb_Comp_3 0.07618775 0.006004731 0.006531655 -423.6749 4 0.07618775
+ AIC.naive BIC.naive GMDL.naive
+Nb_Comp_0 0.005780156 0.005884498 -441.1050
+Nb_Comp_1 0.005833993 0.006043423 -436.3376
+Nb_Comp_2 0.005890962 0.006206384 -431.7944
+Nb_Comp_3 0.005938011 0.006359551 -427.5722
+
+
+