R/bal.tab.Match.R

Defines functions bal.tab.Match

Documented in bal.tab.Match

#' Balance Statistics for `Matching` Objects
#' 
#' @description Generates balance statistics for output objects from \pkg{Matching}.
#' 
#' @inheritParams bal.tab
#' @param x a `Match` object (the output of a call to \pkgfun{Matching}{Match} or \pkgfun{Matching}{Matchby}).
#' @param formula a `formula` with the treatment variable as the response and the covariates for which balance is to be assessed as the predictors. All named variables must be in `data`. See Details.
#' @param data a data frame containing variables named in `formula`, if supplied, and other arguments.
#' @param treat a vector of treatment statuses. See Details.
#' @param covs a data frame of covariate values for which to check balance. See Details.
#' @param s.d.denom `character`; how the denominator for standardized mean differences should be calculated, if requested. See [col_w_smd()] for allowable options. Abbreviations allowed. If not specified, `bal.tab()` will use "treated" if the estimand of the call to `Match()` is the ATT, "pooled" if the estimand is the ATE, and "control" if the estimand is the ATC.
#' 
#' @returns
#' If clusters and imputations are not specified, an object of class `"bal.tab"` containing balance summaries for the given object. See [bal.tab()] for details.
#' 
#' If clusters are specified, an object of class `"bal.tab.cluster"` containing balance summaries within each cluster and a summary of balance across clusters. See [`class-bal.tab.cluster`] for details.
#' 
#' @details
#' `bal.tab()` generates a list of balance summaries for the object given, and functions similarly to \pkgfun{Matching}{MatchBalance}. The input to `bal.tab.Match()` must include either both `formula` and `data` or both `covs` and `treat`. Using the `formula` + `data` inputs mirrors how \pkgfun{Matching}{MatchBalance} is used.
#' 
#' \pkg{cobalt} functions do not support `Match` object with sampling weights, i.e., with an argument passed to the `weights` argument of `Matching::Match()`.
#' 
#' @seealso [bal.tab()] for details of calculations.
#' 
#' @examplesIf rlang::is_installed("Matching")
#' data("lalonde", package = "cobalt")
#' library(Matching)
#' 
#' ## Estimate propensity score
#' p.fit <- glm(treat ~ age + educ + race + 
#'                married + nodegree + re74 + re75, 
#'              data = lalonde,
#'              family = "binomial")
#' 
#' Match.out <- Match(Tr = lalonde$treat,
#'                    X = fitted(p.fit))
#' 
#' ## Using formula and data
#' bal.tab(Match.out, formula = treat ~ age + educ + race + 
#'           married + nodegree + re74 + re75,
#'         data = lalonde)

#' @exportS3Method bal.tab Match
bal.tab.Match <-      function(x, formula = NULL, data = NULL, treat = NULL, covs = NULL,
                               stats, int = FALSE, poly = 1, distance = NULL, addl = NULL, continuous, binary, s.d.denom, thresholds = NULL, weights = NULL, cluster = NULL, imp = NULL, pairwise = TRUE, s.weights = NULL, abs = FALSE, subset = NULL, quick = TRUE,
                               ...) {
  .bal.tab_dispatch(x, "x2base")
}

Try the cobalt package in your browser

Any scripts or data that you put into this service are public.

cobalt documentation built on Aug. 26, 2026, 1:07 a.m.