Open njtierney opened 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?
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.
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?
}
Have updated tidy and glance and they now return data tables.
mmcc
will borrow from thebroom
functions:tidy
- produce summaries of the coefficientsaugment
- provide predictions from the model attached to the dataglance
- provide a one-line data.frame summaryThese 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?
tidy_draws
: return the full draws in "tidy" form (currently as inmcmc_to_dt
augment_draws
: return the predictions at each iteration