Bridgesampling with rstanarm?


#1

Given the recent blog post about the bridgesampling R package I wanted to try it on some rstanarm stanreg objects. However, at least for a poisson glm fit, not all information that bridgesampling needs is retained, i.e.:

> bridge_sampler(mvr_stan_poisson1$stanfit)
Error in object@.MISC$stan_fit_instance$unconstrain_pars(pars) : 
  variable gamma missing

Is there some way to get around this or can I only use this with “manually” written Stan models?


#2

Can you give a minimal example that does this? (ie all the code and data for something that gives the same error)

Otherwise it’s hard to diagnose.


#3

The full dataset used for this is a bit large but the stan_glm call is this:

> mvr_stan_poisson1 <- stan_glm(Fix ~ Experience + Ability + treatment + System + Lab, 
                      data = mvr, family = poisson, 
                      prior = normal(0,20.0), prior_intercept = normal(0,20.0),
                      chains = CHAINS, cores = CORES, seed = SEED, iter = ITER)
> bridge_sampler(mvr_stan_poisson1$stanfit)
Error in object@.MISC$stan_fit_instance$unconstrain_pars(pars) : 
  variable gamma missing

I’ll see if I can cut down the dataset to something smaller/minimal that has the same behavior.

Should I understand you as bridgesampling on rstanarm models are generally supported and my failure here depends on some specifics about my model or dataset?


#4

Actually, the same behavior happens for warpbreaks dataset included in R:

> breaksmodel<-stan_glm(breaks~wool*tension, warpbreaks, family=poisson)
> bridge_sampler(breaksmodel$stanfit)
Error in object@.MISC$stan_fit_instance$unconstrain_pars(pars) : 
  variable gamma missing

#5

From ?bridge_sampler

Note
To be able to use a stanreg object for samples, the user crucially needs to have specified the diagnostic_file when fitting the model in rstanarm.

See the diagnostic_file argument to rstan::sampling that is passed through the ... by model fitting functions in rstanarm.


#6

A minimally working example (from ?bridgesampling and written by Ben Goodrich):

library(bridgesampling)
library(rstanarm)

# N.B.: remember to specify the diagnostic_file

fit_1 <- stan_glm(mpg ~ wt + qsec + am, data = mtcars,
                  chains = 2, cores = 2, iter = 5000,
                  diagnostic_file = file.path(tempdir(), "df.csv"))
bridge_1 <- bridge_sampler(fit_1)
fit_2 <- update(fit_1, formula = . ~ . + cyl)
bridge_2 <- bridge_sampler(fit_2, method = "warp3")
bf(bridge_1, bridge_2)

#7

Thanks. Sorry for missing this in the docs.