diff --git a/R/.gitignore b/R/.gitignore index d1fc5c7e..6ac09748 100644 --- a/R/.gitignore +++ b/R/.gitignore @@ -1,3 +1,4 @@ hBayesDM*.tar.gz hBayesDM.Rcheck/ docs/ +!inst/include/stan_meta_header.hpp diff --git a/R/configure b/R/configure new file mode 100755 index 00000000..0304fc54 --- /dev/null +++ b/R/configure @@ -0,0 +1,5 @@ +#! /bin/sh + +# Generated by rstantools. Do not edit by hand. + +"${R_HOME}/bin/Rscript" -e "rstantools::rstan_config()" diff --git a/R/configure.win b/R/configure.win new file mode 100755 index 00000000..5e2dceb8 --- /dev/null +++ b/R/configure.win @@ -0,0 +1,5 @@ +#! /bin/sh + +# Generated by rstantools. Do not edit by hand. + +"${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "rstantools::rstan_config()" diff --git a/R/inst/include/meta_header.hpp b/R/inst/include/meta_header.hpp deleted file mode 100644 index 762c0f08..00000000 --- a/R/inst/include/meta_header.hpp +++ /dev/null @@ -1,7 +0,0 @@ -/* Usage Example: - * - * #include "csr_matrix_times_vector2.hpp" - * - * And place file in `inst/include/` directory. - * See https://github.com/stan-dev/rstanarm/tree/master/inst/include for more. - */ diff --git a/R/inst/include/stan_meta_header.hpp b/R/inst/include/stan_meta_header.hpp new file mode 100644 index 00000000..3b914da2 --- /dev/null +++ b/R/inst/include/stan_meta_header.hpp @@ -0,0 +1 @@ +// Insert all #include statements here diff --git a/R/inst/stan_files b/R/inst/stan similarity index 100% rename from R/inst/stan_files rename to R/inst/stan diff --git a/R/src/Makevars b/R/src/Makevars deleted file mode 100644 index 720131ef..00000000 --- a/R/src/Makevars +++ /dev/null @@ -1,22 +0,0 @@ -STANHEADERS_SRC = `"$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "cat(system.file('include', 'src', package = 'StanHeaders', mustWork = TRUE), sep = '')"` -PKG_CPPFLAGS = -I"../inst/include" -I"$(STANHEADERS_SRC)" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error -DBOOST_NO_AUTO_PTR - -CXX_STD = CXX14 -SOURCE_PATH = ../inst/stan_files -ifeq ($(BUILD_ALL), true) - SOURCES = $(wildcard $(SOURCE_PATH)/*.stan) -endif -OBJECTS = $(SOURCES:.stan=.o) init.o - -all: $(SHLIB) - -clean: - rm -rf "$(SOURCE_PATH)/*.o" - rm -rf *.so *.o - rm -rf "$(SOURCE_PATH)/*.cc" - rm -rf "$(SOURCE_PATH)/*.hpp" - -%.cc: %.stan - "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "source(file.path('..', 'tools', 'make_cc.R')); make_cc(commandArgs(TRUE))" $< - -.phony: all clean diff --git a/R/src/Makevars.win b/R/src/Makevars.win deleted file mode 100644 index c9a5fc0b..00000000 --- a/R/src/Makevars.win +++ /dev/null @@ -1,22 +0,0 @@ -STANHEADERS_SRC = `"$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "cat(system.file('include', 'src', package = 'StanHeaders', mustWork = TRUE), sep = '')"` -PKG_CPPFLAGS = -I"../inst/include" -I"$(STANHEADERS_SRC)" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error -DBOOST_NO_AUTO_PTR - -CXX_STD = CXX14 -SOURCE_PATH = ../inst/stan_files -ifeq ($(BUILD_ALL), true) - SOURCES = $(wildcard $(SOURCE_PATH)/*.stan) -endif -OBJECTS = $(SOURCES:.stan=.o) init.o - -all: $(SHLIB) - -clean: - RM -rf "$(SOURCE_PATH)/*.o" - RM -rf *.so *.o - RM -rf "$(SOURCE_PATH)/*.cc" - RM -rf "$(SOURCE_PATH)/*.hpp" - -%.cc: %.stan - "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "source(file.path('..', 'tools', 'make_cc.R')); make_cc(commandArgs(TRUE))" $< - -.phony: clean diff --git a/R/tools/make_cc.R b/R/tools/make_cc.R deleted file mode 100644 index d4817e7a..00000000 --- a/R/tools/make_cc.R +++ /dev/null @@ -1,48 +0,0 @@ -# Part of the rstanarm package for estimating model parameters -# Copyright (C) 2015, 2016, 2017 Trustees of Columbia University -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 3 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -options(warn = 3L) -options("useFancyQuotes" = FALSE) - -make_cc <- function(file) { - file <- sub("\\.cc$", ".stan", file) - cppcode <- rstan::stanc(file, allow_undefined = TRUE, - obfuscate_model_name = FALSE)$cppcode - cppcode <- sub("(class[[:space:]]+[A-Za-z_][A-Za-z0-9_]*[[:space:]]*: public prob_grad \\{)", - paste("#include \n", "\\1"), cppcode) - - cat(readLines(file.path("..", "inst", "stan_files", "pre", "license.stan")), - "#ifndef MODELS_HPP", "#define MODELS_HPP", "#define STAN__SERVICES__COMMAND_HPP", - "#include ", - cppcode, "#endif", file = sub("\\.stan$", ".hpp", file), - sep = "\n", append = FALSE) - - f <- sub("\\.stan$", "", basename(file)) - Rcpp::exposeClass(class = paste0("model_", f), - constructors = list(c("SEXP", "SEXP", "SEXP")), fields = character(), - methods = c("call_sampler", - "param_names", "param_names_oi", "param_fnames_oi", - "param_dims", "param_dims_oi", "update_param_oi", "param_oi_tidx", - "grad_log_prob", "log_prob", - "unconstrain_pars", "constrain_pars", "num_pars_unconstrained", - "unconstrained_param_names", "constrained_param_names"), - file = file.path("..", "inst", "stan_files", paste0(f, ".cc")), - header = paste0('#include "', f, '.hpp"'), - module = paste0("stan_fit4", f, "_mod"), - CppClass = "rstan::stan_fit ", - Rfile = FALSE) - return(invisible(NULL)) -} diff --git a/commons/stan_files/alt_delta.stan b/commons/stan_files/alt_delta.stan index f998ff63..08f6acfd 100644 --- a/commons/stan_files/alt_delta.stan +++ b/commons/stan_files/alt_delta.stan @@ -1,13 +1,13 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - int choice[N, T]; - real outcome[N, T]; // no lower and upper bounds - real bluePunish[N, T]; - real orangePunish[N, T]; + array[N] int Tsubj; + array[N, T] int choice; + array[N, T] real outcome; // no lower and upper bounds + array[N, T] real bluePunish; + array[N, T] real orangePunish; } transformed data { real initV_ev; // initial values for EV @@ -88,10 +88,10 @@ generated quantities { real mu_gamma; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/alt_gamma.stan b/commons/stan_files/alt_gamma.stan index 0bd9bb70..5e282e2b 100644 --- a/commons/stan_files/alt_gamma.stan +++ b/commons/stan_files/alt_gamma.stan @@ -1,13 +1,13 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - int choice[N, T]; - real outcome[N, T]; // no lower and upper bounds - real bluePunish[N, T]; - real orangePunish[N, T]; + array[N] int Tsubj; + array[N, T] int choice; + array[N, T] real outcome; // no lower and upper bounds + array[N, T] real bluePunish; + array[N, T] real orangePunish; } transformed data { vector[2] initV_ev; // initial values for EV @@ -89,10 +89,10 @@ generated quantities { real mu_gamma; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/bandit2arm_delta.stan b/commons/stan_files/bandit2arm_delta.stan index 3c44ddde..be371086 100644 --- a/commons/stan_files/bandit2arm_delta.stan +++ b/commons/stan_files/bandit2arm_delta.stan @@ -1,11 +1,11 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - int choice[N, T]; - real outcome[N, T]; // no lower and upper bounds + array[N] int Tsubj; + array[N, T] int choice; + array[N, T] real outcome; // no lower and upper bounds } transformed data { vector[2] initV; // initial values for EV @@ -65,10 +65,10 @@ generated quantities { real mu_tau; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/bandit4arm2_kalman_filter.stan b/commons/stan_files/bandit4arm2_kalman_filter.stan index 5f687b7a..38a87366 100644 --- a/commons/stan_files/bandit4arm2_kalman_filter.stan +++ b/commons/stan_files/bandit4arm2_kalman_filter.stan @@ -1,11 +1,11 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - int choice[N,T]; - real outcome[N,T]; + array[N] int Tsubj; + array[N,T] int choice; + array[N,T] real outcome; } transformed data { @@ -104,8 +104,8 @@ generated quantities { real mu_mu0; real mu_s0; real mu_sD; - real log_lik[N]; - real y_pred[N,T]; + array[N] real log_lik; + array[N,T] real y_pred; for (i in 1:N) { for (t in 1:T) { diff --git a/commons/stan_files/bandit4arm_2par_lapse.stan b/commons/stan_files/bandit4arm_2par_lapse.stan index b95da5ce..4d07cca0 100644 --- a/commons/stan_files/bandit4arm_2par_lapse.stan +++ b/commons/stan_files/bandit4arm_2par_lapse.stan @@ -1,4 +1,4 @@ -#include /pre/license.stan +#include /include/license.stan // Seymour et al 2012 J neuro model, w/o C (chioce perseveration) but with xi (lapse rate) // w/o reward sensitivity and punishment sensitivity @@ -7,10 +7,10 @@ data { int N; int T; - int Tsubj[N]; - real rew[N, T]; - real los[N, T]; - int choice[N, T]; + array[N] int Tsubj; + array[N, T] real rew; + array[N, T] real los; + array[N, T] int choice; } transformed data { @@ -104,10 +104,10 @@ generated quantities { real mu_xi; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/bandit4arm_4par.stan b/commons/stan_files/bandit4arm_4par.stan index 18d6acf9..5a6f46f2 100644 --- a/commons/stan_files/bandit4arm_4par.stan +++ b/commons/stan_files/bandit4arm_4par.stan @@ -1,13 +1,13 @@ -#include /pre/license.stan +#include /include/license.stan // Seymour et al 2012 J neuro model, w/o C (chioce perseveration) data { int N; int T; - int Tsubj[N]; - real rew[N, T]; - real los[N, T]; - int choice[N, T]; + array[N] int Tsubj; + array[N, T] real rew; + array[N, T] real los; + array[N, T] int choice; } transformed data { @@ -106,10 +106,10 @@ generated quantities { real mu_P; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/bandit4arm_lapse.stan b/commons/stan_files/bandit4arm_lapse.stan index 161ce311..3f7fcd70 100644 --- a/commons/stan_files/bandit4arm_lapse.stan +++ b/commons/stan_files/bandit4arm_lapse.stan @@ -1,13 +1,13 @@ -#include /pre/license.stan +#include /include/license.stan // Seymour et al 2012 J neuro model, w/o C (chioce perseveration) but with xi (lapse rate) data { int N; int T; - int Tsubj[N]; - real rew[N, T]; - real los[N, T]; - int choice[N, T]; + array[N] int Tsubj; + array[N, T] real rew; + array[N, T] real los; + array[N, T] int choice; } transformed data { @@ -111,10 +111,10 @@ generated quantities { real mu_xi; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/bandit4arm_lapse_decay.stan b/commons/stan_files/bandit4arm_lapse_decay.stan index b089ee21..5c1a21b2 100644 --- a/commons/stan_files/bandit4arm_lapse_decay.stan +++ b/commons/stan_files/bandit4arm_lapse_decay.stan @@ -1,14 +1,14 @@ -#include /pre/license.stan +#include /include/license.stan // Seymour et al 2012 J neuro model, w/o C (chioce perseveration) but with xi (lapse rate). Added decay rate (Niv et al., 2015, J. Neuro) // Aylward et al., 2018, PsyArXiv data { int N; int T; - int Tsubj[N]; - real rew[N, T]; - real los[N, T]; - int choice[N, T]; + array[N] int Tsubj; + array[N, T] real rew; + array[N, T] real los; + array[N, T] int choice; } transformed data { @@ -123,10 +123,10 @@ generated quantities { real mu_d; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/bandit4arm_singleA_lapse.stan b/commons/stan_files/bandit4arm_singleA_lapse.stan index b383f389..fdf2875f 100644 --- a/commons/stan_files/bandit4arm_singleA_lapse.stan +++ b/commons/stan_files/bandit4arm_singleA_lapse.stan @@ -1,14 +1,14 @@ -#include /pre/license.stan +#include /include/license.stan // Seymour et al 2012 J neuro model, w/o C (chioce perseveration) but with xi (lapse rate). Single learning rate both for R and P. // Aylward et al., 2018, PsyArXiv data { int N; int T; - int Tsubj[N]; - real rew[N, T]; - real los[N, T]; - int choice[N, T]; + array[N] int Tsubj; + array[N, T] real rew; + array[N, T] real los; + array[N, T] int choice; } transformed data { @@ -107,10 +107,10 @@ generated quantities { real mu_xi; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/banditNarm_2par_lapse.stan b/commons/stan_files/banditNarm_2par_lapse.stan index cfc939c4..58e3e0cb 100644 --- a/commons/stan_files/banditNarm_2par_lapse.stan +++ b/commons/stan_files/banditNarm_2par_lapse.stan @@ -1,4 +1,4 @@ -#include /pre/license.stan +#include /include/license.stan // Seymour et al 2012 J neuro model, w/o C (chioce perseveration) but with xi (lapse rate) // w/o reward sensitivity and punishment sensitivity @@ -7,10 +7,10 @@ data { int N; int T; - int Tsubj[N]; - real rew[N, T]; - real los[N, T]; - int choice[N, T]; + array[N] int Tsubj; + array[N, T] real rew; + array[N, T] real los; + array[N, T] int choice; int Narm; } @@ -105,10 +105,10 @@ generated quantities { real mu_xi; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/banditNarm_4par.stan b/commons/stan_files/banditNarm_4par.stan index 3c525c50..3f5ccef6 100644 --- a/commons/stan_files/banditNarm_4par.stan +++ b/commons/stan_files/banditNarm_4par.stan @@ -1,13 +1,13 @@ -#include /pre/license.stan +#include /include/license.stan // Seymour et al 2012 J neuro model, w/o C (chioce perseveration) data { int N; int T; - int Tsubj[N]; - real rew[N, T]; - real los[N, T]; - int choice[N, T]; + array[N] int Tsubj; + array[N, T] real rew; + array[N, T] real los; + array[N, T] int choice; int Narm; } @@ -107,10 +107,10 @@ generated quantities { real mu_P; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/banditNarm_delta.stan b/commons/stan_files/banditNarm_delta.stan index 80f11cf2..8d01b578 100644 --- a/commons/stan_files/banditNarm_delta.stan +++ b/commons/stan_files/banditNarm_delta.stan @@ -1,12 +1,12 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - real rew[N, T]; - real los[N, T]; - int choice[N, T]; + array[N] int Tsubj; + array[N, T] real rew; + array[N, T] real los; + array[N, T] int choice; int Narm; } @@ -68,10 +68,10 @@ generated quantities { real mu_tau; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/banditNarm_kalman_filter.stan b/commons/stan_files/banditNarm_kalman_filter.stan index 1d68a017..79f2e532 100644 --- a/commons/stan_files/banditNarm_kalman_filter.stan +++ b/commons/stan_files/banditNarm_kalman_filter.stan @@ -1,12 +1,12 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - real rew[N, T]; - real los[N, T]; - int choice[N, T]; + array[N] int Tsubj; + array[N, T] real rew; + array[N, T] real los; + array[N, T] int choice; int Narm; } transformed data { @@ -106,8 +106,8 @@ generated quantities { real mu_mu0; real mu_s0; real mu_sD; - real log_lik[N]; - real y_pred[N,T]; + array[N] real log_lik; + array[N,T] real y_pred; for (i in 1:N) { for (t in 1:T) { diff --git a/commons/stan_files/banditNarm_lapse.stan b/commons/stan_files/banditNarm_lapse.stan index 50f49a8a..809ac5cb 100644 --- a/commons/stan_files/banditNarm_lapse.stan +++ b/commons/stan_files/banditNarm_lapse.stan @@ -1,13 +1,13 @@ -#include /pre/license.stan +#include /include/license.stan // Seymour et al 2012 J neuro model, w/o C (chioce perseveration) but with xi (lapse rate) data { int N; int T; - int Tsubj[N]; - real rew[N, T]; - real los[N, T]; - int choice[N, T]; + array[N] int Tsubj; + array[N, T] real rew; + array[N, T] real los; + array[N, T] int choice; int Narm; } @@ -112,10 +112,10 @@ generated quantities { real mu_xi; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/banditNarm_lapse_decay.stan b/commons/stan_files/banditNarm_lapse_decay.stan index bc2fcc05..6e90abdc 100644 --- a/commons/stan_files/banditNarm_lapse_decay.stan +++ b/commons/stan_files/banditNarm_lapse_decay.stan @@ -1,14 +1,14 @@ -#include /pre/license.stan +#include /include/license.stan // Seymour et al 2012 J neuro model, w/o C (chioce perseveration) but with xi (lapse rate). Added decay rate (Niv et al., 2015, J. Neuro) // Aylward et al., 2018, PsyArXiv data { int N; int T; - int Tsubj[N]; - real rew[N, T]; - real los[N, T]; - int choice[N, T]; + array[N] int Tsubj; + array[N, T] real rew; + array[N, T] real los; + array[N, T] int choice; int Narm; } @@ -124,10 +124,10 @@ generated quantities { real mu_d; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/banditNarm_singleA_lapse.stan b/commons/stan_files/banditNarm_singleA_lapse.stan index 8ab49eef..5677d21d 100644 --- a/commons/stan_files/banditNarm_singleA_lapse.stan +++ b/commons/stan_files/banditNarm_singleA_lapse.stan @@ -1,14 +1,14 @@ -#include /pre/license.stan +#include /include/license.stan // Seymour et al 2012 J neuro model, w/o C (chioce perseveration) but with xi (lapse rate). Single learning rate both for R and P. // Aylward et al., 2018, PsyArXiv data { int N; int T; - int Tsubj[N]; - real rew[N, T]; - real los[N, T]; - int choice[N, T]; + array[N] int Tsubj; + array[N, T] real rew; + array[N, T] real los; + array[N, T] int choice; int Narm; } @@ -108,10 +108,10 @@ generated quantities { real mu_xi; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/bart_ewmv.stan b/commons/stan_files/bart_ewmv.stan index 4d521150..168add88 100644 --- a/commons/stan_files/bart_ewmv.stan +++ b/commons/stan_files/bart_ewmv.stan @@ -1,16 +1,16 @@ data { int N; // Number of subjects int T; // Maximum number of trials - int Tsubj[N]; // Number of trials for each subject + array[N] int Tsubj; // Number of trials for each subject int P; // Number of max pump + 1 ** CAUTION ** - int pumps[N, T]; // Number of pump + array[N, T] int pumps; // Number of pump // int reward[N, T]; // Amount of rewards - int explosion[N, T]; // Whether the balloon exploded (0 or 1) + array[N, T] int explosion; // Whether the balloon exploded (0 or 1) } transformed data { // Whether a subject pump the button or not (0 or 1) - int d[N, T, P]; + array[N, T, P] int d; for (j in 1:N) { for (k in 1:Tsubj[j]) { @@ -110,10 +110,10 @@ generated quantities { real mu_lambda = exp(mu_pr[5]); // Log-likelihood for model fit - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T, P]; + array[N, T, P] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (j in 1:N) diff --git a/commons/stan_files/bart_par4.stan b/commons/stan_files/bart_par4.stan index 2049a200..b573d1f1 100644 --- a/commons/stan_files/bart_par4.stan +++ b/commons/stan_files/bart_par4.stan @@ -1,17 +1,17 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; // Number of subjects int T; // Maximum number of trials - int Tsubj[N]; // Number of trials for each subject + array[N] int Tsubj; // Number of trials for each subject int P; // Number of max pump + 1 ** CAUTION ** - int pumps[N, T]; // Number of pump - int explosion[N, T]; // Whether the balloon exploded (0 or 1) + array[N, T] int pumps; // Number of pump + array[N, T] int explosion; // Whether the balloon exploded (0 or 1) } transformed data{ // Whether a subject pump the button or not (0 or 1) - int d[N, T, P]; + array[N, T, P] int d; for (j in 1:N) { for (k in 1:Tsubj[j]) { @@ -92,10 +92,10 @@ generated quantities { real mu_tau = exp(mu_pr[4]); // Log-likelihood for model fit - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T, P]; + array[N, T, P] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (j in 1:N) diff --git a/commons/stan_files/cgt_cm.stan b/commons/stan_files/cgt_cm.stan index f6cdb079..a528683c 100644 --- a/commons/stan_files/cgt_cm.stan +++ b/commons/stan_files/cgt_cm.stan @@ -2,14 +2,14 @@ data { int N; // Number of subjects int T; // Max trials per subject int B; // Number of bet options - int Tsubj[N]; // number of trials/subject - int col_chosen[N,T]; // chosen color index - int bet_chosen[N,T]; // chosen bet indexs + array[N] int Tsubj; // number of trials/subject + array[N,T] int col_chosen; // chosen color index + array[N,T] int bet_chosen; // chosen bet indexs vector[B] bet_delay; // vector of bet delays - real gain[N,T,B]; // gain: (capital + capital * bet_prop) - real loss[N,T,B]; // loss: (capital - capital * bet_prop) - real prop_red[N,T]; // proportion of red boxes - real prop_chosen[N,T]; // proportion of chosen boxes + array[N,T,B] real gain; // gain: (capital + capital * bet_prop) + array[N,T,B] real loss; // loss: (capital - capital * bet_prop) + array[N,T] real prop_red; // proportion of red boxes + array[N,T] real prop_chosen; // proportion of chosen boxes } parameters { @@ -100,10 +100,10 @@ generated quantities { real mu_beta; // Define log likelihood vector - real log_lik[N]; - real y_hat_col[N,T]; - real y_hat_bet[N,T]; - real bet_utils[N,T,B]; + array[N] real log_lik; + array[N,T] real y_hat_col; + array[N,T] real y_hat_bet; + array[N,T,B] real bet_utils; for (j in 1:N) { for (k in 1:T) { diff --git a/commons/stan_files/choiceRT_ddm.stan b/commons/stan_files/choiceRT_ddm.stan index dde21623..f18a905e 100644 --- a/commons/stan_files/choiceRT_ddm.stan +++ b/commons/stan_files/choiceRT_ddm.stan @@ -1,15 +1,15 @@ -#include /pre/license.stan +#include /include/license.stan // based on codes/comments by Guido Biele, Joseph Burling, Andrew Ellis, and potentially others @ Stan mailing lists data { int N; // Number of subjects int Nu_max; // Max (across subjects) number of upper boundary responses int Nl_max; // Max (across subjects) number of lower boundary responses - int Nu[N]; // Number of upper boundary responses for each subj - int Nl[N]; // Number of lower boundary responses for each subj - real RTu[N, Nu_max]; // upper boundary response times - real RTl[N, Nl_max]; // lower boundary response times - real minRT[N]; // minimum RT for each subject of the observed data + array[N] int Nu; // Number of upper boundary responses for each subj + array[N] int Nl; // Number of lower boundary responses for each subj + array[N, Nu_max] real RTu; // upper boundary response times + array[N, Nl_max] real RTl; // lower boundary response times + array[N] real minRT; // minimum RT for each subject of the observed data real RTbound; // lower bound or RT across all subjects (e.g., 0.1 second) } @@ -79,7 +79,7 @@ generated quantities { real mu_tau; // nondecision time // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // Assign group level parameter values mu_alpha = exp(mu_pr[1]); diff --git a/commons/stan_files/choiceRT_ddm_single.stan b/commons/stan_files/choiceRT_ddm_single.stan index 95e0bc1b..91ad5e39 100644 --- a/commons/stan_files/choiceRT_ddm_single.stan +++ b/commons/stan_files/choiceRT_ddm_single.stan @@ -1,11 +1,11 @@ -#include /pre/license.stan +#include /include/license.stan // based on codes/comments by Guido Biele, Joseph Burling, Andrew Ellis, and potentially others @ Stan mailing lists data { int Nu; // of upper boundary responses int Nl; // of lower boundary responses - real RTu[Nu]; // upper boundary response times - real RTl[Nl]; // lower boundary response times + array[Nu] real RTu; // upper boundary response times + array[Nl] real RTl; // lower boundary response times real minRT; // minimum RT of the observed data real RTbound; // lower bound or RT (e.g., 0.1 second) } diff --git a/commons/stan_files/choiceRT_lba.stan b/commons/stan_files/choiceRT_lba.stan index 222e5a27..22c87795 100644 --- a/commons/stan_files/choiceRT_lba.stan +++ b/commons/stan_files/choiceRT_lba.stan @@ -1,4 +1,4 @@ -#include /pre/license.stan +#include /include/license.stan // The model published in Annis, J., Miller, B. J., & Palmeri, T. J. (2016). // Bayesian inference with Stan: A tutorial on adding custom distributions. Behavior research methods, 1-24. @@ -17,16 +17,16 @@ functions { b_tv_ts = (b - t * v_pdf)/(t * s); term_1b = v_pdf * Phi(b_A_tv_ts); - term_2b = s * exp(normal_lpdf(fabs(b_A_tv_ts) | 0, 1)); + term_2b = s * exp(normal_lpdf(abs(b_A_tv_ts) | 0, 1)); term_3b = v_pdf * Phi(b_tv_ts); - term_4b = s * exp(normal_lpdf(fabs(b_tv_ts) | 0, 1)); + term_4b = s * exp(normal_lpdf(abs(b_tv_ts) | 0, 1)); pdf = (1/A) * (-term_1b + term_2b + term_3b - term_4b); return pdf; } - real lba_cdf(real t, real b, real A, real v_cdf, real s) { + real lba_cdf_fun(real t, real b, real A, real v_cdf, real s) { //CDF of the LBA model real b_A_tv; real b_tv; @@ -43,8 +43,8 @@ functions { term_1a = b_A_tv/A * Phi(b_A_tv/ts); term_2a = b_tv/A * Phi(b_tv/ts); - term_3a = ts/A * exp(normal_lpdf(fabs(b_A_tv/ts) | 0, 1)); - term_4a = ts/A * exp(normal_lpdf(fabs(b_tv/ts) | 0, 1)); + term_3a = ts/A * exp(normal_lpdf(abs(b_A_tv/ts) | 0, 1)); + term_4a = ts/A * exp(normal_lpdf(abs(b_tv/ts) | 0, 1)); cdf = 1 + term_1a - term_2a + term_3a - term_4a; @@ -70,7 +70,7 @@ functions { if (RT[2, i] == j) { pdf = lba_pdf(t, b, A, v[j], s); } else { - cdf *= lba_cdf(t, b, A, v[j], s); + cdf *= lba_cdf_fun(t, b, A, v[j], s); } } prob_neg = 1; @@ -99,9 +99,9 @@ functions { vector[num_elements(v)] drift; int max_iter; int iter; - real start[num_elements(v)]; - real ttf[num_elements(v)]; - int resp[num_elements(v)]; + array[num_elements(v)] real start; + array[num_elements(v)] real ttf; + array[num_elements(v)] int resp; real rt; vector[2] pred; real b; @@ -141,7 +141,7 @@ functions { //if one is negative get the positive drift resp = sort_indices_asc(ttf); { - real temp_ttf[num_elements(v)]; + array[num_elements(v)] real temp_ttf; temp_ttf = sort_asc(ttf); ttf = temp_ttf; } @@ -164,8 +164,8 @@ data { int Max_tr; int N_choices; int N_cond; - int N_tr_cond[N, N_cond]; - matrix[2, Max_tr] RT[N, N_cond]; + array[N, N_cond] int N_tr_cond; + array[N, N_cond] matrix[2, Max_tr] RT; } @@ -174,19 +174,19 @@ parameters { real mu_d; real mu_A; real mu_tau; - vector[N_choices] mu_v[N_cond]; + array[N_cond] vector[N_choices] mu_v; // Hyperparameter sigmas real sigma_d; real sigma_A; real sigma_tau; - vector[N_choices] sigma_v[N_cond]; + array[N_cond] vector[N_choices] sigma_v; // Individual parameters - real d[N]; - real A[N]; - real tau[N]; - vector[N_choices] v[N, N_cond]; + array[N] real d; + array[N] real A; + array[N] real tau; + array[N, N_cond] vector[N_choices] v; } transformed parameters { // s is set to 1 to make model identifiable @@ -240,10 +240,10 @@ generated quantities { int n_trials; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - matrix[2, Max_tr] y_pred[N, N_cond]; + array[N, N_cond] matrix[2, Max_tr] y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/choiceRT_lba_single.stan b/commons/stan_files/choiceRT_lba_single.stan index 1d5fd992..b0696dd9 100644 --- a/commons/stan_files/choiceRT_lba_single.stan +++ b/commons/stan_files/choiceRT_lba_single.stan @@ -1,4 +1,4 @@ -#include /pre/license.stan +#include /include/license.stan // The model published in Annis, J., Miller, B. J., & Palmeri, T. J. (2016). // Bayesian inference with Stan: A tutorial on adding custom distributions. Behavior research methods, 1-24. @@ -26,7 +26,7 @@ functions { return pdf; } - real lba_cdf(real t, real b, real A, real v, real s) { + real lba_cdf_fun(real t, real b, real A, real v, real s) { //CDF of the LBA model real b_A_tv; real b_tv; @@ -72,7 +72,7 @@ functions { if (RT[2, i] == j) { pdf = lba_pdf(t, b, A, v[j], s); } else { - cdf *= (1-lba_cdf(t, b, A, v[j], s)); + cdf *= (1-lba_cdf_fun(t, b, A, v[j], s)); } } prob_neg = 1; @@ -101,9 +101,9 @@ functions { vector[num_elements(v)] drift; int max_iter; int iter; - real start[num_elements(v)]; - real ttf[num_elements(v)]; - int resp[num_elements(v)]; + array[num_elements(v)] real start; + array[num_elements(v)] real ttf; + array[num_elements(v)] int resp; real rt; vector[2] pred; real b; @@ -143,7 +143,7 @@ functions { //if one is negative get the positive drift resp = sort_indices_asc(ttf); { - real temp_ttf[num_elements(v)]; + array[num_elements(v)] real temp_ttf; temp_ttf = sort_asc(ttf); ttf = temp_ttf; } @@ -164,16 +164,16 @@ functions { data { int N_choice; int N_cond; - int tr_cond[N_cond]; + array[N_cond] int tr_cond; int max_tr; - matrix[2, max_tr] RT[N_cond]; + array[N_cond] matrix[2, max_tr] RT; } parameters { real d; real A; real tau; - vector[N_choice] v[N_cond]; + array[N_cond] vector[N_choice] v; } transformed parameters { real s; @@ -209,7 +209,7 @@ generated quantities { real log_lik; // For posterior predictive check - matrix[2, max_tr] y_pred[N_cond]; + array[N_cond] matrix[2, max_tr] y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (j in 1:N_cond) { diff --git a/commons/stan_files/cra_exp.stan b/commons/stan_files/cra_exp.stan index 86a44a0e..1641087e 100644 --- a/commons/stan_files/cra_exp.stan +++ b/commons/stan_files/cra_exp.stan @@ -1,4 +1,4 @@ -#include /pre/license.stan +#include /include/license.stan /** * Choice under Risk and Ambiguity Task @@ -18,13 +18,13 @@ functions { data { int N; // Number of subjects int T; // Max number of trials across subjects - int Tsubj[N]; // Number of trials/block for each subject + array[N] int Tsubj; // Number of trials/block for each subject - int choice[N, T]; // The options subjects choose (0: fixed / 1: variable) - real prob[N, T]; // The objective probability of the variable lottery - real ambig[N, T]; // The ambiguity level of the variable lottery (0 for risky lottery) - real reward_var[N, T]; // The amount of reward values on variable lotteries (risky and ambiguity conditions) - real reward_fix[N, T]; // The amount of reward values on fixed lotteries (reference) + array[N, T] int choice; // The options subjects choose (0: fixed / 1: variable) + array[N, T] real prob; // The objective probability of the variable lottery + array[N, T] real ambig; // The ambiguity level of the variable lottery (0 for risky lottery) + array[N, T] real reward_var; // The amount of reward values on variable lotteries (risky and ambiguity conditions) + array[N, T] real reward_fix; // The amount of reward values on fixed lotteries (reference) } // Declare all parameters as vectors for vectorizing @@ -82,16 +82,16 @@ generated quantities { real mu_gamma; // For log likelihood calculation for each subject - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Model regressors - real sv[N, T]; - real sv_fix[N, T]; - real sv_var[N, T]; - real p_var[N, T]; + array[N, T] real sv; + array[N, T] real sv_fix; + array[N, T] real sv_var; + array[N, T] real p_var; // Set all posterior predictions to -1 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/cra_linear.stan b/commons/stan_files/cra_linear.stan index b8653c85..5baddba0 100644 --- a/commons/stan_files/cra_linear.stan +++ b/commons/stan_files/cra_linear.stan @@ -1,4 +1,4 @@ -#include /pre/license.stan +#include /include/license.stan /** * Choice under Risk and Ambiguity Task @@ -18,13 +18,13 @@ functions { data { int N; // Number of subjects int T; // Max number of trials across subjects - int Tsubj[N]; // Number of trials/block for each subject + array[N] int Tsubj; // Number of trials/block for each subject - int choice[N, T]; // The options subjects choose (0: fixed / 1: variable) - real prob[N, T]; // The objective probability of the variable lottery - real ambig[N, T]; // The ambiguity level of the variable lottery (0 for risky lottery) - real reward_var[N, T]; // The amount of reward values on variable lotteries (risky and ambiguity conditions) - real reward_fix[N, T]; // The amount of reward values on fixed lotteries (reference) + array[N, T] int choice; // The options subjects choose (0: fixed / 1: variable) + array[N, T] real prob; // The objective probability of the variable lottery + array[N, T] real ambig; // The ambiguity level of the variable lottery (0 for risky lottery) + array[N, T] real reward_var; // The amount of reward values on variable lotteries (risky and ambiguity conditions) + array[N, T] real reward_fix; // The amount of reward values on fixed lotteries (reference) } // Declare all parameters as vectors for vectorizing @@ -82,16 +82,16 @@ generated quantities { real mu_gamma; // For log likelihood calculation for each subject - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Model regressors - real sv[N, T]; - real sv_fix[N, T]; - real sv_var[N, T]; - real p_var[N, T]; + array[N, T] real sv; + array[N, T] real sv_fix; + array[N, T] real sv_var; + array[N, T] real p_var; // Set all posterior predictions to -1 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/dbdm_prob_weight.stan b/commons/stan_files/dbdm_prob_weight.stan index ee248835..c9fc36af 100644 --- a/commons/stan_files/dbdm_prob_weight.stan +++ b/commons/stan_files/dbdm_prob_weight.stan @@ -1,16 +1,16 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - int choice[N, T]; - real opt1hprob[N, T]; - real opt2hprob[N, T]; - real opt1hval[N, T]; - real opt1lval[N, T]; - real opt2hval[N, T]; - real opt2lval[N, T]; + array[N] int Tsubj; + array[N, T] int choice; + array[N, T] real opt1hprob; + array[N, T] real opt2hprob; + array[N, T] real opt1hval; + array[N, T] real opt1lval; + array[N, T] real opt2hval; + array[N, T] real opt2lval; } transformed data { } @@ -69,20 +69,20 @@ model { if (opt1lval[i,t]>= 0) { U_opt[1] = w_prob[1]*(opt1hval[i,t]^rho[i]) + w_prob[2]*(opt1lval[i,t]^rho[i]); } else { - U_opt[1] = w_prob[1]*(opt1hval[i,t]^rho[i]) - w_prob[2]*(fabs(opt1lval[i,t])^rho[i])*lambda[i]; + U_opt[1] = w_prob[1]*(opt1hval[i,t]^rho[i]) - w_prob[2]*(abs(opt1lval[i,t])^rho[i])*lambda[i]; } } else { - U_opt[1] = -w_prob[1]*(fabs(opt1hval[i,t])^rho[i])*lambda[i] - w_prob[2]*(fabs(opt1lval[i,t])^rho[i])*lambda[i]; + U_opt[1] = -w_prob[1]*(abs(opt1hval[i,t])^rho[i])*lambda[i] - w_prob[2]*(abs(opt1lval[i,t])^rho[i])*lambda[i]; } if (opt2hval[i,t] > 0) { if (opt2lval[i,t] >= 0) { U_opt[2] = w_prob[3]*(opt2hval[i,t]^rho[i]) + w_prob[4]*(opt2lval[i,t]^rho[i]); } else { - U_opt[2] = w_prob[3]*(opt2hval[i,t]^rho[i]) - w_prob[4]*(fabs(opt2lval[i,t])^rho[i])*lambda[i]; + U_opt[2] = w_prob[3]*(opt2hval[i,t]^rho[i]) - w_prob[4]*(abs(opt2lval[i,t])^rho[i])*lambda[i]; } } else { - U_opt[2] = -w_prob[3]*(fabs(opt2hval[i,t])^rho[i])*lambda[i] -w_prob[4]*(fabs(opt2lval[i,t])^rho[i])*lambda[i]; + U_opt[2] = -w_prob[3]*(abs(opt2hval[i,t])^rho[i])*lambda[i] -w_prob[4]*(abs(opt2lval[i,t])^rho[i])*lambda[i]; } // compute action probabilities choice[i, t] ~ categorical_logit(U_opt*beta[i]); @@ -95,9 +95,9 @@ generated quantities { real mu_rho; real mu_lambda; real mu_beta; - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N,T]; + array[N,T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { for (t in 1:T) { @@ -127,20 +127,20 @@ generated quantities { if (opt1lval[i,t]>= 0) { U_opt[1] = w_prob[1]*(opt1hval[i,t]^rho[i]) + w_prob[2]*(opt1lval[i,t]^rho[i]); } else { - U_opt[1] = w_prob[1]*(opt1hval[i,t]^rho[i]) - w_prob[2]*(fabs(opt1lval[i,t])^rho[i])*lambda[i]; + U_opt[1] = w_prob[1]*(opt1hval[i,t]^rho[i]) - w_prob[2]*(abs(opt1lval[i,t])^rho[i])*lambda[i]; } } else { - U_opt[1] = -w_prob[1]*(fabs(opt1hval[i,t])^rho[i])*lambda[i] - w_prob[2]*(fabs(opt1lval[i,t])^rho[i])*lambda[i]; + U_opt[1] = -w_prob[1]*(abs(opt1hval[i,t])^rho[i])*lambda[i] - w_prob[2]*(abs(opt1lval[i,t])^rho[i])*lambda[i]; } if (opt2hval[i,t] > 0) { if (opt2lval[i,t] >= 0) { U_opt[2] = w_prob[3]*(opt2hval[i,t]^rho[i]) + w_prob[4]*(opt2lval[i,t]^rho[i]); } else { - U_opt[2] = w_prob[3]*(opt2hval[i,t]^rho[i]) - w_prob[4]*(fabs(opt2lval[i,t])^rho[i])*lambda[i]; + U_opt[2] = w_prob[3]*(opt2hval[i,t]^rho[i]) - w_prob[4]*(abs(opt2lval[i,t])^rho[i])*lambda[i]; } } else { - U_opt[2] = -w_prob[3]*(fabs(opt2hval[i,t])^rho[i])*lambda[i] -w_prob[4]*(fabs(opt2lval[i,t])^rho[i])*lambda[i]; + U_opt[2] = -w_prob[3]*(abs(opt2hval[i,t])^rho[i])*lambda[i] -w_prob[4]*(abs(opt2lval[i,t])^rho[i])*lambda[i]; } // compute action probabilities diff --git a/commons/stan_files/dd_cs.stan b/commons/stan_files/dd_cs.stan index d221d34a..1ac41cbf 100644 --- a/commons/stan_files/dd_cs.stan +++ b/commons/stan_files/dd_cs.stan @@ -1,14 +1,14 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - real delay_later[N, T]; - real amount_later[N, T]; - real delay_sooner[N, T]; - real amount_sooner[N, T]; - int choice[N, T]; // 0 for instant reward, 1 for delayed reward + array[N] int Tsubj; + array[N, T] real delay_later; + array[N, T] real amount_later; + array[N, T] real delay_sooner; + array[N, T] real amount_sooner; + array[N, T] int choice; // 0 for instant reward, 1 for delayed reward } transformed data { @@ -69,10 +69,10 @@ generated quantities { real mu_beta; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/dd_cs_single.stan b/commons/stan_files/dd_cs_single.stan index 2436b8b1..01e14487 100644 --- a/commons/stan_files/dd_cs_single.stan +++ b/commons/stan_files/dd_cs_single.stan @@ -1,12 +1,12 @@ -#include /pre/license.stan +#include /include/license.stan data { int Tsubj; - real delay_later[Tsubj]; - real amount_later[Tsubj]; - real delay_sooner[Tsubj]; - real amount_sooner[Tsubj]; - int choice[Tsubj]; // 0 for instant reward, 1 for delayed reward + array[Tsubj] real delay_later; + array[Tsubj] real amount_later; + array[Tsubj] real delay_sooner; + array[Tsubj] real amount_sooner; + array[Tsubj] int choice; // 0 for instant reward, 1 for delayed reward } transformed data { @@ -19,8 +19,8 @@ parameters { } transformed parameters { - real ev_later[Tsubj]; - real ev_sooner[Tsubj]; + array[Tsubj] real ev_later; + array[Tsubj] real ev_sooner; for (t in 1:Tsubj) { ev_later[t] = amount_later[t] * exp(-1* (pow(r * delay_later[t], s))); @@ -45,7 +45,7 @@ generated quantities { real log_lik; // For posterior predictive check - real y_pred[Tsubj]; + array[Tsubj] real y_pred; logR = log(r); diff --git a/commons/stan_files/dd_exp.stan b/commons/stan_files/dd_exp.stan index 3d772a5a..dd58cd61 100644 --- a/commons/stan_files/dd_exp.stan +++ b/commons/stan_files/dd_exp.stan @@ -1,14 +1,14 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - real delay_later[N, T]; - real amount_later[N, T]; - real delay_sooner[N, T]; - real amount_sooner[N, T]; - int choice[N, T]; // 0 for instant reward, 1 for delayed reward + array[N] int Tsubj; + array[N, T] real delay_later; + array[N, T] real amount_later; + array[N, T] real delay_sooner; + array[N, T] real amount_sooner; + array[N, T] int choice; // 0 for instant reward, 1 for delayed reward } transformed data { @@ -64,10 +64,10 @@ generated quantities { real mu_beta; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/dd_hyperbolic.stan b/commons/stan_files/dd_hyperbolic.stan index 1551304a..2a645732 100644 --- a/commons/stan_files/dd_hyperbolic.stan +++ b/commons/stan_files/dd_hyperbolic.stan @@ -1,14 +1,14 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - real delay_later[N, T]; - real amount_later[N, T]; - real delay_sooner[N, T]; - real amount_sooner[N, T]; - int choice[N, T]; // 0 for instant reward, 1 for delayed reward + array[N] int Tsubj; + array[N, T] real delay_later; + array[N, T] real amount_later; + array[N, T] real delay_sooner; + array[N, T] real amount_sooner; + array[N, T] int choice; // 0 for instant reward, 1 for delayed reward } transformed data { @@ -64,10 +64,10 @@ generated quantities { real mu_beta; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/dd_hyperbolic_single.stan b/commons/stan_files/dd_hyperbolic_single.stan index be3011f0..2a2e8d1d 100644 --- a/commons/stan_files/dd_hyperbolic_single.stan +++ b/commons/stan_files/dd_hyperbolic_single.stan @@ -1,12 +1,12 @@ -#include /pre/license.stan +#include /include/license.stan data { int Tsubj; - real delay_later[Tsubj]; - real amount_later[Tsubj]; - real delay_sooner[Tsubj]; - real amount_sooner[Tsubj]; - int choice[Tsubj]; // 0 for instant reward, 1 for delayed reward + array[Tsubj] real delay_later; + array[Tsubj] real amount_later; + array[Tsubj] real delay_sooner; + array[Tsubj] real amount_sooner; + array[Tsubj] int choice; // 0 for instant reward, 1 for delayed reward } transformed data { @@ -18,8 +18,8 @@ parameters { } transformed parameters { - real ev_later[Tsubj]; - real ev_sooner[Tsubj]; + array[Tsubj] real ev_later; + array[Tsubj] real ev_sooner; for (t in 1:Tsubj) { ev_later[t] = amount_later[t] / (1 + k * delay_later[t]); @@ -40,7 +40,7 @@ generated quantities { real log_lik; // For posterior predictive check - real y_pred[Tsubj]; + array[Tsubj] real y_pred; logK = log(k); diff --git a/commons/stan_files/gng_m1.stan b/commons/stan_files/gng_m1.stan index 5ac8abd0..aeac9f14 100644 --- a/commons/stan_files/gng_m1.stan +++ b/commons/stan_files/gng_m1.stan @@ -1,12 +1,12 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - int cue[N, T]; - int pressed[N, T]; - real outcome[N, T]; + array[N] int Tsubj; + array[N, T] int cue; + array[N, T] int pressed; + array[N, T] real outcome; } transformed data { @@ -82,14 +82,14 @@ generated quantities { real mu_xi; real mu_ep; real mu_rho; - real log_lik[N]; - real Qgo[N, T]; - real Qnogo[N, T]; - real Wgo[N, T]; - real Wnogo[N, T]; + array[N] real log_lik; + array[N, T] real Qgo; + array[N, T] real Qnogo; + array[N, T] real Wgo; + array[N, T] real Wnogo; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/gng_m2.stan b/commons/stan_files/gng_m2.stan index c9a8ced8..fe95ed89 100644 --- a/commons/stan_files/gng_m2.stan +++ b/commons/stan_files/gng_m2.stan @@ -1,12 +1,12 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - int cue[N, T]; - int pressed[N, T]; - real outcome[N, T]; + array[N] int Tsubj; + array[N, T] int cue; + array[N, T] int pressed; + array[N, T] real outcome; } transformed data { @@ -92,14 +92,14 @@ generated quantities { real mu_ep; real mu_b; real mu_rho; - real log_lik[N]; - real Qgo[N, T]; - real Qnogo[N, T]; - real Wgo[N, T]; - real Wnogo[N, T]; + array[N] real log_lik; + array[N, T] real Qgo; + array[N, T] real Qnogo; + array[N, T] real Wgo; + array[N, T] real Wnogo; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/gng_m3.stan b/commons/stan_files/gng_m3.stan index 2368ea1a..9ad5922e 100644 --- a/commons/stan_files/gng_m3.stan +++ b/commons/stan_files/gng_m3.stan @@ -1,12 +1,12 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - int cue[N, T]; - int pressed[N, T]; - real outcome[N, T]; + array[N] int Tsubj; + array[N, T] int cue; + array[N, T] int pressed; + array[N, T] real outcome; } transformed data { @@ -103,15 +103,15 @@ generated quantities { real mu_b; real mu_pi; real mu_rho; - real log_lik[N]; - real Qgo[N, T]; - real Qnogo[N, T]; - real Wgo[N, T]; - real Wnogo[N, T]; - real SV[N, T]; + array[N] real log_lik; + array[N, T] real Qgo; + array[N, T] real Qnogo; + array[N, T] real Wgo; + array[N, T] real Wnogo; + array[N, T] real SV; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/gng_m4.stan b/commons/stan_files/gng_m4.stan index 73e30cb1..5bf57889 100644 --- a/commons/stan_files/gng_m4.stan +++ b/commons/stan_files/gng_m4.stan @@ -1,12 +1,12 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - int cue[N, T]; - int pressed[N, T]; - real outcome[N, T]; + array[N] int Tsubj; + array[N, T] int cue; + array[N, T] int pressed; + array[N, T] real outcome; } transformed data { @@ -121,15 +121,15 @@ generated quantities { real mu_pi; real mu_rhoRew; real mu_rhoPun; - real log_lik[N]; - real Qgo[N, T]; - real Qnogo[N, T]; - real Wgo[N, T]; - real Wnogo[N, T]; - real SV[N, T]; + array[N] real log_lik; + array[N, T] real Qgo; + array[N, T] real Qnogo; + array[N, T] real Wgo; + array[N, T] real Wnogo; + array[N, T] real SV; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/igt_orl.stan b/commons/stan_files/igt_orl.stan index 6c94d80f..61067699 100644 --- a/commons/stan_files/igt_orl.stan +++ b/commons/stan_files/igt_orl.stan @@ -1,12 +1,12 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - int choice[N, T]; - real outcome[N, T]; - real sign_out[N, T]; + array[N] int Tsubj; + array[N, T] int choice; + array[N, T] real outcome; + array[N, T] real sign_out; } transformed data { vector[4] initV; @@ -122,10 +122,10 @@ generated quantities { real mu_betaP; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N,T]; + array[N,T] real y_pred; // Set all posterior predictions to -1 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/igt_pvl_decay.stan b/commons/stan_files/igt_pvl_decay.stan index 2d908a19..8f74bae2 100644 --- a/commons/stan_files/igt_pvl_decay.stan +++ b/commons/stan_files/igt_pvl_decay.stan @@ -1,11 +1,11 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - int choice[N, T]; - real outcome[N, T]; + array[N] int Tsubj; + array[N, T] int choice; + array[N, T] real outcome; } transformed data { vector[4] initV; @@ -82,10 +82,10 @@ generated quantities { real mu_lambda; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/igt_pvl_delta.stan b/commons/stan_files/igt_pvl_delta.stan index 05c6e870..dfb35a07 100644 --- a/commons/stan_files/igt_pvl_delta.stan +++ b/commons/stan_files/igt_pvl_delta.stan @@ -1,11 +1,11 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - int choice[N, T]; - real outcome[N, T]; + array[N] int Tsubj; + array[N, T] int choice; + array[N, T] real outcome; } transformed data { vector[4] initV; @@ -81,10 +81,10 @@ generated quantities { real mu_lambda; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/igt_vpp.stan b/commons/stan_files/igt_vpp.stan index 61c2b831..13924ed2 100644 --- a/commons/stan_files/igt_vpp.stan +++ b/commons/stan_files/igt_vpp.stan @@ -1,11 +1,11 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - int choice[N, T]; - real outcome[N, T]; + array[N] int Tsubj; + array[N, T] int choice; + array[N, T] real outcome; } transformed data { @@ -120,10 +120,10 @@ generated quantities { real mu_w; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/pre/license.stan b/commons/stan_files/include/license.stan similarity index 100% rename from commons/stan_files/pre/license.stan rename to commons/stan_files/include/license.stan diff --git a/commons/stan_files/peer_ocu.stan b/commons/stan_files/peer_ocu.stan index cd0c52d5..8e25fd4d 100644 --- a/commons/stan_files/peer_ocu.stan +++ b/commons/stan_files/peer_ocu.stan @@ -1,16 +1,16 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - int condition[N, T]; // 0: solo, 1: ss, 2: mix, 3: rr - real p_gamble[N, T]; - real safe_Hpayoff[N, T]; - real safe_Lpayoff[N, T]; - real risky_Hpayoff[N, T]; - real risky_Lpayoff[N, T]; - int choice[N, T]; + array[N] int Tsubj; + array[N, T] int condition; // 0: solo, 1: ss, 2: mix, 3: rr + array[N, T] real p_gamble; + array[N, T] real safe_Hpayoff; + array[N, T] real safe_Lpayoff; + array[N, T] real risky_Hpayoff; + array[N, T] real risky_Lpayoff; + array[N, T] int choice; } transformed data { @@ -71,10 +71,10 @@ generated quantities { real mu_ocu; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/prl_ewa.stan b/commons/stan_files/prl_ewa.stan index 234cf467..e5842a44 100644 --- a/commons/stan_files/prl_ewa.stan +++ b/commons/stan_files/prl_ewa.stan @@ -1,4 +1,4 @@ -#include /pre/license.stan +#include /include/license.stan /** * Probabilistic Reversal Learning (PRL) Task @@ -9,10 +9,10 @@ data { int N; // Number of subjects int T; // Maximum number of trials across subjects - int Tsubj[N]; // Number of trials/blocks for each subject + array[N] int Tsubj; // Number of trials/blocks for each subject - int choice[N, T]; // The choices subjects made - real outcome[N, T]; // The outcome + array[N, T] int choice; // The choices subjects made + array[N, T] real outcome; // The outcome } transformed data { @@ -97,19 +97,19 @@ generated quantities { real mu_beta; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For model regressors //real mr_ev[N, T, 2]; // Expected value - real ev_c[N, T]; // Expected value of the chosen option - real ev_nc[N, T]; // Expected value of the non-chosen option + array[N, T] real ev_c; // Expected value of the chosen option + array[N, T] real ev_nc; // Expected value of the non-chosen option //real mr_ew[N, T, 2]; // Experience weight - real ew_c[N, T]; // Experience weight of the chosen option - real ew_nc[N, T]; // Experience weight of the non-chosen option + array[N, T] real ew_c; // Experience weight of the chosen option + array[N, T] real ew_nc; // Experience weight of the non-chosen option // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions, model regressors to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/prl_fictitious.stan b/commons/stan_files/prl_fictitious.stan index 0fb8d486..1d957e71 100644 --- a/commons/stan_files/prl_fictitious.stan +++ b/commons/stan_files/prl_fictitious.stan @@ -1,4 +1,4 @@ -#include /pre/license.stan +#include /include/license.stan /** * Probabilistic Reversal Learning (PRL) Task @@ -9,9 +9,9 @@ data { int N; // Number of subjects int T; // Maximum number of trials across subjects - int Tsubj[N]; // Number of trials/blocks for each subject - int choice[N, T]; // The choices subjects made - real outcome[N, T]; // The outcome + array[N] int Tsubj; // Number of trials/blocks for each subject + array[N, T] int choice; // The choices subjects made + array[N, T] real outcome; // The outcome } transformed data { @@ -94,18 +94,18 @@ generated quantities { real mu_beta; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For model regressors - real ev_c[N, T]; // Expected value of the chosen option - real ev_nc[N, T]; // Expected value of the non-chosen option + array[N, T] real ev_c; // Expected value of the chosen option + array[N, T] real ev_nc; // Expected value of the non-chosen option - real pe_c[N, T]; //Prediction error of the chosen option - real pe_nc[N, T]; //Prediction error of the non-chosen option - real dv[N, T]; //Decision value = PE_chosen - PE_non-chosen + array[N, T] real pe_c; //Prediction error of the chosen option + array[N, T] real pe_nc; //Prediction error of the non-chosen option + array[N, T] real dv; //Decision value = PE_chosen - PE_non-chosen // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions, model regressors to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/prl_fictitious_multipleB.stan b/commons/stan_files/prl_fictitious_multipleB.stan index 264d6c8f..0ae30193 100644 --- a/commons/stan_files/prl_fictitious_multipleB.stan +++ b/commons/stan_files/prl_fictitious_multipleB.stan @@ -1,4 +1,4 @@ -#include /pre/license.stan +#include /include/license.stan /** * Probabilistic Reversal Learning (PRL) Task @@ -10,13 +10,13 @@ data { int N; // Number of subjects int B; // Max number of blocks across subjects - int Bsubj[N]; // Number of blocks for each subject + array[N] int Bsubj; // Number of blocks for each subject int T; // Max number of trials across subjects - int Tsubj[N, B]; // Number of trials/block for each subject + array[N, B] int Tsubj; // Number of trials/block for each subject - int choice[N, B, T]; // Choice for each subject-block-trial - real outcome[N, B, T]; // Outcome (reward/loss) for each subject-block-trial + array[N, B, T] int choice; // Choice for each subject-block-trial + array[N, B, T] real outcome; // Outcome (reward/loss) for each subject-block-trial } transformed data { @@ -101,18 +101,18 @@ generated quantities { real mu_beta; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For model regressors - real ev_c[N, B, T]; // Expected value of the chosen option - real ev_nc[N, B, T]; // Expected value of the non-chosen option + array[N, B, T] real ev_c; // Expected value of the chosen option + array[N, B, T] real ev_nc; // Expected value of the non-chosen option - real pe_c[N, B, T]; //Prediction error of the chosen option - real pe_nc[N, B, T]; //Prediction error of the non-chosen option - real dv[N, B, T]; //Decision value = PE_chosen - PE_non-chosen + array[N, B, T] real pe_c; //Prediction error of the chosen option + array[N, B, T] real pe_nc; //Prediction error of the non-chosen option + array[N, B, T] real dv; //Decision value = PE_chosen - PE_non-chosen // For posterior predictive check - real y_pred[N, B, T]; + array[N, B, T] real y_pred; // Set all posterior predictions, model regressors to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/prl_fictitious_rp.stan b/commons/stan_files/prl_fictitious_rp.stan index daa0779c..414969ae 100644 --- a/commons/stan_files/prl_fictitious_rp.stan +++ b/commons/stan_files/prl_fictitious_rp.stan @@ -1,4 +1,4 @@ -#include /pre/license.stan +#include /include/license.stan /** * Probabilistic Reversal Learning (PRL) Task @@ -9,9 +9,9 @@ data { int N; // Number of subjects int T; // Max number of trials across subjects - int Tsubj[N]; // Number of trials/blocks for each subject - int choice[N, T]; // The choices subjects made - real outcome[N, T]; // The outcome + array[N] int Tsubj; // Number of trials/blocks for each subject + array[N, T] int choice; // The choices subjects made + array[N, T] real outcome; // The outcome } transformed data { @@ -104,19 +104,19 @@ generated quantities { real mu_beta; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For model regressors - real ev_c[N, T]; // Expected value of the chosen option - real ev_nc[N, T]; // Expected value of the non-chosen option + array[N, T] real ev_c; // Expected value of the chosen option + array[N, T] real ev_nc; // Expected value of the non-chosen option - real pe_c[N, T]; // Prediction error of the chosen option - real pe_nc[N, T]; // Prediction error of the non-chosen option + array[N, T] real pe_c; // Prediction error of the chosen option + array[N, T] real pe_nc; // Prediction error of the non-chosen option - real dv[N, T]; // Decision value = PE_chosen - PE_non-chosen + array[N, T] real dv; // Decision value = PE_chosen - PE_non-chosen // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Initialize all the variables to avoid NULL values for (i in 1:N) { diff --git a/commons/stan_files/prl_fictitious_rp_woa.stan b/commons/stan_files/prl_fictitious_rp_woa.stan index 48f78a42..c9763e81 100644 --- a/commons/stan_files/prl_fictitious_rp_woa.stan +++ b/commons/stan_files/prl_fictitious_rp_woa.stan @@ -1,4 +1,4 @@ -#include /pre/license.stan +#include /include/license.stan /** * Probabilistic Reversal Learning (PRL) Task @@ -9,9 +9,9 @@ data { int N; // Number of subjects int T; // Max number of trials across subjects - int Tsubj[N]; // Number of trials/blocks for each subject - int choice[N, T]; // The choices subjects made - real outcome[N, T]; // The outcome + array[N] int Tsubj; // Number of trials/blocks for each subject + array[N, T] int choice; // The choices subjects made + array[N, T] real outcome; // The outcome } transformed data { @@ -97,19 +97,19 @@ generated quantities { real mu_beta; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For model regressors - real ev_c[N, T]; // Expected value of the chosen option - real ev_nc[N, T]; // Expected value of the non-chosen option + array[N, T] real ev_c; // Expected value of the chosen option + array[N, T] real ev_nc; // Expected value of the non-chosen option - real pe_c[N, T]; // Prediction error of the chosen option - real pe_nc[N, T]; // Prediction error of the non-chosen option + array[N, T] real pe_c; // Prediction error of the chosen option + array[N, T] real pe_nc; // Prediction error of the non-chosen option - real dv[N, T]; // Decision value = PE_chosen - PE_non-chosen + array[N, T] real dv; // Decision value = PE_chosen - PE_non-chosen // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Initialize all the variables to avoid NULL values for (i in 1:N) { diff --git a/commons/stan_files/prl_fictitious_woa.stan b/commons/stan_files/prl_fictitious_woa.stan index 58a4053f..8dc18cb0 100644 --- a/commons/stan_files/prl_fictitious_woa.stan +++ b/commons/stan_files/prl_fictitious_woa.stan @@ -1,4 +1,4 @@ -#include /pre/license.stan +#include /include/license.stan /** * Probabilistic Reversal Learning (PRL) Task @@ -9,9 +9,9 @@ data { int N; // Number of subjects int T; // Maximum number of trials across subjects - int Tsubj[N]; // Number of trials/blocks for each subject - int choice[N, T]; // The choices subjects made - real outcome[N, T]; // The outcome + array[N] int Tsubj; // Number of trials/blocks for each subject + array[N, T] int choice; // The choices subjects made + array[N, T] real outcome; // The outcome } transformed data { @@ -87,18 +87,18 @@ generated quantities { real mu_beta; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For model regressors - real ev_c[N, T]; // Expected value of the chosen option - real ev_nc[N, T]; // Expected value of the non-chosen option + array[N, T] real ev_c; // Expected value of the chosen option + array[N, T] real ev_nc; // Expected value of the non-chosen option - real pe_c[N, T]; //Prediction error of the chosen option - real pe_nc[N, T]; //Prediction error of the non-chosen option - real dv[N, T]; //Decision value = PE_chosen - PE_non-chosen + array[N, T] real pe_c; //Prediction error of the chosen option + array[N, T] real pe_nc; //Prediction error of the non-chosen option + array[N, T] real dv; //Decision value = PE_chosen - PE_non-chosen // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions, model regressors to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/prl_rp.stan b/commons/stan_files/prl_rp.stan index a7303744..67f3c77f 100644 --- a/commons/stan_files/prl_rp.stan +++ b/commons/stan_files/prl_rp.stan @@ -1,4 +1,4 @@ -#include /pre/license.stan +#include /include/license.stan /** * Probabilistic Reversal Learning (PRL) Task @@ -9,10 +9,10 @@ data { int N; // Number of subjects int T; // Maximum number of trials across subjects - int Tsubj[N]; // Number of trials/blocks for each subject + array[N] int Tsubj; // Number of trials/blocks for each subject - int choice[N, T]; // The choices subjects made - real outcome[N, T]; // The outcome + array[N, T] int choice; // The choices subjects made + array[N, T] real outcome; // The outcome } transformed data { @@ -87,15 +87,15 @@ generated quantities { real mu_beta; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For model regressors - real ev_c[N, T]; // Expected value of the chosen option - real ev_nc[N, T]; // Expected value of the non-chosen option - real pe[N, T]; // Prediction error + array[N, T] real ev_c; // Expected value of the chosen option + array[N, T] real ev_nc; // Expected value of the non-chosen option + array[N, T] real pe; // Prediction error // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Initialize all the variables to avoid NULL values for (i in 1:N) { diff --git a/commons/stan_files/prl_rp_multipleB.stan b/commons/stan_files/prl_rp_multipleB.stan index 8cd77c43..dfe6d3aa 100644 --- a/commons/stan_files/prl_rp_multipleB.stan +++ b/commons/stan_files/prl_rp_multipleB.stan @@ -1,4 +1,4 @@ -#include /pre/license.stan +#include /include/license.stan /** * Probabilistic Reversal Learning (PRL) Task @@ -10,13 +10,13 @@ data { int N; // Number of subjects int B; // Maximum number of blocks across subjects - int Bsubj[N]; // Number of blocks for each subject + array[N] int Bsubj; // Number of blocks for each subject int T; // Maximum number of trials across subjects - int Tsubj[N, B]; // Number of trials/blocks for each subject + array[N, B] int Tsubj; // Number of trials/blocks for each subject - int choice[N, B, T]; // The choices subjects made - real outcome[N, B, T]; // The outcome + array[N, B, T] int choice; // The choices subjects made + array[N, B, T] real outcome; // The outcome } transformed data { @@ -93,15 +93,15 @@ generated quantities { real mu_beta; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For model regressors - real ev_c[N, B, T]; // Expected value of the chosen option - real ev_nc[N, B, T]; // Expected value of the non-chosen option - real pe[N, B, T]; // Prediction error + array[N, B, T] real ev_c; // Expected value of the chosen option + array[N, B, T] real ev_nc; // Expected value of the non-chosen option + array[N, B, T] real pe; // Prediction error // For posterior predictive check - real y_pred[N, B, T]; + array[N, B, T] real y_pred; // Initialize all the variables to avoid NULL values for (i in 1:N) { diff --git a/commons/stan_files/pstRT_ddm.stan b/commons/stan_files/pstRT_ddm.stan index 6ac7f390..d96893ca 100644 --- a/commons/stan_files/pstRT_ddm.stan +++ b/commons/stan_files/pstRT_ddm.stan @@ -41,14 +41,14 @@ functions{ data { int N; // Number of subjects int T; // Maximum number of trials - int Tsubj[N]; // Number of trials for each subject + array[N] int Tsubj; // Number of trials for each subject int n_cond; // Number of task conditions - int cond[N, T]; // Task condition (NA: -1) - int choice[N, T]; // Response (NA: -1) - real RT[N, T]; // Response time - real minRT[N]; // Minimum RT for each subject of the observed data + array[N, T] int cond; // Task condition (NA: -1) + array[N, T] int choice; // Response (NA: -1) + array[N, T] real RT; // Response time + array[N] real minRT; // Minimum RT for each subject of the observed data real RTbound; // Lower bound or RT across all subjects (e.g., 0.1 second) - real prob[n_cond]; // Reward probability for each task condition (for posterior predictive check) + array[n_cond] real prob; // Reward probability for each task condition (for posterior predictive check) } transformed data { @@ -135,7 +135,7 @@ generated quantities { real mu_d3; // For log likelihood - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check (one-step method) matrix[N, T] choice_os; diff --git a/commons/stan_files/pstRT_rlddm1.stan b/commons/stan_files/pstRT_rlddm1.stan index 021bbf2a..e2088801 100644 --- a/commons/stan_files/pstRT_rlddm1.stan +++ b/commons/stan_files/pstRT_rlddm1.stan @@ -41,16 +41,16 @@ functions{ data { int N; // Number of subjects int T; // Maximum number of trials - int Tsubj[N]; // Number of trials for each subject + array[N] int Tsubj; // Number of trials for each subject int n_cond; // Number of task conditions - int cond[N, T]; // Task condition (NA: -1) - int choice[N, T]; // Response (NA: -1) - real RT[N, T]; // Response time - real fd[N, T]; // Feedback + array[N, T] int cond; // Task condition (NA: -1) + array[N, T] int choice; // Response (NA: -1) + array[N, T] real RT; // Response time + array[N, T] real fd; // Feedback real initQ; // Initial Q value - real minRT[N]; // Minimum RT for each subject of the observed data + array[N] real minRT; // Minimum RT for each subject of the observed data real RTbound; // Lower bound or RT across all subjects (e.g., 0.1 second) - real prob[n_cond]; // Reward probability for each task condition (for posterior predictive check) + array[n_cond] real prob; // Reward probability for each task condition (for posterior predictive check) } transformed data { @@ -133,7 +133,7 @@ generated quantities { real mu_alpha; // For log likelihood - real log_lik[N]; + array[N] real log_lik; // For model regressors matrix[N, T] Q1; diff --git a/commons/stan_files/pstRT_rlddm6.stan b/commons/stan_files/pstRT_rlddm6.stan index 56d0eed7..6d680a25 100644 --- a/commons/stan_files/pstRT_rlddm6.stan +++ b/commons/stan_files/pstRT_rlddm6.stan @@ -41,17 +41,17 @@ functions{ data { int N; // Number of subjects int T; // Maximum number of trials - int Tsubj[N]; // Number of trials for each subject - int Isubj[N, T]; // Trial number for each task condition + array[N] int Tsubj; // Number of trials for each subject + array[N, T] int Isubj; // Trial number for each task condition int n_cond; // Number of task conditions - int cond[N, T]; // Task condition (NA: -1) - int choice[N, T]; // Response (NA: -1) - real RT[N, T]; // Response time - real fd[N, T]; // Feedback + array[N, T] int cond; // Task condition (NA: -1) + array[N, T] int choice; // Response (NA: -1) + array[N, T] real RT; // Response time + array[N, T] real fd; // Feedback real initQ; // Initial Q value - real minRT[N]; // Minimum RT for each subject of the observed data + array[N] real minRT; // Minimum RT for each subject of the observed data real RTbound; // Lower bound or RT across all subjects (e.g., 0.1 second) - real prob[n_cond]; // Reward probability for each task condition (for posterior predictive check) + array[n_cond] real prob; // Reward probability for each task condition (for posterior predictive check) } transformed data { @@ -152,7 +152,7 @@ generated quantities { real mu_alpha_neg; // For log likelihood - real log_lik[N]; + array[N] real log_lik; // For model regressors matrix[N, T] Q1; diff --git a/commons/stan_files/pst_Q.stan b/commons/stan_files/pst_Q.stan index 4a6cbb37..a51860d8 100644 --- a/commons/stan_files/pst_Q.stan +++ b/commons/stan_files/pst_Q.stan @@ -1,14 +1,14 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; // Number of subjects int T; // Maximum # of trials - int Tsubj[N]; // # of trials for acquisition phase + array[N] int Tsubj; // # of trials for acquisition phase - int option1[N, T]; - int option2[N, T]; - int choice[N, T]; - real reward[N, T]; + array[N, T] int option1; + array[N, T] int option2; + array[N, T] int choice; + array[N, T] real reward; } transformed data { @@ -73,7 +73,7 @@ generated quantities { real mu_beta; // For log-likelihood calculation - real log_lik[N]; + array[N] real log_lik; mu_alpha = Phi_approx(mu_pr[1]); mu_beta = Phi_approx(mu_pr[2]) * 10; diff --git a/commons/stan_files/pst_gainloss_Q.stan b/commons/stan_files/pst_gainloss_Q.stan index 788b9a4e..c34fd277 100644 --- a/commons/stan_files/pst_gainloss_Q.stan +++ b/commons/stan_files/pst_gainloss_Q.stan @@ -1,14 +1,14 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; // Number of subjects int T; // Maximum # of trials - int Tsubj[N]; // # of trials for acquisition phase + array[N] int Tsubj; // # of trials for acquisition phase - int option1[N, T]; - int option2[N, T]; - int choice[N, T]; - real reward[N, T]; + array[N, T] int option1; + array[N, T] int option2; + array[N, T] int choice; + array[N, T] real reward; } transformed data { @@ -79,7 +79,7 @@ generated quantities { real mu_beta; // For log-likelihood calculation - real log_lik[N]; + array[N] real log_lik; mu_alpha_pos = Phi_approx(mu_pr[1]); mu_alpha_neg = Phi_approx(mu_pr[2]); diff --git a/commons/stan_files/ra_noLA.stan b/commons/stan_files/ra_noLA.stan index c5c599c4..1c0c61fd 100644 --- a/commons/stan_files/ra_noLA.stan +++ b/commons/stan_files/ra_noLA.stan @@ -1,13 +1,13 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - real gain[N, T]; - real loss[N, T]; // absolute loss amount - real cert[N, T]; - int gamble[N, T]; + array[N] int Tsubj; + array[N, T] real gain; + array[N, T] real loss; // absolute loss amount + array[N, T] real cert; + array[N, T] int gamble; } transformed data { @@ -57,10 +57,10 @@ generated quantities { real mu_rho; real mu_tau; - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/ra_noRA.stan b/commons/stan_files/ra_noRA.stan index 0f36c3be..67e4ccbe 100644 --- a/commons/stan_files/ra_noRA.stan +++ b/commons/stan_files/ra_noRA.stan @@ -1,13 +1,13 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - real gain[N, T]; - real loss[N, T]; // absolute loss amount - real cert[N, T]; - int gamble[N, T]; + array[N] int Tsubj; + array[N, T] real gain; + array[N, T] real loss; // absolute loss amount + array[N, T] real cert; + array[N, T] int gamble; } transformed data { @@ -58,10 +58,10 @@ generated quantities { real mu_lambda; real mu_tau; - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/ra_prospect.stan b/commons/stan_files/ra_prospect.stan index 542ea460..2fb74420 100644 --- a/commons/stan_files/ra_prospect.stan +++ b/commons/stan_files/ra_prospect.stan @@ -1,13 +1,13 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - real gain[N, T]; - real loss[N, T]; // absolute loss amount - real cert[N, T]; - int gamble[N, T]; + array[N] int Tsubj; + array[N, T] real gain; + array[N, T] real loss; // absolute loss amount + array[N, T] real cert; + array[N, T] int gamble; } transformed data { } @@ -59,10 +59,10 @@ generated quantities { real mu_lambda; real mu_tau; - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { @@ -84,7 +84,7 @@ generated quantities { real pGamble; evSafe = pow(cert[i, t], rho[i]); - evGamble = 0.5 * (pow(gain[i, t], rho[i]) - lambda[i] * pow(fabs(loss[i, t]), rho[i])); + evGamble = 0.5 * (pow(gain[i, t], rho[i]) - lambda[i] * pow(abs(loss[i, t]), rho[i])); pGamble = inv_logit(tau[i] * (evGamble - evSafe)); log_lik[i] += bernoulli_lpmf(gamble[i, t] | pGamble); diff --git a/commons/stan_files/rdt_happiness.stan b/commons/stan_files/rdt_happiness.stan index 3abb9e18..4a87f384 100644 --- a/commons/stan_files/rdt_happiness.stan +++ b/commons/stan_files/rdt_happiness.stan @@ -1,17 +1,17 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - real gain[N, T]; - real loss[N, T]; // absolute loss amount - real cert[N, T]; - int type[N, T]; - int gamble[N, T]; - real outcome[N, T]; - real happy[N, T]; - real RT_happy[N, T]; + array[N] int Tsubj; + array[N, T] real gain; + array[N, T] real loss; // absolute loss amount + array[N, T] real cert; + array[N, T] int type; + array[N, T] int gamble; + array[N, T] real outcome; + array[N, T] real happy; + array[N, T] real RT_happy; } transformed data { } @@ -91,10 +91,10 @@ generated quantities { real mu_gam; real mu_sig; - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/task2AFC_sdt.stan b/commons/stan_files/task2AFC_sdt.stan index 02e4a6ce..97b80d24 100644 --- a/commons/stan_files/task2AFC_sdt.stan +++ b/commons/stan_files/task2AFC_sdt.stan @@ -1,10 +1,10 @@ // Hierarchical Signal Detection Theory data { int N; - int h[N]; - int f[N]; - int signal[N]; - int noise[N]; + array[N] int h; + array[N] int f; + array[N] int signal; + array[N] int noise; } parameters { @@ -23,8 +23,8 @@ transformed parameters { vector[N] d; vector[N] c; - real thetah[N]; - real thetaf[N]; + array[N] real thetah; + array[N] real thetaf; for (i in 1:N){ d[i] = mu_pr[1] + sigma[1] * d_pr[i]; @@ -54,10 +54,10 @@ generated quantities{ real mu_d; real mu_c; - real log_lik[N, 2]; + array[N, 2] real log_lik; // For posterior predictive check - real y_pred[N, 2]; + array[N, 2] real y_pred; //set all posterior predictions to 0 (avoids NULL values) for (i in 1:N){ diff --git a/commons/stan_files/ts_par4.stan b/commons/stan_files/ts_par4.stan index c615f6d0..1022def3 100644 --- a/commons/stan_files/ts_par4.stan +++ b/commons/stan_files/ts_par4.stan @@ -1,12 +1,12 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - int level1_choice[N,T]; // 1: left, 2: right - int level2_choice[N,T]; // 1-4: 1/2: commonly associated with level1=1, 3/4: commonly associated with level1=2 - int reward[N,T]; + array[N] int Tsubj; + array[N,T] int level1_choice; // 1: left, 2: right + array[N,T] int level2_choice; // 1-4: 1/2: commonly associated with level1=1, 3/4: commonly associated with level1=2 + array[N,T] int reward; real trans_prob; } transformed data { @@ -113,11 +113,11 @@ generated quantities { real mu_w; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred_step1[N,T]; - real y_pred_step2[N,T]; + array[N,T] real y_pred_step1; + array[N,T] real y_pred_step2; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/ts_par6.stan b/commons/stan_files/ts_par6.stan index b472afa0..3ed451fd 100644 --- a/commons/stan_files/ts_par6.stan +++ b/commons/stan_files/ts_par6.stan @@ -1,12 +1,12 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - int level1_choice[N,T]; // 1: left, 2: right - int level2_choice[N,T]; // 1-4: 1/2: commonly associated with level1=1, 3/4: commonly associated with level1=2 - int reward[N,T]; + array[N] int Tsubj; + array[N,T] int level1_choice; // 1: left, 2: right + array[N,T] int level2_choice; // 1-4: 1/2: commonly associated with level1=1, 3/4: commonly associated with level1=2 + array[N,T] int reward; real trans_prob; } transformed data { @@ -123,11 +123,11 @@ generated quantities { real mu_w; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred_step1[N,T]; - real y_pred_step2[N,T]; + array[N,T] real y_pred_step1; + array[N,T] real y_pred_step2; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/ts_par7.stan b/commons/stan_files/ts_par7.stan index 089042c2..b7a654fc 100644 --- a/commons/stan_files/ts_par7.stan +++ b/commons/stan_files/ts_par7.stan @@ -1,12 +1,12 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - int level1_choice[N,T]; // 1: left, 2: right - int level2_choice[N,T]; // 1-4: 1/2: commonly associated with level1=1, 3/4: commonly associated with level1=2 - int reward[N,T]; + array[N] int Tsubj; + array[N,T] int level1_choice; // 1: left, 2: right + array[N,T] int level2_choice; // 1-4: 1/2: commonly associated with level1=1, 3/4: commonly associated with level1=2 + array[N,T] int reward; real trans_prob; } transformed data { @@ -127,11 +127,11 @@ generated quantities { real mu_lambda; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred_step1[N,T]; - real y_pred_step2[N,T]; + array[N,T] real y_pred_step1; + array[N,T] real y_pred_step2; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/ug_bayes.stan b/commons/stan_files/ug_bayes.stan index 6136e708..1649ca2c 100644 --- a/commons/stan_files/ug_bayes.stan +++ b/commons/stan_files/ug_bayes.stan @@ -1,11 +1,11 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - real offer[N, T]; - int accept[N, T]; + array[N] int Tsubj; + array[N, T] real offer; + array[N, T] int accept; } transformed data { @@ -36,9 +36,9 @@ parameters { transformed parameters { // Transform subject-level raw parameters - real alpha[N]; - real beta[N]; - real tau[N]; + array[N] real alpha; + array[N] real beta; + array[N] real tau; for (i in 1:N) { alpha[i] = Phi_approx(mu_pr[1] + sigma[1] * alpha_pr[i]) * 20; @@ -103,10 +103,10 @@ generated quantities { real mu_tau; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/ug_delta.stan b/commons/stan_files/ug_delta.stan index 9bb70e0a..93da09f8 100644 --- a/commons/stan_files/ug_delta.stan +++ b/commons/stan_files/ug_delta.stan @@ -1,11 +1,11 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; int T; - int Tsubj[N]; - real offer[N, T]; - int accept[N, T]; + array[N] int Tsubj; + array[N, T] real offer; + array[N, T] int accept; } transformed data { @@ -25,9 +25,9 @@ parameters { transformed parameters { // Transform subject-level raw parameters - real alpha[N]; - real tau[N]; - real ep[N]; + array[N] real alpha; + array[N] real tau; + array[N] real ep; for (i in 1:N) { alpha[i] = Phi_approx(mu_pr[1] + sigma[1] * alpha_pr[i]) * 20; @@ -79,10 +79,10 @@ generated quantities { real mu_ep; // For log likelihood calculation - real log_lik[N]; + array[N] real log_lik; // For posterior predictive check - real y_pred[N, T]; + array[N, T] real y_pred; // Set all posterior predictions to 0 (avoids NULL values) for (i in 1:N) { diff --git a/commons/stan_files/wcs_sql.stan b/commons/stan_files/wcs_sql.stan index 81b8ce17..65c5dad0 100644 --- a/commons/stan_files/wcs_sql.stan +++ b/commons/stan_files/wcs_sql.stan @@ -1,14 +1,14 @@ -#include /pre/license.stan +#include /include/license.stan data { int N; // number of subjects int T; // max trial - int Tsubj[N]; // number of max trials per subject + array[N] int Tsubj; // number of max trials per subject - int choice[N, 4, T]; // subject's deck choice within a trial (1, 2, 3 and 4) - int outcome[N, T]; // whether subject's choice is correct or not within a trial (1 and 0) - matrix[1, 3] choice_match_att[N, T]; // indicates which dimension the chosen card matches to within a trial - matrix[3, 4] deck_match_rule[T]; // indicates which dimension(color, form, number) each of the 4 decks matches to within a trial + array[N, 4, T] int choice; // subject's deck choice within a trial (1, 2, 3 and 4) + array[N, T] int outcome; // whether subject's choice is correct or not within a trial (1 and 0) + array[N, T] matrix[1, 3] choice_match_att; // indicates which dimension the chosen card matches to within a trial + array[T] matrix[3, 4] deck_match_rule; // indicates which dimension(color, form, number) each of the 4 decks matches to within a trial } transformed data { @@ -106,10 +106,10 @@ generated quantities { real mu_d; // for log-likelihood calculation - real log_lik[N]; + array[N] real log_lik; // for posterior predictive check - int y_pred[N, 4, T]; + array[N, 4, T] int y_pred; // initiate the variable to avoid NULL values for (i in 1:N) {