R/coef_format.R

Defines functions coef_format

Documented in coef_format

#' Format coefficient table
#'
#'\code{coef_format} takes the tibble of coefficients and p.values
#'from a tidy call, and roudns to 3 dp and adds stars as a column.
#'
#' @param df A tibble from a tidy broom call
#' @param ... Extra calls to round.
#'
#' @return A tibble
#' @export
#'
#' @examples
#'
#' all_data_wide %>% filter(Treatment != "CON") %>%
#'   group_by(Host, Treatment) %>%
#'   do(tidy(glm(Inf_rate ~ MRS2, data = ., family = binomial()))) %>%
#'   format_num()

coef_format  <- function(df, ...) {

  df <- df %>%
    mutate_if(is.numeric, round, digits = 3, ...) %>%
    mutate(signif = ifelse(p.value > 0.1, "",
                           ifelse(p.value <= 0.1 & p.value > 0.05, ".",
                           ifelse(p.value <= 0.05 & p.value > 0.01, "*",
                                  ifelse(p.value <= 0.01 & p.value > 0.001, "**", "***")))))

  return(df)
}
daflealab/genlabfunc documentation built on May 27, 2019, 7:25 a.m.