Skip to content

Instantly share code, notes, and snippets.

@jebyrnes
Created November 4, 2018 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jebyrnes/c28d1f5523be392e4666da2f06110c10 to your computer and use it in GitHub Desktop.
Save jebyrnes/c28d1f5523be392e4666da2f06110c10 to your computer and use it in GitHub Desktop.
Some residual methods for tidybayes
tidy_residuals <- function(model){
UseMethod("tidy_residuals")
}
tidy_residuals.brmsfit <- function(model){
res <- residuals(model, summary=FALSE)
props <- summary(model)
nchains <- props$chains
iter <- props$iter - props$warmup
start <- seq(1, nrow(res), nrow(res)/nchains)
chains <- map(start, ~as.mcmc(res[.x:(.x+iter-1),])) %>%
coda::as.mcmc.list()
tidy_draws(chains)
}
gather_residuals <- function(model){
tidy_residuals(model) %>%
gather(.variable, .value, -.chain, -.iteration, -.draw)
}
spread_residuals <- function(model){
tidy_residuals(model)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment