Problem with getting STAN to work on Mac

I am getting a warning when trying to run stan on my MAC:

Here is the warning:

DIAGNOSTIC(S) FROM PARSER:
Info (non-fatal):
Left-hand side of sampling statement (~) may contain a non-linear transform of a parameter or local variable.
If it does, you need to include a target += statement with the log absolute determinant of the Jacobian of the transform.
Left-hand-side of sampling statement:
etaUNC ~ sem_lv_lpdf(…)

Compiling stan model…DIAGNOSTIC(S) FROM PARSER:
Info (non-fatal):
Left-hand side of sampling statement (~) may contain a non-linear transform of a parameter or local variable.
If it does, you need to include a target += statement with the log absolute determinant of the Jacobian of the transform.
Left-hand-side of sampling statement:
etaUNC ~ sem_lv_lpdf(…)

Error in if (nchar(CXX) == 0) { : argument is of length zero
In addition: Warning message:
In system2(file.path(R.home(component = “bin”), “R”), args = paste(“CMD config”, :
running command ‘’/Library/Frameworks/R.framework/Resources/bin/R’ CMD config CXX14 2>/dev/null’ had status 1
Error in blavaan(mod51, data = dat, std.lv = T, n.chains = 3, burnin = 10000, :
blavaan ERROR: problem with MCMC estimation. The model syntax and data have been exported.

Here is the Session Info:

R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] runjags_2.0.4-2 rstan_2.18.2 StanHeaders_2.18.1 ggplot2_3.1.1 blavaan_0.3-4 lavaan_0.6-3

loaded via a namespace (and not attached):
[1] zoo_1.8-6 tidyselect_0.2.5 purrr_0.3.2 lattice_0.20-38 colorspace_1.4-1 stats4_3.6.0
[7] loo_2.1.0 MCMCpack_1.4-4 rlang_0.3.4 pkgbuild_1.0.3 pillar_1.4.1 glue_1.3.1
[13] withr_2.1.2 matrixStats_0.54.0 plyr_1.8.4 MatrixModels_0.4-1 munsell_0.5.0 gtable_0.3.0
[19] mvtnorm_1.0-10 coda_0.19-2 nonnest2_0.5-2 inline_0.3.15 callr_3.2.0 SparseM_1.77
[25] ps_1.3.0 quantreg_5.40 parallel_3.6.0 Rcpp_1.0.1 scales_1.0.0 gridExtra_2.3
[31] mcmc_0.9-6 mnormt_1.5-5 processx_3.3.1 dplyr_0.8.1 CompQuadForm_1.4.3 grid_3.6.0
[37] cli_1.1.0 tools_3.6.0 sandwich_2.5-1 magrittr_1.5 lazyeval_0.2.2 tibble_2.1.3
[43] crayon_1.3.4 pbivnorm_0.6.0 pkgconfig_2.0.2 MASS_7.3-51.4 Matrix_1.2-17 prettyunits_1.0.2
[49] assertthat_0.2.1 rstudioapi_0.10 R6_2.4.0 compiler_3.6.0

Thanks for any help in advance,

Matt

This looks like a problem with something called “blavaan.” Can you try running the model without the intermediary?

It is a problem with blavaan. I ran a simple model and it still isn’t working. Here it is:

library(rstan)
scode ← "

  • parameters {
  • real y[2];
  • }
  • model {
  • y[1] ~ normal(0, 1);
  • y[2] ~ double_exponential(0, 2);
  • }
  • "

fit1 ← stan(model_code = scode, iter = 10, verbose = FALSE)

Error in if (nchar(CXX) == 0) { : argument is of length zero
In addition: Warning message:
In system2(file.path(R.home(component = “bin”), “R”), args = paste(“CMD config”, :
running command ‘’/Library/Frameworks/R.framework/Resources/bin/R’ CMD config CXX14 2>/dev/null’ had status 1

Thanks for your help in advance,

Matt

Have you recently updated your R, your macOS , or first time running Stan on this Machine. If not, ignore everything below and good luck getting someone who knows more than me (ie most people).

This looks like a problem with C++ / fortran etc. I am no sort of expert at all on Stan or computers in general but I received errors like that at one point recently after getting a new computer and reinstalling things that needed compiling. The new OS distributions lack the Xcode and other necessary things they once had.

My lack of expertise made it take a whole night (because my problem was never EXACTLY what the instructions directed… when is it ever) but I eventually fixed it. If no one else has better advice before tomorrow I’ll respond with details.

I updated my OSX software to Mojave, installed Xcode, and then rstan still didn’t work. Got this message:

Error in sink(type = “output”) : invalid connection
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file28112159360.cpp 2> file28112159360.cpp.err.txt’ had status 1
Error in blavaan(mod51, data = dat, std.lv = T, n.chains = 3, burnin = 10000, :
blavaan ERROR: problem with MCMC estimation. The model syntax and data have been exported.

I then tried to uninstall and reinstall rstan as well as restart my computer but I am still getting the same message.

Any help is much appreciated.

Matt

This part makes me think that this is the Rccp install problem.
My understanding is the different versions of R have different clang versions and fortran versions.

You can look in your usr files to see if you have them (this repo, macOS r tools has a package that will try to detect and download the correct files directly from the places they are held.

This is all complicated by things I don’t fully understand, for instance, The most current version of gfortran for Mojave is 8.2. However this is not the version R needs which is 6.1

R 3.6 needs clang7.

The issues page on the repo above has details about the versions. If you look in your /usr/local/ you should see if you have the right version of clang installed. I think the pkg I linked will install the correct version of fortran.

I did some sort of hack job putting it all together and fixing my problems but I did eventually succeed (I had this problem unrelated to Stan, it was a problem that also affected installing any r packages that weren’t already compiled.).

There is another long thread here that addresses various Mac problems.

Unless someone comes here and tells you I am an imbecile and this isn’t related to the stuff I’ve been talking about–

FIRST I would check out that last post and see if I have all the files and versions installed (command line tools, Xcode, clang, fortran). IF they are all there and correct the makevars file might need to be fixed, and if not then I am wrong about everything.

I hope that helps at ALL!

Thanks! I eventually got it to work and it was related to Rccp, clang, fortran and thier interaction with Mojave.

Here are the steps I took to fix it if anyone has a similar problem:

(1) Update Mojave to the latest update
(2) Install Xcode
(3) Follow the instructions on the following website:

https://thecoatlessprofessor.com/programming/r-compiler-tools-for-rcpp-on-macos/

Thanks for everyone’s help!

1 Like