Xtable for rstan tables

Hi all,

Is it possible to get rstan to provide results in xtable. I’m getting this error message when I try to get the summary of the results into xtable.

Error in UseMethod(“xtable”): no applicable method for ’xtable’

applied to an object of class “list”

Thanks in advance,

David

Hi David,

Can you post the code that you’re using to call xtable with the summary?

If it is possible, it would likely involve calling the rstan::As.mcmc.list() and hoping there is an xtable method for a coda object.

I just tried this

library(xtable)
library(coda)
results <- As.mcmc.list(myfit, pars=c(“alpha”,“beta1”,“sigma”))
xtable(results)

and this is the error message I received.

Error in UseMethod(“xtable”): no applicable method for ’xtable’applied to an object of class “mcmc.list”

(coda and xtable are loaded)

Thanks,

David

OK. Hope is not turning out to be a great strategy these days.

No kidding. The only thing that seems to work is to launch shinystan on the object and then generate a latex table from there. It’s an extra step, but it works.

David

The following works for me:

fit = stan(model, data=data)
xtable(summary(fit)$summary)

I believe your original issue was that you were calling xtable on just summary(fit), which returns a list of summary dataframes (one summarising all chains, and then one per chain).