Created
November 4, 2018 02:58
-
-
Save jebyrnes/c28d1f5523be392e4666da2f06110c10 to your computer and use it in GitHub Desktop.
Some residual methods for tidybayes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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