#' Glance upon your dic samples to get the penalised deviance
#'
#' This provides a one-row dataframe (`data.table`) with information on the
#' overall deviance, effective number of parameters (when `type` was pD) or
#' optimism (when `type` was popt), and resulting penalised deviance.
#'
#' @param x a dic object generated by rjags::dic.samples
#' @param ... (optional) additional arguments to pass
#'
#' @return a one-row dataframe of summary information of the dic samples
#'
#' @author Sam Clifford, \email{sj.clifford@@gmail.com}
#'
#' @import data.table
#' @export
#' @examples
#' library(rjags)
#' example_jags_model$recompile()
#' model_dic <- dic.samples(example_jags_model, n.iter = 1000)
#' glance(model_dic)
glance.dic <- function(x, ...){
dic_table <- with(x,
data.table::data.table(
deviance = as.numeric(deviance),
penalty = as.numeric(penalty),
type = as.character(type)
)
)
dic_return <- dic_table[ , lapply(.SD,
sum),
.SDcols = c("deviance", "penalty") ,
by = type]
dic_return[ , deviance_penalised := penalty + deviance ]
return(dic_return[])
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.