nutterb / HydeNet

Hybrid Decision Networks in R
Other
23 stars 3 forks source link

`bindPosterior` should retain an index for chain number #83

Closed nutterb closed 8 years ago

nutterb commented 8 years ago

When multiple chains are runs and bound together with bindPosterior, we lose the chain number. This makes it impossible to generate plots similar to the default plot methods in rjags. It would be nice to do

Post <- compileJagsModel(Ion,
    data = list(median_pressure = 29.585),
    n.chains = 5) %>%
  HydePosterior(variable.names = "ion_111", n.iter = 100) %>%
  bindPosterior() %>%
  group_by(chain, median_pressure) %>%
  obs = 1:n())

ggplot(Post, aes(x = obs, y = ion_111)) + geom_line()

For that matter, bindPosterior could also retain an observation number index within each chain so it didn't have to be calculated manually.

jarrod-dalton commented 8 years ago

On top of this, it may be helpful to have a wrapper for HydePosterior() %>% bindPosterior() since those two functions are frequently run consecutively

nutterb commented 8 years ago

How would you feel about skipping the wrapper and just placing bindPosterior in HydePosterior. The impetus behind having separate functions was to allow us the option of using rjags' plotting methods to look at diagnostics. If we have the chain and observation indices, we can use ggplot to produce the same plots. (we may have to write a plotting method, but that's fairly trivial)

jarrod-dalton commented 8 years ago

I think this would be fine. Some people who are used to modeling in JAGS (yet still interested in using HydeNet - which is kind of like drivers of manual-transmission cars wanting to go to automatic transmission) may wish to retain the list structure of the posterior samples. A little dlply() helper function that translates the combined data frame you describe above to a list object more like the default rjags output would keep those folks happy.

nutterb commented 8 years ago

In that case, I'll rewrite bindPosterior to add the indices, and then add an option to HydePosterior with bind = TRUE to bind the results right there. Users who want the traditional output can set bind = FALSE