Skip to content

Instantly share code, notes, and snippets.

@oliviergimenez
Created December 21, 2022 11:24
Show Gist options
  • Save oliviergimenez/b91c81f56ffe410bb02feb1a03d23601 to your computer and use it in GitHub Desktop.
Save oliviergimenez/b91c81f56ffe410bb02feb1a03d23601 to your computer and use it in GitHub Desktop.
Converts MCMC output list into dataframe with better column names for plotting
# from Cole Monnahan https://github.com/colemonnahan/fcwhales
convert_to_df <- function(fit, name = NULL){
fit <- as.mcmc(fit)
post <- data.frame(do.call(rbind, fit))
new <- gsub('[.]$', '', names(post))
new <- gsub('[.]','_', new)
names(post) <- new
if(!is.null(name)) post$model <- name
return(post)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment