Skip to content

Instantly share code, notes, and snippets.

@njtierney
Created February 17, 2017 06:48
Show Gist options
  • Save njtierney/aff88d1cb182c959b436154f48faf1e6 to your computer and use it in GitHub Desktop.
Save njtierney/aff88d1cb182c959b436154f48faf1e6 to your computer and use it in GitHub Desktop.
Gist of a little function for tidying the results of inla
# broom tidy method for class "inla"
tidy.inla <- function(x){
# x = model_inla
term_names <- rownames(x$summary.fixed)
tibble::as_tibble(x$summary.fixed) %>%
dplyr::mutate(terms = term_names) %>%
dplyr::select(terms,
dplyr::everything())
}
@jebyrnes
Copy link

jebyrnes commented May 1, 2024

You could probably make it more flexible with arguments, but....

# broom tidy method for class "inla"

tidy.inla <- function(x){
  
  # x = model_inla
  term_names <- rownames(x$summary.fixed)
  re_term_names <- rownames(x$summary.hyperpar)
  
  
  tibble::as_tibble(bind_rows(x$summary.fixed, x$summary.hyperpar)) %>%
    dplyr::mutate(terms = c(term_names, re_term_names)) %>%
    dplyr::select(terms,
                  dplyr::everything())
  
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment