#' combine_log() combine estimates from mitools like objects, intended for logit models
#'
#' @param mi_estimates is an object generated by mitools::mitools::MIcombine or survey::withPV()
#'
#' @return a tidy table with estimates, estandard errors, p value, and confidence intervals
#'
#' @examples
#' library(dplyr)
#' library(erce)
#' ## add example besides combine_log()
#'
#'
#' @export
# function
combine_log <- function(mi_estimates) {
# require libraries
require(dplyr)
require(mitools)
# function to avoid text output from mitools
quiet <- function(x) {
sink(tempfile())
on.exit(sink())
invisible(force(x))
}
# get cpmbined estimates and summary
mi_results <- quiet(mitools::MIcombine(mi_estimates))
summary <- quiet(summary(mi_results))
# create tidy table
tidy_results <- summary %>%
tibble::rownames_to_column("term") %>%
dplyr::rename(e = results,
se = se,
lo = `(lower`,
hi = `upper)`) %>%
cbind(miss_info = mi_results$missinfo) %>%
cbind(df = mi_results$df) %>%
dplyr::mutate(p_val = 2 * (1 - pt(abs(e / se), df))) %>%
dplyr::mutate(
e = as.numeric(e),
se = as.numeric(se),
p_val = as.numeric(p_val),
lo = as.numeric(lo),
hi = as.numeric(hi),
miss_info = as.numeric(miss_info)
) %>%
# for logit estimates
mutate(or = exp(e)) %>%
mutate(or_lo = exp(lo)) %>%
mutate(or_hi = exp(hi)) %>%
dplyr::select(term, e, se, p_val, lo, hi, or, or_lo, or_hi) %>%
tibble::as_tibble()
# give output
return(tidy_results)
# Source: https://github.com/wepelham3/sack2/blob/master/R/tidy_MIcombine.R
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.