Thanks to Mitzi, I was able to get cmdstanr running on my mac. But when I tried to run it, I had two problems.

The example model on the cmdstanr Getting Started page compiled and ran but gave the wrong answer.

The 8 schools model gave an error in compilation.
I don’t know if these two problems are related. I’ll describe them both below. I’m on Rstudio version 1.2.5033, R version 3.6.1, Mac Catalina 10.15.4, rstan 2.19.2 (not using rstan for this, but it’s in my environment so I thought I’d let you know), cmdstanr version 0.0.0.9000
–
Problem 1. The example model on the cmdstanr Getting Started page compiled and ran but gave the wrong answer.
I went to the example on the cmdstanr Getting Started page:
file < file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
mod < cmdstan_model(file)
and this seemed to work fine. I checked by printing the model:
mod$print()
and it was just as on the Getting Started page. But then I ran it:
data_list < list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1))
fit < mod$sample(
data = data_list,
seed = 123,
num_chains = 2,
num_cores = 2
)
and I got this:
1159 of 2000 (58.0%) transitions hit the maximum treedepth limit of 10 or 2^101 leapfrog steps.
Trajectories that are prematurely terminated due to this limit will result in slow exploration.
Increasing the max_depth limit can avoid this at the expense of more computation.
If increasing max_depth does not remove warnings, try to reparameterize the model.
and this:
> fit$summary()
# A tibble: 3 x 10
variable mean median sd mad q5 q95 rhat ess_bulk
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 lp__ 7.31e+ 0 7.01e+ 0 8.09e 1 3.58e 1 8.87e+ 0 6.75e+ 0 1.00 770.
2 theta 2.54e 1 2.35e 1 1.25e 1 1.28e 1 8.04e 2 4.77e 1 1.00 1597.
3 sigma 1.13e+20 9.99e+19 1.03e+20 1.03e+20 2.43e+19 3.14e+20 1.65 3.43
# … with 1 more variable: ess_tail <dbl>
Uh oh!
–
Problem 2. The 8 schools model gave an error in compilation.
Next I thought I’d try the 8 schools model. I used the following file, “8schools.stan”:
data {
int<lower=0> J; // number of schools
real y[J]; // estimated treatment effects
real<lower=0> sigma[J]; // standard error of effect estimates
}
parameters {
real mu; // population treatment effect
real<lower=0> tau; // standard deviation in treatment effects
vector[J] eta; // unscaled deviation from mu by school
}
transformed parameters {
vector[J] theta = mu + tau * eta; // school treatment effects
}
model {
target += normal_lpdf(eta  0, 1); // prior logdensity
target += normal_lpdf(y  theta, sigma); // loglikelihood
}
and then I did this:
mod < cmdstan_model("8schools.stan")
And this is what appeared in the Rstudio console:
Compiling Stan program...
Warning:
The parameter mu has 0 priors.
Warning:
The parameter tau has 0 priors.
Warning:
The parameter theta has 0 priors.
/var/folders/j8/kg_4ryhs4d78nts87zqw73wh0000gn/T/RtmphsxHbn/model38f583623e3.hpp:4:11: error: expected identifier or '{'
namespace 8schools_model_namespace {
^
/var/folders/j8/kg_4ryhs4d78nts87zqw73wh0000gn/T/RtmphsxHbn/model38f583623e3.hpp:4:11: error: expected unqualifiedid
/var/folders/j8/kg_4ryhs4d78nts87zqw73wh0000gn/T/RtmphsxHbn/model38f583623e3.hpp:494:9: error: expected unqualifiedid
typedef 8schools_model_namespace::8schools_model stan_model;
^
/var/folders/j8/kg_4ryhs4d78nts87zqw73wh0000gn/T/RtmphsxHbn/model38f583623e3.hpp:503:3: error: unknown type name 'stan_model'
stan_model* m = new stan_model(data_context, seed, msg_stream);
^
/var/folders/j8/kg_4ryhs4d78nts87zqw73wh0000gn/T/RtmphsxHbn/model38f583623e3.hpp:503:23: error: unknown type name 'stan_model'
stan_model* m = new stan_model(data_context, seed, msg_stream);
^
5 errors generated.
make: *** [/var/folders/j8/kg_4ryhs4d78nts87zqw73wh0000gn/T/RtmphsxHbn/model38f583623e3] Error 1
Error in processx::run(command = make_cmd(), args = c(tmp_exe, include_paths, :
System command 'make' failed, exit status: 2, stderr (last 10 lines):
E> typedef 8schools_model_namespace::8schools_model stan_model;
E> ^
E> /var/folders/j8/kg_4ryhs4d78nts87zqw73wh0000gn/T/RtmphsxHbn/model38f583623e3.hpp:503:3: error: unknown type name 'stan_model'
E> stan_model* m = new stan_model(data_context, seed, msg_stream);
E> ^
E> /var/folders/j8/kg_4ryhs4d78nts87zqw73wh0000gn/T/RtmphsxHbn/model38f583623e3.hpp:503:23: error: unknown type name 'stan_model'
E> stan_model* m = new stan_model(data_context, seed, msg_stream);
E> ^
E> 5 errors generated.
E> make: *** [/var/folders/j8/kg_4ryhs4d78nts87zqw73wh0000gn/T/RtmphsxHbn/model38f583623e3] Error 1
Type .Last.error.trace to see where the error occured
–
A few problems here:
First, it said, “Warning: The parameter theta has 0 priors.” But theta is a transformed parameter. I don’t think you’d expect to have a prior on a transformed parameter. I mean, sure, you can, but it wouldn’t be the usual thing. So I don’t think this warning is appropriate.
Second, it said “occured” rather than “occurred” in the error message. No big deal but we might as well fix typos.
Third, and most importantly, it gave a compilation error, and I can’t figure out what the error is. I followed the instructions and typed .Last.error.trace in the Rstudio console, and this is what came out:
Stack trace:
1. cmdstanr:::cmdstan_model("8schools.stan")
2. CmdStanModel$new(stan_file = stan_file, compile = compile, ...)
3. .subset2(public_bind_env, "initialize")(...)
4. self$compile(...)
5. processx::run(command = make_cmd(), args = c(tmp_exe, include_paths, ...
6. throw(new_process_error(res, call = sys.call(), echo = echo, ...
x System command 'make' failed, exit status: 2, stderr (last 10 lines):
E> typedef 8schools_model_namespace::8schools_model stan_model;
E> ^
E> /var/folders/j8/kg_4ryhs4d78nts87zqw73wh0000gn/T/RtmphsxHbn/model38f583623e3.hpp:503:3: error: unknown type name 'stan_model'
E> stan_model* m = new stan_model(data_context, seed, msg_stream);
E> ^
E> /var/folders/j8/kg_4ryhs4d78nts87zqw73wh0000gn/T/RtmphsxHbn/model38f583623e3.hpp:503:23: error: unknown type name 'stan_model'
E> stan_model* m = new stan_model(data_context, seed, msg_stream);
E> ^
E> 5 errors generated.
E> make: *** [/var/folders/j8/kg_4ryhs4d78nts87zqw73wh0000gn/T/RtmphsxHbn/model38f583623e3] Error 1
–
Thanks in advance for your help!
Andrew