Closed AruhoTinka closed 1 year ago
Hi, did you test if at least the documentation examples can run? e.g.
library(brms)
prior1 <- prior(normal(0,10), class = b) +
prior(cauchy(0,2), class = sd)
fit1 <- brm(count ~ zAge + zBase * Trt + (1|patient),
data = epilepsy, family = poisson(), prior = prior1)
If the above doesn't work, try setting options(brms.backend = "cmdstanr")
before attempting to fit the model.
As an aside, I suggest renaming your variables to remove dots and underscores beforehand, using those symbols in formulas can cause some issues.
Thank you, BMFazio, I tried the recommendations, but it still fails, with the following error: ################################################### install_cmdstan(cores = 2) The C++ toolchain required for CmdStan is setup properly!
library(brms) Loading required package: Rcpp Loading 'brms' package (version 2.19.0). Useful instructions can be found by typing help('brms'). A more detailed introduction to the package is available through vignette('brms_overview').
Attaching package: ‘brms’
The following object is masked from ‘package:stats’:
ar
Warning messages: 1: package ‘brms’ was built under R version 4.2.3 2: package ‘Rcpp’ was built under R version 4.2.3
prior1 <- prior(normal(0,10), class = b) +
- prior(cauchy(0,2), class = sd) fit1 <- brm(count ~ zAge + zBase * Trt + (1|patient),
- data = epilepsy, family = poisson(), prior = prior1) Compiling Stan program... make cmd is make -f "C:/PROGRA~1/R/R-42~1.0/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-42~1.0/share/make/winshlib.mk" CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB="file9c027762133.dll" WIN=64 TCLBIN= OBJECTS="file9c027762133.o"
make would use
if test "zfile9c027762133.o" != "z"; then \
if test -e "file9c027762133-win.def"; then \
echo g++ -shared -s -static-libgcc -o file9c027762133.dll file9c027762133-win.def file9c027762133.o -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-42~1.0/bin/x64" -lR ; \
g++ -shared -s -static-libgcc -o file9c027762133.dll file9c027762133-win.def file9c027762133.o -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-42~1.0/bin/x64" -lR ; \
else \
echo EXPORTS > tmp.def; \
nm file9c027762133.o | sed -n 's/^. [BCDRT] / /p' | sed -e '/[.]refptr[.]/d' -e '/[.]weak[.]/d' | sed 's/[^ ][^ ]/"&"/g' >> tmp.def; \
echo g++ -shared -s -static-libgcc -o file9c027762133.dll tmp.def file9c027762133.o -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-42~1.0/bin/x64" -lR ; \
g++ -shared -s -static-libgcc -o file9c027762133.dll tmp.def file9c027762133.o -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-42~1.0/bin/x64" -lR ; \
rm -f tmp.def; \
fi \
fi
Error in compileCode(f, code, language = language, verbose = verbose) :
C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file9c027762133.o:file9c027762133.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1d): undefined reference to tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file9c027762133.o:file9c027762133.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1d): undefined reference to
tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file9c027762133.o:file9c027762133.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x3a): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file9c027762133.o:file9c027762133.cpp:(.text$ZN3tbb10interface623task
Error in sink(type = "output") : invalid connection
#######################################################################
Thanks. Aruho
Hmm. It seems that CmdStan
did not install properly, so it won't run with the cmdstanr
backend, but that is a separate problem.
I have done some local testing and managed to reproduce your error message, so I am almost certain that your initial issue is being caused by rstan
. I assume you installed the CRAN version i.e. used install.packages("rstan")
. The issue is fixed in the latest development version, please follow this guide to obtain it (version 2.26) and continue with the rest of the steps to ensure that everything else is properly configured, including running the test models.
Dear BmFazio,
I installed the latest version, 2.26, after installing the newest version of R (4.3.1) and Rstudio. However, it brings the same error: failing to download the "cmdstan" and asking for a retry. I checked the location of the failed download and found it had partially downloaded with 36MB. I manually downloaded the "cmdstan-2.32.2.tar.gz" with 48.1MBs and replaced it with the partially downloaded one. But on retrying, it brings the same error as below. ############################################################################ library(cmdstanr) This is cmdstanr version 0.5.3
check_cmdstan_toolchain(fix = TRUE, quiet = TRUE) library(posterior) This is posterior version 1.4.1
Attaching package: ‘posterior’
The following objects are masked from ‘package:stats’:
mad, sd, var
The following objects are masked from ‘package:base’:
%in%, match
library(bayesplot) This is bayesplot version 1.10.0
- Online documentation and vignettes at mc-stan.org/bayesplot
- bayesplot theme set to bayesplot::theme_default()
- Does not affect other ggplot2 plots
- See ?bayesplot_theme_set for details on theme setting
Attaching package: ‘bayesplot’
The following object is masked from ‘package:posterior’:
rhat
color_scheme_set("brightblue") check_cmdstan_toolchain() The C++ toolchain required for CmdStan is setup properly! install_cmdstan(cores = 2) The C++ toolchain required for CmdStan is setup properly!
- Latest CmdStan release is v2.32.2
- Installing CmdStan v2.32.2 in C:/Users/User/OneDrive - University of Cape Town/Documents/.cmdstan/cmdstan-2.32.2
- Downloading cmdstan-2.32.2.tar.gz from GitHub... Error: Download of CmdStan failed. Please try again.
###################################################### Kindly advise
I thank you. Aruho
If you have installed rstan
2.26, then it should not be a problem to run the examples without installing cmdstanr
. You haven't mentioned if you also ran the test models in the link I sent or if you were still getting an error. Either way, I would expect the model you initially posted to work properly now that you updated rstan
.
If this hasn't resolved your issue, I suggest you post a followup on the Stan forums (https://discourse.mc-stan.org) as this is unlikely to be a problem with brms
itself.
Dear BMFazio, Yes, I ran it initially, it didnt give anything tangible. But this time it posted a file of "2 obs of 10 variables" on the global environment. I reloaded Rtools with the recent one - Rtools43, and reloaded rstan and here below are the results it gave me. I am I good to go, with this output? I see there are still some errors. kindly advise. ###################
install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE) WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding: https://cran.rstudio.com/bin/windows/Rtools/ Installing package into ‘C:/Users/User/AppData/Local/R/win-library/4.3’ (as ‘lib’ is unspecified) also installing the dependencies ‘RUnit’, ‘rstudioapi’ There is a binary version available but the source version is later: binary source needs_compilation rstudioapi 0.14 0.15.0 FALSE trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.3/RUnit_0.4.32.zip' Content type 'application/zip' length 296748 bytes (289 KB) downloaded 289 KB trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.3/rstan_2.21.8.zip' Content type 'application/zip' length 3352800 bytes (3.2 MB) downloaded 3.2 MB package ‘RUnit’ successfully unpacked and MD5 sums checked package ‘rstan’ successfully unpacked and MD5 sums checked The downloaded binary packages are in C:\Users\User\AppData\Local\Temp\RtmpMbFSFl\downloaded_packages installing the source package ‘rstudioapi’ trying URL 'https://cloud.r-project.org/src/contrib/rstudioapi_0.15.0.tar.gz' Content type 'application/x-gzip' length 115689 bytes (112 KB) downloaded 112 KB * installing *source* package 'rstudioapi' ... ** package 'rstudioapi' successfully unpacked and MD5 sums checked ** using staged installation ** R ** inst ** byte-compile and prepare package for lazy loading ** help *** installing help indices *** copying figures ** building package indices ** installing vignettes ** testing if installed package can be loaded from temporary location ** testing if installed package can be loaded from final location ** testing if installed package keeps a record of temporary installation path * DONE (rstudioapi) The downloaded source packages are in ‘C:\Users\User\AppData\Local\Temp\RtmpMbFSFl\downloaded_packages’ > example(stan_model, package = "rstan", run.dontrun = TRUE) Loading required package: StanHeaders Loading required package: ggplot2 rstan (Version 2.21.8, GitRev: 2e1f913d3ca3) For execution on a local, multicore CPU with excess RAM we recommend calling options(mc.cores = parallel::detectCores()). To avoid recompilation of unchanged Stan programs, we recommend calling rstan_options(auto_write = TRUE) Do not specify '-march=native' in 'LOCAL_CPPFLAGS' or a Makevars file stn_md> stancode <- 'data {real y_mean;} parameters {real y;} model {y ~ normal(y_mean,1);}' stn_md> mod <- stan_model(model_code = stancode, verbose = TRUE) TRANSLATING MODEL '73fc79f8b1915e8208c736914c86d1a1' FROM Stan CODE TO C++ CODE NOW. successful in parsing the Stan model '73fc79f8b1915e8208c736914c86d1a1'. COMPILING THE C++ CODE FOR MODEL '73fc79f8b1915e8208c736914c86d1a1' NOW. OS: x86_64, mingw32; rstan: 2.21.8; Rcpp: 1.0.10; inline: 0.3.19 trying URL 'https://cran.rstudio.com/bin/windows/Rtools/rtools43/files/rtools43-5550-5548.exe' Content type 'application/x-msdownload' length 487427824 bytes (464.8 MB) downloaded 464.8 MB trying URL 'https://cran.rstudio.com/bin/windows/Rtools/rtools43/files/rtools43-5550-5548.exe' Content type 'application/x-msdownload' length 487427824 bytes (464.8 MB) downloaded 464.8 MB >> setting environment variables: LOCAL_LIBS = "C:/Users/User/AppData/Local/R/win-library/4.3/rstan/lib/x64/libStanServices.a" -L"C:/Users/User/AppData/Local/R/win-library/4.3/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/User/AppData/Local/R/win-library/4.3/RcppParallel/lib/x64" -ltbb PKG_CPPFLAGS = -I"C:/Users/User/AppData/Local/R/win-library/4.3/Rcpp/include/" -I"C:/Users/User/AppData/Local/R/win-library/4.3/RcppEigen/include/" -I"C:/Users/User/AppData/Local/R/win-library/4.3/RcppEigen/include/unsupported" -I"C:/Users/User/AppData/Local/R/win-library/4.3/BH/include" -I"C:/Users/User/AppData/Local/R/win-library/4.3/StanHeaders/include/src/" -I"C:/Users/User/AppData/Local/R/win-library/4.3/StanHeaders/include/" -I"C:/Users/User/AppData/Local/R/win-library/4.3/RcppParallel/include/" -I"C:/Users/User/AppData/Local/R/win-library/4.3/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include "C:/Users/User/AppData/Local/R/win-library/4.3/StanHeaders/include/stan/math/prim/fun/Eigen.hpp" -std=c++1y >> Program source : 1 : 2 : // includes from the plugin 3 : // [[Rcpp::plugins(cpp14)]] 4 : 5 : 6 : // user includes 7 : #include############################
Aruho
This thread looks to me like it belongs onto the Stan forums and not the brms issue tracker.
Dear GitHub community, I am a beginner with BRMS and I can't understand this error below, and how to rectify it, I need help (my R code that resulted in the error after compilation is also here below.
#######R-code########
practice with brms
date: 07 july 2023
library(ProbBayes) library(brms) library(dplyr) library(ggplot2)
import own data
practc <- read.csv("D:/DESKTOP/UCT 2023/R-Final/Imputedpaxdata_CatData.csv")
setwd("D:/DESKTOP/UCT 2023/R-Final")
non-informative priors
fit_CFC_pref <- brm(CFCPref.~ Age + Gender + Education + Netindv..Inc. + Days.wk + daily_taxifares
Error in compileCode(f, code, language = language, verbose = verbose) : C:/rtools40/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: file1a304d8c7d.o:file1a304d8c7d.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1d): undefined reference to
tbb::internal::task_scheduler_observer_v3::observe(bool)'C:/rtools40/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: file1a304d8c7d.o:file1a304d8c7d.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1d): undefined reference to
tbb::internal::task_scheduler_observer_v3::observe(bool)'C:/rtools40/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: file1a304d8c7d.o:file1a304d8c7d.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x3a): undefined reference to `tbb::internal::task_scheduler_observer_v3::observ Error in sink(type = "output") : invalid connection ################Thank you
Aruho