R/estimate_ates.R

Defines functions estimate_ates

Documented in estimate_ates

#' Estimate many average treatment effects
#'
#'
#' @param this_data data frame to estimate from.
#' @param fns list of functions to compute ATEs.
#' @param profile logical indicating whether the computation times should be returned rather than the estimates themselves.
#' @param ... additional arguments to be passed to the functions in \code{fns}
#'
#' @return a data frame containing all the ATEs, one per column.
#' @export
#' @importFrom purrr map
#'
#' @examples
#' 
#' 
estimate_ates <- function(this_data, fns, profile = FALSE, ...) {
  # browser()
  ests <- map(fns, function(f) {
    f(this_data, ...)
  }) %>% bind_cols
  if (!profile) {
    return(ests)
  } else {
    times <- sapply(fns, function(f) {
      system.time(f(this_data, ...))[3]
    })
    names(times) <- names(fns)
    return(list(ests = ests, times = times))
  }
}
denisagniel/synthate documentation built on April 16, 2020, 12:45 a.m.