njtierney / mmcc

Fast, tidy functions for mcmc diagnostics and summaries, built with data.table
http://mmcc.njtierney.com/
Other
24 stars 5 forks source link

new sets of functions for tidying mcmc objects #18

Open njtierney opened 6 years ago

njtierney commented 6 years ago

mmcc will borrow from the broom functions:

These functions work for a frequentist model - which provides point estimates of coefficients, but in a Bayesian context, where we have distributions for each estimate, it doesn't quite map on.

So the question then is, should we have another family of functions to return the distributions?

samclifford commented 6 years ago

Part of the issue here is that JAGS doesn't return a fitted model, it returns a list of matrices of MCMC draws. If we go to augment, how do we know that we have the response variable in the model? If we want to glance at some model summaries, at what point have we calculated the DIC?

samclifford commented 6 years ago

The value of rjags::dic.samples is an object of class dic which contains vectors of contributions to deviance and the penalty, then returns the penalised deviance. Perhaps we could do with a glance.dic to return this information in a tidy data frame. I can see it being very useful when fitting multiple models to the same data set (using purrr::map or similar) and wanting to find which has the lowest DIC.

samclifford commented 6 years ago

Some initial thoughts:


tidy.dic <- function(dic){

  dic.tidy <- with(dic, 
                   data.frame(deviance = as.numeric(deviance),
                              penalty = as.numeric(penalty),
                              type = as.character(type)))

  return(dic.tidy)

}

glance.dic <- function(X){
  require(data.table)

  dic.table <- data.table(tidy.dic(X))

  dic.return <- dic.table[ , lapply(.SD, sum), .SDcols = c("deviance", "penalty") , by=type]
  dic.return[ , DIC := penalty + deviance  ]

  return(dic.return)
  # how do we get this to not be a promise?

}
samclifford commented 6 years ago

Have updated tidy and glance and they now return data tables.