% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/balance.R
\name{mb_balance_table}
\alias{mb_balance_table}
\title{Pre-treatment balance table}
\usage{
mb_balance_table(treated, ..., data = NULL, threshold = 0.1)
}
\arguments{
\item{treated}{Logical or 0/1 numeric vector identifying the
treated unit. \code{TRUE} / \code{1} means treated.}

\item{...}{Numeric or factor covariates to balance check. Names
become row labels. May be passed as a data frame via the
\code{data} argument.}

\item{data}{Optional data frame. If supplied, \code{...} is ignored
and every column other than \code{treated} is checked. Pass the
\code{treated} argument as a column reference (e.g. \code{data$treat})
or as the column name in the data frame.}

\item{threshold}{Numeric scalar. Absolute SMD threshold above
which a row is flagged as imbalanced. Default \code{0.10}.}
}
\value{
An \code{mb_balance_table} data frame with columns
\code{covariate}, \code{mean_treated}, \code{mean_control}, \code{sd_treated},
\code{sd_control}, \code{n_treated}, \code{n_control}, \code{smd}, \code{p_value},
\code{imbalanced}. Numeric and binary covariates use the
pooled-SD SMD and a Welch two-sample t-test. Factor covariates
are decomposed into one row per non-reference level using the
level-indicator and a chi-squared test on the original
factor.
}
\description{
Computes a Magenta Book-standard balance check for pre-treatment
covariates: by-arm mean and standard deviation, standardised
mean difference (SMD), and a two-sample test of equality. The
SMD is the unitless effect size most evaluators report; rules
of thumb flag \verb{|SMD| > 0.10} as a meaningful imbalance and
\verb{|SMD| > 0.25} as a serious imbalance.
}
\details{
For a numeric or 0/1 covariate \eqn{X} with treated mean
\eqn{\bar X_T}, control mean \eqn{\bar X_C}, treated SD
\eqn{s_T}, and control SD \eqn{s_C}, the standardised mean
difference is
\deqn{\text{SMD} = \frac{\bar X_T - \bar X_C}{\sqrt{(s_T^2 + s_C^2)/2}}.}

This is the equal-weighted pooled-SD form recommended by Stuart
(2010) and Austin (2009) for propensity-score balance
diagnostics. It differs from Cohen's d, which uses the
degrees-of-freedom-weighted pooled SD
\eqn{\sqrt{(s_T^2(n_T-1) + s_C^2(n_C-1))/(n_T+n_C-2)}}; the two
agree when \eqn{n_T = n_C}. magentabook ships a cross-validation
test against \code{cobalt::bal.tab} which uses the same averaged-SD
form.

Rules of thumb (Cohen 1988; Stuart 2010):
\itemize{
\item \verb{|SMD| < 0.10}: well balanced
\item \verb{0.10 <= |SMD| < 0.25}: meaningful imbalance, consider
covariate adjustment
\item \verb{|SMD| >= 0.25}: serious imbalance, matching or weighting
recommended
}

Magenta Book impact evaluation guidance recommends a balance
table for any quasi-experimental design and as a sense-check
even for randomised designs.
}
\examples{
set.seed(20260427)
n <- 400
treated <- rep(c(0, 1), each = n / 2)
age     <- rnorm(n, mean = 45 + 2 * treated, sd = 10)
female  <- rbinom(n, 1, 0.5)
income  <- rnorm(n, mean = 30000 + 1500 * treated, sd = 8000)
mb_balance_table(treated = treated, age = age, female = female, income = income)
}
\references{
Stuart, E. A. (2010). Matching methods for causal inference: A
review and a look forward. Statistical Science 25(1).
\url{doi:10.1214/09-STS313}.

Austin, P. C. (2009). Balance diagnostics for comparing the
distribution of baseline covariates between treatment groups
in propensity-score matched samples. Statistics in Medicine
28(25). \url{doi:10.1002/sim.3697}.

HM Treasury (2020). The Magenta Book, supplementary guidance on
quasi-experimental methods.
\url{https://www.gov.uk/government/publications/the-magenta-book}.
}
\seealso{
\code{\link[=mb_did_2x2]{mb_did_2x2()}}, \code{\link[=mb_questions]{mb_questions()}}.

Other planning: 
\code{\link{mb_counterfactual}()},
\code{\link{mb_evaluation_plan}()},
\code{\link{mb_questions}()},
\code{\link{mb_stakeholders}()}
}
\concept{planning}
