R/tidy_stats.confint.r

Defines functions tidy_stats.confint

Documented in tidy_stats.confint

#' tidy_stats method for confint output.
#'
#' Creates a tidystats data frame from the output of confint.
#'
#' @param model The output of confint().
#' @param args Unused.
#'
#' @details This method should not be called directly.
#'
#' @export
tidy_stats.confint <- function(model, args = NULL) {
  output <- as.data.frame(model) %>% # as_data_frame() throws an error
    dplyr::mutate(
      term = rownames(model),
      order = 1:dplyr::n()
      ) %>%
    tidyr::gather("statistic", "value", -term, -order) %>%
    dplyr::arrange(order) %>%
    dplyr::select(term, statistic, value, -order) %>%
    dplyr::mutate(
      statistic = stringr::str_replace(statistic, " ", ""),
      statistic = paste(statistic, "CI")
      ) %>%
    tibble::as_data_frame()

  return(output)
}
WillemSleegers/tidystats-v0.3 documentation built on Aug. 12, 2019, 5:31 p.m.