Mac installation problems

Apologies if this is not the right place to post but new to forum and stan. I have tried to install stan and run the vignettes but encounter the following warnings when I try to fit the model (which is in the working directory as 8schools.stan and schools.stan, the two versions which are provided):

fit <- stan(file = ‘8schools.stan’, data = schools_dat, iter = 1000, chains = 4)
PARSER EXPECTED: whitespace to end of file.
FOUND AT line 1:
{\rtf1\ansi\ansicpg1252\cocoartf1504\cocoasubrtf830
{\fonttbl\f0\fmodern\fcharset0 Courier;}
{\colortbl;\red255\green255\blue255;\red0\green0\blue0;}
{*\expandedcolortbl;;\cssrgb\c0\c0\c0;}
\paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\deftab720
\pard\pardeftab720\sl280\partightenfactor0

\f0\fs24 \cf2 \expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec2 // saved as 8schools.stan
data {
int<lower=0> J; // number of schools
real y[J]; // estimated treatment effects
real<lower=0> sigma[J]; // s.e. of effect estimates
}
parameters {
real mu;
real<lower=0> tau;
real eta[J];
}
transformed parameters {
real theta[J];
for (j in 1:J)
theta[j] = mu + tau * eta[j];
}
model {
target += normal_lpdf(eta | 0, 1);
target += normal_lpdf(y | theta, sigma);
}
}

Error in stanc(file = file, model_code = model_code, model_name = model_name, :
failed to parse Stan model ‘8schools’ due to the above error.
In addition: Warning message:
In readLines(file, warn = TRUE) :
incomplete final line found on ‘/Users/djamesw/Rprojects/8schools.stan’


sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

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.4/Resources/lib/libRlapack.dylib

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

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

other attached packages:
[1] rstan_2.16.2 StanHeaders_2.16.0-1 ggplot2_2.2.1

loaded via a namespace (and not attached):
[1] Rcpp_0.12.12 withr_2.0.0 digest_0.6.12 grid_3.4.1
[5] plyr_1.8.4 gtable_0.2.0 stats4_3.4.1 scales_0.4.1
[9] rlang_0.1.1 lazyeval_0.2.0 devtools_1.13.3 tools_3.4.1
[13] munsell_0.4.3 parallel_3.4.1 compiler_3.4.1 inline_0.3.14
[17] colorspace_1.3-2 memoise_1.1.0 gridExtra_2.2.1 tibble_1.3.3


writeLines(readLines(file.path(Sys.getenv(“HOME”), “.R/Makevars”)))

CXXFLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function


devtools::session_info(“rstan”)
Session info -----------------------------------------------------------------------
setting value
version R version 3.4.1 (2017-06-30)
system x86_64, darwin15.6.0
ui RStudio (1.0.153)
language (EN)
collate en_AU.UTF-8
tz Australia/Brisbane
date 2017-08-06

Packages ---------------------------------------------------------------------------
package * version date source
BH 1.62.0-1 2016-11-19 CRAN (R 3.4.0)
colorspace 1.3-2 2016-12-14 CRAN (R 3.4.0)
dichromat 2.0-0 2013-01-24 CRAN (R 3.4.0)
digest 0.6.12 2017-01-27 CRAN (R 3.4.0)
ggplot2 * 2.2.1 2016-12-30 CRAN (R 3.4.0)
graphics * 3.4.1 2017-07-07 local
grDevices * 3.4.1 2017-07-07 local
grid 3.4.1 2017-07-07 local
gridExtra 2.2.1 2016-02-29 CRAN (R 3.4.0)
gtable 0.2.0 2016-02-26 CRAN (R 3.4.0)
inline 0.3.14 2015-04-13 CRAN (R 3.4.0)
labeling 0.3 2014-08-23 CRAN (R 3.4.0)
lattice 0.20-35 2017-03-25 CRAN (R 3.4.1)
lazyeval 0.2.0 2016-06-12 CRAN (R 3.4.0)
magrittr 1.5 2014-11-22 CRAN (R 3.4.0)
MASS 7.3-47 2017-02-26 CRAN (R 3.4.1)
Matrix 1.2-10 2017-05-03 CRAN (R 3.4.1)
methods * 3.4.1 2017-07-07 local
munsell 0.4.3 2016-02-13 CRAN (R 3.4.0)
plyr 1.8.4 2016-06-08 CRAN (R 3.4.0)
RColorBrewer 1.1-2 2014-12-07 CRAN (R 3.4.0)
Rcpp 0.12.12 2017-07-15 CRAN (R 3.4.1)
RcppEigen 0.3.3.3.0 2017-05-01 CRAN (R 3.4.0)
reshape2 1.4.2 2016-10-22 CRAN (R 3.4.0)
rlang 0.1.1 2017-05-18 CRAN (R 3.4.0)
rstan * 2.16.2 2017-07-03 CRAN (R 3.4.1)
scales 0.4.1 2016-11-09 CRAN (R 3.4.0)
StanHeaders * 2.16.0-1 2017-07-03 CRAN (R 3.4.1)
stats * 3.4.1 2017-07-07 local
stats4 3.4.1 2017-07-07 local
stringi 1.1.5 2017-04-07 CRAN (R 3.4.0)
stringr 1.2.0 2017-02-18 CRAN (R 3.4.0)
tibble 1.3.3 2017-05-28 CRAN (R 3.4.0)
tools 3.4.1 2017-07-07 local
utils * 3.4.1 2017-07-07 local


Mac OS Sierra version 10.12.6


I am aware that there may be problems with the latest version of R (according to a post by Bob Carpenter) but I don’t know if my problem is the same.

I would be grateful for any suggestions.

Have you opened the files with textedit and saved them as rtf (rich text format)?

Try this in terminal

less filename.stan # press q to quit

Thanks for that suggestion. Initially when I was saving the stan file the rtf extension would be added but I noticed that and removed the rtf as you can see below. I ran the code you suggested which produced the additional output. I’m not sure if that provides any further clues.


8schools.stan rstan from source warning.rtf
Blog post.rtf rstan_setup.R
R_Library_location.rtf schools.stan


Duncans-MBP:Rprojects djamesw$ less schools.stan

{\rtf1\ansi\ansicpg1252\cocoartf1504\cocoasubrtf830
{\fonttbl\f0\fnil\fcharset0 Monaco;}
{\colortbl;\red255\green255\blue255;\red38\green38\blue38;\red245\green245\blue2
45;}
{*\expandedcolortbl;;\cssrgb\c20000\c20000\c20000;\cssrgb\c96863\c96863\c96863;
}
\paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\deftab720
\pard\pardeftab720\partightenfactor0

\f0\fs23\fsmilli11900 \cf2 \cb3 \expnd0\expndtw0\kerning0
data {
int<lower=0> J; // number of schools
real y[J]; // estimated treatment effects
real<lower=0> sigma[J]; // s.e. of effect estimates
}
parameters {
real mu;
real<lower=0> tau;
vector[J] eta;
}
transformed parameters {
vector[J] theta;
:

The process of installing stan has been daunting as I’m not a programmer and I’m not that familiar with the Terminal, C compilers etc. I could never get stan to run on Windows7 so when my PC failed last week I rushed out to buy a Mac as it seemed a lot of stan users preferred them.

I noticed that Xcode, clang and fortran are required. I installed clang37 as suggested (which seemed to work) but then noticed that I may already have had clang40. I’m not sure if I have actually downgraded my version. The output from the installation (through homebrew):


Duncans-MBP:bin djamesw$ brew tap homebrew/versions
Updating Homebrew…
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
pumba
==> Updated Formulae
angular-cli gsmartcontrol oniguruma
ansifilter heroku percona-server
axel imagemagick percona-server-mongodb
bash-snippets imagemagick@6 percona-server@5.5
brew-gem influxdb percona-server@5.6
btfs knot-resolver percona-toolkit
buku kubernetes-cli percona-xtrabackup
certbot libmwaw pre-commit
clojurescript libphonenumber pyinvoke
dep libwps qrupdate
depqbf libxkbcommon rtv
docutils minio scalapack
eg mongo-orchestration sqlmap
etcd msgpack syntaxerl
firebase-cli node-build thefuck
git node@6 veclibfort
gitlab-ci-multi-runner nodeenv wabt
gofabric8 octave yaz

Warning: homebrew/versions was deprecated. This tap is now empty as all its formulae were migrated.
==> Tapping homebrew/versions
Cloning into ‘/usr/local/Homebrew/Library/Taps/homebrew/homebrew-versions’…
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 9 (delta 0), reused 5 (delta 0), pack-reused 0
Unpacking objects: 100% (9/9), done.
Tapped 0 formulae (37 files, 31.4KB)
Duncans-MBP:bin djamesw$ brew install llvm37
==> Installing dependencies for llvm@3.7: gmp, libffi
==> Installing llvm@3.7 dependency: gmp
==> Downloading https://homebrew.bintray.com/bottles/gmp-6.1.2.sierra.bottle.1.t
######################################################################## 100.0%
==> Pouring gmp-6.1.2.sierra.bottle.1.tar.gz
==> Using the sandbox
🍺 /usr/local/Cellar/gmp/6.1.2: 18 files, 3.1MB
==> Installing llvm@3.7 dependency: libffi
==> Downloading https://homebrew.bintray.com/bottles/libffi-3.2.1.sierra.bottle.
######################################################################## 100.0%
==> Pouring libffi-3.2.1.sierra.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because some formulae require a newer version of libffi.

For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/libffi/lib

==> Summary
🍺 /usr/local/Cellar/libffi/3.2.1: 16 files, 297.0KB
==> Installing llvm@3.7
==> Downloading https://homebrew.bintray.com/bottles/llvm@3.7-3.7.1.sierra.bottl
######################################################################## 100.0%
==> Pouring llvm@3.7-3.7.1.sierra.bottle.1.tar.gz
==> Caveats
Extra tools are installed in /usr/local/opt/llvm@3.7/share/clang-3.7

To link to libc++, something like the following is required:
CXX=“clang+±3.7 -stdlib=libc++“
CXXFLAGS=”$CXXFLAGS -nostdinc++ -I/usr/local/opt/llvm@3.7/lib/llvm-3.7/include/c++/v1"
LDFLAGS=”$LDFLAGS -L/usr/local/opt/llvm@3.7/lib/llvm-3.7/lib"

Python modules have been installed and Homebrew’s site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
mkdir -p /Users/djamesw/.local/lib/python3.6/site-packages
echo ‘import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")’ >> /Users/djamesw/.local/lib/python3.6/site-packages/homebrew.pth
==> Summary
🍺 /usr/local/Cellar/llvm@3.7/3.7.1: 1,700 files, 274.9MB
Duncans-MBP:bin djamesw$ ls
FileCheck-3.7 llvm-dsymutil-3.7
R llvm-dwarfdump-3.7
Rscript llvm-extract-3.7
brew llvm-link-3.7
bugpoint-3.7 llvm-mc-3.7
c-index-test-3.7 llvm-mcmarkup-3.7
clang+±3.7 llvm-nm-3.7
clang-3.7 llvm-objdump-3.7
clang-apply-replacements-3.7 llvm-pdbdump-3.7
clang-check-3.7 llvm-profdata-3.7
clang-format-3.7 llvm-ranlib-3.7
clang-modernize-3.7 llvm-readobj-3.7
clang-query-3.7 llvm-rtdyld-3.7
clang-rename-3.7 llvm-size-3.7
clang-tblgen-3.7 llvm-stress-3.7
clang-tidy-3.7 llvm-symbolizer-3.7
count-3.7 llvm-tblgen-3.7
jags macho-dump-3.7
llc-3.7 not-3.7
lli-3.7 obj2yaml-3.7
lli-child-target-3.7 opt-3.7
llvm-ar-3.7 pandoc
llvm-as-3.7 pandoc-citeproc
llvm-bcanalyzer-3.7 pp-trace-3.7
llvm-config-3.7 scan-build-3.7
llvm-cov-3.7 scan-view-3.7
llvm-cxxdump-3.7 verify-uselistorder-3.7
llvm-diff-3.7 yaml2obj-3.7
llvm-dis-3.7


A few warnings/instructions were produced which I have not acted on (yet):

For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/libffi/lib

To link to libc++, something like the following is required:
CXX=“clang+±3.7 -stdlib=libc++“
CXXFLAGS=”$CXXFLAGS -nostdinc++ -I/usr/local/opt/llvm@3.7/lib/llvm-3.7/include/c++/v1"
LDFLAGS=”$LDFLAGS -L/usr/local/opt/llvm@3.7/lib/llvm-3.7/lib"

Python modules have been installed and Homebrew’s site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
mkdir -p /Users/djamesw/.local/lib/python3.6/site-packages
echo ‘import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")’ >> /Users/djamesw/.local/lib/python3.6/site-packages/homebrew.pth


I downloaded gfortran-4.2.3 and gfortran-6.3-Sierra but am not sure which, if either, to install. I have already installed XQuartz-2.7.11 but I’m unsure whether that was necessary. It would be useful to have some test code which identified what was missing/required. I should say that the R test code worked fine (ie I got 10):

fx <- inline::cxxfunction( signature(x = “integer”, y = “numeric” ) , ’

return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;

’ )

fx( 2L, 5 ) # should be 10

My concern is that every step seems to lead to another which takes me deeper into murky territory from which I may not be able to return.

Thanks once again.

Your Stan program needs to be pure ASCII. This should work

fit <- stan(file = ‘https://raw.githubusercontent.com/stan-dev/example-models/master/misc/eight_schools/eight_schools.stan’, 
            data = schools_dat, iter = 1000, chains = 4)

Many thanks

Attempt 1

Output from your suggestion:

fit ← stan(file = ‘https://raw.githubusercontent.com/stan-dev/example-models/master/misc/eight_schools/eight_schools.stan’, data = schools_dat, iter = 1000, chains = 4)
Error: unexpected input in “fit ← stan(file = �”


Attempt 2

So I then copied from that file and put it into eight_schools.stan in my working directory (ensuring I first removed the rtf extension which Textedit automatically includes):

> fit <- stan(file = 'eight_schools.stan', data = schools_dat, iter = 1000, chains = 4)
PARSER EXPECTED: whitespace to end of file.
FOUND AT line 1: 
{\rtf1\ansi\ansicpg1252\cocoartf1504\cocoasubrtf830
{\fonttbl\f0\fmodern\fcharset0 Courier;}
{\colortbl;\red255\green255\blue255;\red0\green0\blue0;}
{\*\expandedcolortbl;;\cssrgb\c0\c0\c0;}
\paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\deftab720
\pard\pardeftab720\sl280\partightenfactor0

\f0\fs24 \cf2 \expnd0\expndtw0\kerning0
data \{\
  int<lower=0> J;          // number of schools\
  real y[J];               // estimated treatment effect (school j)\
  real<lower=0> sigma[J];  // std err of effect estimate (school j)\
\}\
parameters \{\
  real mu;\
  real theta[J];\
  real<lower=0> tau;\
\}\
model \{\
  theta ~ normal(mu, tau); \
  y ~ normal(theta,sigma);\
\}\
}


Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  failed to parse Stan model 'eight_schools' due to the above error.
In addition: Warning message:
In readLines(file, warn = TRUE) :
  incomplete final line found on '/Users/djamesw/Rprojects/eight_schools.stan'

Attempt 3

So I then looked for an alternative raw file in the Github repo:

> fit <- stan(file = 'https://raw.githubusercontent.com/stan-dev/example-models/master/ARM/Ch.19/schools.stan', data = schools_dat, iter = 1000, chains = 4)
DIAGNOSTIC(S) FROM PARSER:
Warning (non-fatal): assignment operator <- deprecated in the Stan language; use = instead.
Warning (non-fatal): assignment operator <- deprecated in the Stan language; use = instead.

In file included from file109545552dc.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:12:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/core/gevv_vvv_vari.hpp:5:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/core/var.hpp:7:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include/boost/math/tools/config.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include/boost/config.hpp:39:
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include/boost/config/compiler/clang.hpp:196:11: warning: 'BOOST_NO_CXX11_RVALUE_REFERENCES' macro redefined [-Wmacro-redefined]
#define BOOST_NO_CXX11_RVALUE_REFERENCES
          ^
<command line>:6:9: note: previous definition is here
#define BOOST_NO_CXX11_RVALUE_REFERENCES 1
        ^
1 warning generated.
Error in new_CppObject_xp(fields$.module, fields$.pointer, ...) : 
  variable does not exist; processing stage=data initialization; variable name=N; base type=int
In addition: Warning messages:
1: In normalizePath(file) :
  path[1]="https://raw.githubusercontent.com/stan-dev/example-models/master/ARM/Ch.19/schools.stan": No such file or directory
2: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
3: In FUN(X[[i]], ...) : data with name N is not numeric and not used
4: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
5: In FUN(X[[i]], ...) :
  data with name sigma_y is not numeric and not used
trying deprecated constructor; please alert package maintainer
Error in new_CppObject_xp(fields$.module, fields$.pointer, ...) : 
  no valid constructor available for the argument list
failed to create the sampler; sampling not done

I note that that file has ← in the stan code which I presume is not acceptable:

transformed parameters {
  real<lower=0> sigma_theta;
  vector[N] theta;

  theta <- mu_theta + xi * eta;
  sigma_theta <- fabs(xi) / sigma_eta;

Nevertheless there are a lot of other warnings which make me wonder if there is something more fundamental wrong.


Installing rstan from source

When I did this (prior to running all of the code etc) I got a lot of warnings and messages (see below). Could this have something to do with it?

clang++  -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I"../inst/include" -I"../inst/include/boost_not_in_BH" -I"`"/Library/Frameworks/R.framework/Resources/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DFUSION_MAX_VECTOR_SIZE=12 -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/RcppEigen/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c misc.cpp -o misc.o
clang++  -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I"../inst/include" -I"../inst/include/boost_not_in_BH" -I"`"/Library/Frameworks/R.framework/Resources/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DFUSION_MAX_VECTOR_SIZE=12 -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/RcppEigen/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c sparse_extractors.cpp -o sparse_extractors.o
clang++  -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I"../inst/include" -I"../inst/include/boost_not_in_BH" -I"`"/Library/Frameworks/R.framework/Resources/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DFUSION_MAX_VECTOR_SIZE=12 -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/RcppEigen/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c stanc.cpp -o stanc.o
In file included from stanc.cpp:22:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/src/stan/lang/compiler.hpp:5:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/src/stan/lang/ast.hpp:68:
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/src/stan/lang/ast/node/conditional_op.hpp:40:21: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
      bool has_var_ = false;
                    ^
1 warning generated.
clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o rstan.so chains.o init.o lang__ast_def.o lang__grammars__bare_type_grammar_inst.o lang__grammars__expression07_grammar_inst.o lang__grammars__expression_grammar_inst.o lang__grammars__functions_grammar_inst.o lang__grammars__indexes_grammar_inst.o lang__grammars__program_grammar_inst.o lang__grammars__semantic_actions.o lang__grammars__statement_2_grammar_inst.o lang__grammars__statement_grammar_inst.o lang__grammars__term_grammar_inst.o lang__grammars__var_deccls_grammar_inst.o lang__grammars__whitespace_grammar_inst.o misc.o sparse_extractors.o stanc.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rstan/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (rstan)

The downloaded source packages are in
	‘/private/var/folders/ks/x4lpc3qx7jj2h0vxd3ppqrsw0000gn/T/Rtmpa4XFu2/downloaded_packages’

Once again, thanks for your help

Attempt 1 would work I think if plain ASCII quotes are used on both sides of the URL. Maybe this:

fit <- stan(file = "https://raw.githubusercontent.com/stan-dev/example-models/master/misc/eight_schools/eight_schools.stan", 
            data = schools_dat, iter = 1000, chains = 4)

Attempt 2 still has all the rich text formatting stuff added to it like {\colortbl.... That won’t work in a Stan program.

Attempt 3 is schools.stan not eight_schools.stan and it defines a different model, namely one that involves the integer N.

Using <- rather than = is frowned upon, but the example models still use it. That isn’t the problem and neither are the compiler warnings.


Thanks again

That might be it! Can’t believe it is that simple though. Here is the output:

> fit <- stan(file = "https://raw.githubusercontent.com/stan-dev/example-models/master/misc/eight_schools/eight_schools.stan",
+ data = schools_dat, iter = 1000, chains = 4)
In file included from file10953e894277.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:12:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/core/gevv_vvv_vari.hpp:5:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/core/var.hpp:7:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include/boost/math/tools/config.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include/boost/config.hpp:39:
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include/boost/config/compiler/clang.hpp:196:11: warning: 'BOOST_NO_CXX11_RVALUE_REFERENCES' macro redefined [-Wmacro-redefined]
#  define BOOST_NO_CXX11_RVALUE_REFERENCES
          ^
<command line>:6:9: note: previous definition is here
#define BOOST_NO_CXX11_RVALUE_REFERENCES 1
        ^
1 warning generated.
starting worker pid=4431 on localhost:11545 at 15:40:48.595
starting worker pid=4439 on localhost:11545 at 15:40:48.763
starting worker pid=4447 on localhost:11545 at 15:40:48.929
starting worker pid=4455 on localhost:11545 at 15:40:49.101

SAMPLING FOR MODEL 'eight_schools' NOW (CHAIN 1).

Gradient evaluation took 1e-05 seconds
1000 transitions using 10 leapfrog steps per transition would take 0.1 seconds.
Adjust your expectations accordingly!


Iteration:   1 / 1000 [  0%]  (Warmup)
Iteration: 100 / 1000 [ 10%]  (Warmup)
Iteration: 200 / 1000 [ 20%]  (Warmup)
Iteration: 300 / 1000 [ 30%]  (Warmup)
Iteration: 400 / 1000 [ 40%]  (Warmup)
Iteration: 500 / 1000 [ 50%]  (Warmup)
Iteration: 501 / 1000 [ 50%]  (Sampling)
Iteration: 600 / 1000 [ 60%]  (Sampling)
Iteration: 700 / 1000 [ 70%]  (Sampling)
Iteration: 800 / 1000 [ 80%]  (Sampling)
Iteration: 900 / 1000 [ 90%]  (Sampling)
Iteration: 1000 / 1000 [100%]  (Sampling)

 Elapsed Time: 0.05585 seconds (Warm-up)
               0.024836 seconds (Sampling)
               0.080686 seconds (Total)


SAMPLING FOR MODEL 'eight_schools' NOW (CHAIN 2).

Gradient evaluation took 1.1e-05 seconds
1000 transitions using 10 leapfrog steps per transition would take 0.11 seconds.
Adjust your expectations accordingly!


Iteration:   1 / 1000 [  0%]  (Warmup)
Iteration: 100 / 1000 [ 10%]  (Warmup)
Iteration: 200 / 1000 [ 20%]  (Warmup)
Iteration: 300 / 1000 [ 30%]  (Warmup)
Iteration: 400 / 1000 [ 40%]  (Warmup)
Iteration: 500 / 1000 [ 50%]  (Warmup)
Iteration: 501 / 1000 [ 50%]  (Sampling)
Iteration: 600 / 1000 [ 60%]  (Sampling)
Iteration: 700 / 1000 [ 70%]  (Sampling)
Iteration: 800 / 1000 [ 80%]  (Sampling)
Iteration: 900 / 1000 [ 90%]  (Sampling)
Iteration: 1000 / 1000 [100%]  (Sampling)

 Elapsed Time: 0.057615 seconds (Warm-up)
               0.018443 seconds (Sampling)
               0.076058 seconds (Total)


SAMPLING FOR MODEL 'eight_schools' NOW (CHAIN 3).

Gradient evaluation took 1e-05 seconds
1000 transitions using 10 leapfrog steps per transition would take 0.1 seconds.
Adjust your expectations accordingly!


Iteration:   1 / 1000 [  0%]  (Warmup)
Iteration: 100 / 1000 [ 10%]  (Warmup)
Iteration: 200 / 1000 [ 20%]  (Warmup)
Iteration: 300 / 1000 [ 30%]  (Warmup)
Iteration: 400 / 1000 [ 40%]  (Warmup)
Iteration: 500 / 1000 [ 50%]  (Warmup)
Iteration: 501 / 1000 [ 50%]  (Sampling)
Iteration: 600 / 1000 [ 60%]  (Sampling)
Iteration: 700 / 1000 [ 70%]  (Sampling)
Iteration: 800 / 1000 [ 80%]  (Sampling)
Iteration: 900 / 1000 [ 90%]  (Sampling)
Iteration: 1000 / 1000 [100%]  (Sampling)

 Elapsed Time: 0.054985 seconds (Warm-up)
               0.033888 seconds (Sampling)
               0.088873 seconds (Total)


SAMPLING FOR MODEL 'eight_schools' NOW (CHAIN 4).

Gradient evaluation took 1e-05 seconds
1000 transitions using 10 leapfrog steps per transition would take 0.1 seconds.
Adjust your expectations accordingly!


Iteration:   1 / 1000 [  0%]  (Warmup)
Iteration: 100 / 1000 [ 10%]  (Warmup)
Iteration: 200 / 1000 [ 20%]  (Warmup)
Iteration: 300 / 1000 [ 30%]  (Warmup)
Iteration: 400 / 1000 [ 40%]  (Warmup)
Iteration: 500 / 1000 [ 50%]  (Warmup)
Iteration: 501 / 1000 [ 50%]  (Sampling)
Iteration: 600 / 1000 [ 60%]  (Sampling)
Iteration: 700 / 1000 [ 70%]  (Sampling)
Iteration: 800 / 1000 [ 80%]  (Sampling)
Iteration: 900 / 1000 [ 90%]  (Sampling)
Iteration: 1000 / 1000 [100%]  (Sampling)

 Elapsed Time: 0.059951 seconds (Warm-up)
               0.020852 seconds (Sampling)
               0.080803 seconds (Total)

Warning messages:
1: In normalizePath(file) :
  path[1]="https://raw.githubusercontent.com/stan-dev/example-models/master/misc/eight_schools/eight_schools.stan": No such file or directory
2: There were 117 divergent transitions after warmup. Increasing adapt_delta above 0.8 may help. See
http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup 
3: There were 1 chains where the estimated Bayesian Fraction of Missing Information was low. See
http://mc-stan.org/misc/warnings.html#bfmi-low 
4: Examine the pairs() plot to diagnose sampling problems

There seem to be a discouraging number of comments/warnings, but I’ll work through the output and try another couple of examples. How can I ensure that pure ASCII is used throughout? Are there certain settings you use or do you just develop an eye for it?

I mostly use RStudio and nano on Linux, neither of which add non-ASCII junk.

The normalizePath thing is not relevant and just a consequence of using a file from the web rather than one on your hard disk.
The divergent transition warning and the BFMI warning are relevant, but are a problem with the model and data rather than your setup. See http://mc-stan.org/misc/warnings.html .

All good; I’ve switched text editor.

This:

… is ASCII, but it’s also not Stan code. It’s the first few characters of the rich text format (RTF) file that TextEdit saved. TextEdit thinks RTF is text, but most programming languages consider ASCII or Unicode to be text.

You were right to switch your editor. Mac OS X these days comes with vi, an editor that generally doesn’t cause surprises and is good for general purpose text editing. RStudio is a good IDE for R-based statistics work.

Newcomers to vi often find it frustrating and then, after considerable persistence, fantastic. Personally, I use emacs, for which the same could be said but with the amplitude dialed up by an order of magnitude. :)

1 Like