Brm function only works the first time I use it

Hi there

This is very strange, but after running the brm() function for the first time (which works perfectly fine), in the code below

dat3 <- data.frame(y = c(rvon_mises(n = 100, mu = -pi/2, kappa = 10), rvon_mises(n = 50, mu = pi/4, kappa = 5)))
mix3 <- mixture(von_mises(), von_mises())
fit3 <- brm(bf(y ~ 1), dat3, family = mix3,
            chains = 2, inits = "random")
summary(fit3)

everything seems to get “frozen” with that function, in that I still can run other commands, but if I try to rerun brm() with different parameters, nothing happens:
R prints “Compiling Stan program…” and immediately (and apparently) finishes the computations without prompting any error message. But nothing has really happened, the variable fit3 in my code remains unchanged no matter what I try. I need to restart R to be able to run brm() again with different parameters, but that’s obviously a headache.

Any idea of what might be going wrong? I Maybe something related to the Stan compilation of the models?

Thanks in advance for any help

  • Operating System: Windows 10
  • brms Version: 2.13.5
1 Like

Hi, please provide a complete example we can run on our computers if possible. It will make it easier to pinpoint things :)

Hi Jcano,

The first step will be to test your RStan installation. Can you try running:

library(rstan)
example(stan_model,run.dontrun=TRUE,verbose=TRUE)

And post the line(s) in the output that start with error:?

1 Like

This is what I get

Error in file(con, "r") : argumento 'description' inválido
Además: Warning messages:
1: In find.package(package, lib.loc, verbose = verbose) :
  package ‘survival’ found more than once, using the first from
  “C:/Users/URJC/Documents/R/win-library/4.0/survival”,
  “C:/Program Files/R/R-4.0.2/library/survival”
2: In find.package(package, lib.loc, verbose = verbose) :
  package ‘MASS’ found more than once, using the first from
  “C:/Users/URJC/Documents/R/win-library/4.0/MASS”,
  “C:/Program Files/R/R-4.0.2/library/MASS”
3: In find.package(package, lib.loc, verbose = verbose) :
  package ‘base’ found more than once, using the first from
  “C:/PROGRA~1/R/R-40~1.2/library/base”,
  “C:/Program Files/R/R-4.0.2/library/base”

Hi, that’s the MWE. I if run it for the first time, everything is OK. If I change kappa from 10 to, say, 1000, and rerun brm() nothing happens, no error, just the message “Compiling Stan program…” but fit3 is not updated, brm() produces no new output.

1 Like

What versions of RStan and StanHeaders do you have? Also, which version of R are you on?

You can check this with:

packageVersion("rstan")
packageVersion("StanHeaders")
R.version.string

Another thing to check, what are the outputs from:

readLines("~/.R/Makevars.win")
readLines("~/.Renviron")
> packageVersion("rstan")
[1] ‘2.21.2’
> packageVersion("StanHeaders")
[1] ‘2.21.0.5’
> R.version.string
[1] "R version 4.0.2 (2020-06-22)"
> readLines("~/.R/Makevars.win")
[1] "CXX14FLAGS=-O3 -march=corei7 -mtune=corei7" "CXX14 = $(BINPREF)g++ -m$(WIN) -std=c++1y" 
[3] "CXX11FLAGS=-O3 -march=corei7 -mtune=corei7"
> readLines("~/.Renviron")
[1] "PATH=\"${RTOOLS40_HOME}\\usr\\bin;${PATH}\""

Great! Two things to change here, first your Makevars.win file has some configurations that will cause issues with R & RTools 4.0. So we’ll reset those to some basic options:

cat("CXX14FLAGS += -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2",file = "~/.R/Makevars.win", sep = "\n", append = FALSE)

Next, your StanHeaders package is out of date, so we’ll reinstall both RStan and StanHeaders to be safe:

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

Can you run those commands, restart R/RStudio and then try your brms model again?

1 Like

That worked!

But in one of the tries I ran (only in one, than it has never come out again), I got the following warning message

Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  'C:/rtools40/usr/mingw_/bin/g++' not found

Is it worrisome? How could I fix it? I have bad memories of having dealt with g++ in the past :-(

1 Like

Excellent! That warning is safe to ignore and won’t affect anything, it should be fixed in the next RStan release.

1 Like