# How to run Stan diagnose binary using StanSample.jl

**URL:** https://discourse.julialang.org/t/how-to-run-stan-diagnose-binary-using-stansample-jl/78304
**Category:** Probabilistic Programming
**Tags:** stan
**Created:** [March 22, 2022, 8:45pm UTC](https://discourse.julialang.org/t/how-to-run-stan-diagnose-binary-using-stansample-jl/78304 "2022-03-22T20:45:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Stephen\_Wild](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephen_wild/32/19061_2.png) [@Stephen\_Wild](https://discourse.julialang.org/u/Stephen_Wild)
#### Post date: [March 22, 2022, 8:45pm UTC](https://discourse.julialang.org/t/how-to-run-stan-diagnose-binary-using-stansample-jl/78304/1 "2022-03-22T20:45:20Z")

</div>

Hello,

I am trying to run Stan’s diagnose binary on a model. Unfortunately, I am getting an error. Here is some reproducible code using the example bernoulli model.

```julia
using StanSample, DataFrames

ProjDir = @ __DIR__

bernoulli_model = "
data {
  int<lower=1> N;
  int<lower=0,upper=1> y[N];
}
parameters {
  real<lower=0,upper=1> theta;
}
model {
  theta ~ beta(1,1);
  y ~ bernoulli(theta);
}
";

data = Dict("N" => 10, "y" => [0, 1, 0, 1, 0, 0, 0, 0, 0, 1])

# Keep tmpdir across multiple runs to prevent re-compilation
tmpdir = joinpath(ProjDir, "tmp")
isdir(tmpdir) && rm(tmpdir; recursive=true)

sm = SampleModel("bernoulli", bernoulli_model, tmpdir);

rc = stan_sample(sm; data);

if success(rc)
  diagnose(sm)
end

```

Unfortunately, I get this error message:

```julia
Base.IOError("could not spawn `/Users/stephenwild/cmdstan/bin/diagnose /Users/stephenwild/Desktop/Stats_stuff/State_space/tmp/bernoulli_chain_1.csv /Users/stephenwild/Desktop/Stats_stuff/State_space/tmp/bernoulli_chain_2.csv /Users/stephenwild/Desktop/Stats_stuff/State_space/tmp/bernoulli_chain_3.csv /Users/stephenwild/Desktop/Stats_stuff/State_space/tmp/bernoulli_chain_4.csv`: no such file or directory (ENOENT)", -2)

```

I tried using [StanDiagnose.jl](https://github.com/StanJulia/StanDiagnose.jl), but was also unsuccessful.

What code do I need to run Stan’s diagnose binary on a model?

---

<div class="post-metadata">

### Author: ![awasserman](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@awasserman](https://discourse.julialang.org/u/awasserman)
#### Post date: [March 22, 2022, 10:24pm UTC](https://discourse.julialang.org/t/how-to-run-stan-diagnose-binary-using-stansample-jl/78304/2 "2022-03-22T22:24:42Z")

</div>

Have you installed CmdStan already? StanSample assumes that it’s already installed in the location specified by the `CMDSTAN` environment variable (or equivalent in the Julia config file).

The error implies that there’s no file at `/Users/stephenwild/cmdstan/bin/diagnose`, so you probably have to either install cmdstan to `/Users/stephenwild/cmdstan` or update the `CMDSTAN` environment variable to point to where you did install it.

---

<div class="post-metadata">

### Author: ![Stephen\_Wild](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephen_wild/32/19061_2.png) [@Stephen\_Wild](https://discourse.julialang.org/u/Stephen_Wild)
#### Post date: [March 22, 2022, 11:44pm UTC](https://discourse.julialang.org/t/how-to-run-stan-diagnose-binary-using-stansample-jl/78304/3 "2022-03-22T23:44:30Z")

</div>

Thanks for the quick answer.

I have installed it, and I’ve successfully run a bunch of models with StanSample.jl. But I haven’t been able to run `diagnose` on them. That is why I find it weird.

---

<div class="post-metadata">

### Author: ![Stephen\_Wild](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephen_wild/32/19061_2.png) [@Stephen\_Wild](https://discourse.julialang.org/u/Stephen_Wild)
#### Post date: [March 22, 2022, 11:59pm UTC](https://discourse.julialang.org/t/how-to-run-stan-diagnose-binary-using-stansample-jl/78304/4 "2022-03-22T23:59:58Z")

</div>

For whatever reason, this round of cleaning and rebuilding cmdstan worked. I can now use `diagnose`. Not sure why it didn’t work earlier, even when I followed the instructions [here](https://mc-stan.org/docs/2_29/cmdstan-guide/diagnose.html).
