diff --git a/ccn2019.rev2.Rmd b/ccn2019.rev2.Rmd index 854a4fa..318502a 100644 --- a/ccn2019.rev2.Rmd +++ b/ccn2019.rev2.Rmd @@ -1,8 +1,8 @@ --- title: "Statistical Properties of the N-Back Sequences" output: - pdf_document: default html_notebook: default + pdf_document: default --- # Problems @@ -132,7 +132,7 @@ # plot(mod1) -plsResult <- plsR(correct ~ ., data=NB2[,c("correct","x_sl","x_ul","x_t","x_l")],3) +plsResult <- plsR(correct ~ ., data=NB2[,c("rt","x_sl","x_ul","x_t","x_l")],3) plsResult diff --git a/ccn2019.rev2.Rmd b/ccn2019.rev2.Rmd index 854a4fa..318502a 100644 --- a/ccn2019.rev2.Rmd +++ b/ccn2019.rev2.Rmd @@ -1,8 +1,8 @@ --- title: "Statistical Properties of the N-Back Sequences" output: - pdf_document: default html_notebook: default + pdf_document: default --- # Problems @@ -132,7 +132,7 @@ # plot(mod1) -plsResult <- plsR(correct ~ ., data=NB2[,c("correct","x_sl","x_ul","x_t","x_l")],3) +plsResult <- plsR(correct ~ ., data=NB2[,c("rt","x_sl","x_ul","x_t","x_l")],3) plsResult diff --git a/pls_training.Rmd b/pls_training.Rmd new file mode 100644 index 0000000..2f9163c --- /dev/null +++ b/pls_training.Rmd @@ -0,0 +1,35 @@ +--- +title: "PLS Training" +output: html_notebook +--- + +PLS: + +```{r} +#detach("package:MASS","plsdof") # to avoid conflict with dplyr::select +library(tidyverse) +library(pls) + +## 1. load sample data +drinks <- read.csv("http://wiki.q-researchsoftware.com/images/d/db/Stacked_colas.csv") +#str(drinks) + +## 2. clean data (remove brand and URLID) +drinks <- drinks %>% + select(-URLID, -brand) + +## 3. use cross validatation to find the optimal number of dimensions +pls.model = plsr(pref ~ ., data = drinks, 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) + +## 5. Sort, and visualize top coefficients +coefs <- coef(pls.model) + +barplot(tail(sort(coefs[,1,1]))) +``` \ No newline at end of file