CCS-Lab / hBayesDM

Hierarchical Bayesian modeling of RLDM tasks, using R & Python
https://ccs-lab.github.io/hBayesDM
GNU General Public License v3.0
224 stars 113 forks source link

issue with ts_par7 #165

Open NicoBiagi opened 1 month ago

NicoBiagi commented 1 month ago

Hello,

I'm running the model ts_par4, ts_par6, and ts_par7 on my dataset. I successfully ran ts_par4 and ts_par6 on Friday, but when I try to run the ts_par7 today I had the following error.

Warning: 'length(x) = 109932 > 1' in coercion to 'logical(1)'Warning: 'length(x) = 109932 > 1' in coercion to 'logical(1)'
Model name  = ts_par7 

Details:
 # of chains                    = 4 
 # of cores used                = 8 
 # of MCMC samples (per chain)  = 4000 
 # of burn-in samples           = 1000 
 # of subjects                  = 146 
 # of (max) trials per subject  = 200 
 `trans_prob` is set to         = 0.7 

make cmd is
  make -f '/Library/Frameworks/R.framework/Resources/etc/Makeconf' -f '/Library/Frameworks/R.framework/Resources/share/make/shlib.mk' CXX='$(CXX17) $(CXX17STD)' CXXFLAGS='$(CXX17FLAGS)' CXXPICFLAGS='$(CXX17PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX17LDFLAGS)' SHLIB_LD='$(SHLIB_CXX17LD)' SHLIB='file1089b65346e51.so' OBJECTS='file1089b65346e51.o'

make would use
clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DUSE_STANC3 -DSTRICT_R_HEADERS  -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION  -D_HAS_AUTO_PTR_ETC=0  -include '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c file1089b65346e51.cpp -o file1089b65346e51.o
if test  "zfile1089b65346e51.o" != "z"; then \
      echo clang++ -arch arm64 -std=gnu++17 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L"/Library/Frameworks/R.framework/Resources/lib" -L/opt/R/arm64/lib -o file1089b65346e51.so file1089b65346e51.o  '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppParallel/lib/' -ltbb   -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation; \
      clang++ -arch arm64 -std=gnu++17 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L"/Library/Frameworks/R.framework/Resources/lib" -L/opt/R/arm64/lib -o file1089b65346e51.so file1089b65346e51.o  '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppParallel/lib/' -ltbb   -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation; \
    fi
Error in compileCode(f, code, language = language, verbose = verbose) : 
  In file included from <built-in>:1:In file included from /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp:22:In file included from /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppEigen/include/Eigen/Dense:1:In file included from /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppEigen/include/Eigen/Core:19:/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal error: 'cmath' file not found  679 | #include <cmath>      |          ^~~~~~~1 error generated.make: *** [file1089b65346e51.o] Error 1
Error in sink(type = "output") : invalid connection

I have tried to run ts_par4 ts_par6 and I get the same error messages (which I did not get on Friday).

This is the code I am using to create the df, rename the columns and run ts_par7

# select only the relevant columns for modelling
df <- data %>% 
  select(subject_id, stim_selected_stage1, stim_selected_stage2,  reward)

# give the appropriate column names
colnames(df) <- c("subjID", "level1_choice", "level2_choice", "reward")

# recode values in the columns
df <- df %>% 
  mutate(
    level1_choice = if_else(level1_choice==0,1,2),
    level2_choice = if_else(level2_choice==2,1,if_else(level2_choice==3,2,if_else(level2_choice==4,3,4)))
  )

# Run the model w
output_tspar7 <- ts_par7(
  data = df, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 8)

Does anyone know what I need to change? Many thanks, Nico

lehlsy0904 commented 3 weeks ago

Dear Nico,

It looks like the error message may be related to Stan compiling issues. Could you first try reinstalling the necessary packages using the code below?

install.packages(c("Rcpp", "RcppEigen", "StanHeaders", "rstan"))

Additionally, could you let me know your system details (e.g., macOS, Windows) so I can provide more targeted assistance and attempt to replicate the error?

Best, Eunhwi

NicoBiagi commented 1 week ago

Dear Eunhwi,

Thanks for your message.

I have run the code you provided but I still get the same error message

"> output_tspar7 <- ts_par7(

  • data = df, niter = 4000, nwarmup = 1000, nchain = 4, ncore = 8) Warning: 'length(x) = 138940 > 1' in coercion to 'logical(1)'Warning: 'length(x) = 138940 > 1' in coercion to 'logical(1)' Model name = ts_par7

Details:

of chains = 4

of cores used = 8

of MCMC samples (per chain) = 4000

of burn-in samples = 1000

of subjects = 188

of (max) trials per subject = 200

trans_prob is set to = 0.7

Trying to compile a simple C file Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/Rcpp/include/" -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppEigen/include/" -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppEigen/include/unsupported" -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/StanHeaders/include/" -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_HAS_AUTO_PTR_ETC=0 -include '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c foo.c -o foo.o In file included from :1: In file included from /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp:22: In file included from /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppEigen/include/Eigen/Dense:1: In file included from /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppEigen/include/Eigen/Core:19: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal error: 'cmath' file not found 679 | #include | ^~~ 1 error generated. make: *** [foo.o] Error 1 make cmd is make -f '/Library/Frameworks/R.framework/Resources/etc/Makeconf' -f '/Library/Frameworks/R.framework/Resources/share/make/shlib.mk' CXX='$(CXX17) $(CXX17STD)' CXXFLAGS='$(CXX17FLAGS)' CXXPICFLAGS='$(CXX17PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX17LDFLAGS)' SHLIB_LD='$(SHLIB_CXX17LD)' SHLIB='file32a61d435bcf.so' OBJECTS='file32a61d435bcf.o'

make would use clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/Rcpp/include/" -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppEigen/include/" -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppEigen/include/unsupported" -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/StanHeaders/include/" -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_HAS_AUTO_PTR_ETC=0 -include '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c file32a61d435bcf.cpp -o file32a61d435bcf.o if test "zfile32a61d435bcf.o" != "z"; then \ echo clang++ -arch arm64 -std=gnu++17 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L"/Library/Frameworks/R.framework/Resources/lib" -L/opt/R/arm64/lib -o file32a61d435bcf.so file32a61d435bcf.o '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppParallel/lib/' -ltbb -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation; \ clang++ -arch arm64 -std=gnu++17 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L"/Library/Frameworks/R.framework/Resources/lib" -L/opt/R/arm64/lib -o file32a61d435bcf.so file32a61d435bcf.o '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppParallel/lib/' -ltbb -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation; \ fi Error in compileCode(f, code, language = language, verbose = verbose) : In file included from :1:In file included from /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp:22:In file included from /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppEigen/include/Eigen/Dense:1:In file included from /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppEigen/include/Eigen/Core:19:/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal error: 'cmath' file not found 679 | #include | ^~~1 error generated.make: *** [file32a61d435bcf.o] Error 1 Error in sink(type = "output") : invalid connection"

I'm using a MacBook Pro with M1 chip, running on Sonoma 14.7.1

Best, Nico