Hi everyone,

I ran several computationally intense models (~2-3 weeks/model; so it’s not desirable to re-run these models) with CmdStan and want to compute the Bayes factor for these models. I came across the bridgesampling package. I imported the .csv output files from CmdStan to R using :

```
files <- c("output_1.csv", "output_2.csv")
out = read_stan_csv(files)
```

When I run

```
library(bridgesampling)
bridge_sampler(out)
```

I get the following error message:

```
Error in .local(object, ...) :
the model object is not created or not valid
```

How can I get around this error message? Is there any workaround to compute the Bayes factor without rerunning the models in RStan?

bridgesampling isn’t compatible with `cmdstan`

unfortunately, there’s more discussion and a possible workaround on their github: bridgesampling on cmdstanr · Issue #27 · quentingronau/bridgesampling · GitHub

2 Likes

Not the desired answer, but a very helpful one, thanks a lot!

1 Like

Update: With the workaround suggested (create an empty Stanfit object), the bridge_sampler command was running for an hour. Then it outputs the following:

```
> bridge_sampler(out, new_mod)
Iteration: 1
Iteration: 2
Iteration: 1
Error in jj[2, ] : Index out of bounds
1: Infinite value in iterative scheme, returning NA.
Try rerunning with more samples.
2: logml could not be estimated within maxiter, rerunning with adjusted starting value.
Estimate might be more variable than usual.
```

Here is my code:

```
# Load packages
library(rstan)
library(bridgesampling)
# Load posterior output from the cmdstan estimation
files <- c("output_1.csv")
out = read_stan_csv(files)
data_stan = rstan::read_rdump("full_data.R");
new_mod <- stan(file = "hmm.stan", data = data_stan, iter = 0)
bridge_sampler(out, new_mod)
```

Any ideas what’s happening?

Try the development version of `bridgesampling`

:

```
devtools::install_github("quentingronau/bridgesampling@master")
```

If that also doesn’t work then you’ll need to open an issue on the bridgesampling github

1 Like