kenkellner / jagsUI

R package to Run JAGS (Just Another Gibbs Sampler) analyses from within R
https://kenkellner.github.io/jagsUI/
35 stars 7 forks source link

Error with `plot.jagsUI` and `traceplot` when using `codaOnly` #48

Closed mikemeredith closed 3 years ago

mikemeredith commented 3 years ago

When 1 or more parameters monitored are included in codaOnly and you run plot or traceplot with the output, you get Error in x$summary[parameter, "Rhat"] : subscript out of bounds traceback shows this is coming from param_trace.

When parameters=NULL, get_plot_info does all_params <- param_names(x$samples) so the default is to plot all the parameters monitored, including those in codaOnly, and that happens with densityplot.

But plot and traceplot display Rhat, and that is not calculated for codaOnly things, hence the error.

Not sure how to solve this. One option is to get all_params from the summary instead of samples, maybe x$summary[, 'Rhat'], but param_names expects an mcmc.list object. Maybe modify param_names to accept any vector of names, which would affect ppcheck and wiskerplot.

Alternatively, catch the error in param_trace and display the trace plot without R-hat.

I favour the first option: I use codaOnly for parameters with thousands of nodes. I don't want to see the summary stats and I sure don't want to plough through the diagnostic plots for all those.

kenkellner commented 3 years ago

Thanks Mike. I agree that the best option is to not include codaOnly parameters in the plots.

mikemeredith commented 3 years ago

Thanks for fixing that Ken.