% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/matching_subclass.R
\name{subclass_match}
\alias{subclass_match}
\title{Subclassification on Propensity Score}
\usage{
subclass_match(
  formula = NULL,
  data = NULL,
  treatment = NULL,
  n_subclasses = 5L,
  ps = NULL,
  ps_model = NULL,
  estimand = "ATT"
)
}
\arguments{
\item{formula}{Formula for propensity score model (e.g.,
\code{treatment ~ age + income}). Ignored if \code{ps} is provided.}

\item{data}{Data frame containing all variables}

\item{treatment}{Character, name of the binary treatment column (0/1)}

\item{n_subclasses}{Integer, number of subclasses to create (default: 5).
Cochran (1968) showed that 5 subclasses removes over 90\\% of bias from
a single covariate.}

\item{ps}{Optional pre-computed numeric vector of propensity scores
(one per row in \code{data}). If NULL, a logistic regression model is
fit using \code{formula}.}

\item{ps_model}{Optional pre-fitted \code{glm} object for propensity scores}

\item{estimand}{Target estimand: \code{"ATT"} (default), \code{"ATE"}, or
\code{"ATC"}}
}
\value{
An S3 object of class \code{c("subclass_result", "couplr_result")}
containing:
\describe{
\item{matched}{Tibble with columns \code{id}, \code{side}, \code{subclass},
\code{ps}, \code{weight}}
\item{subclass_summary}{Tibble with per-subclass statistics: counts,
mean PS, and overlap status}
\item{info}{List with \code{n_subclasses}, \code{estimand}, \code{n_left},
\code{n_right}, \code{method}, \code{vars}}
}
}
\description{
Divides units into K strata based on quantiles of the propensity score,
then computes within-stratum weights for treatment effect estimation.
This is a simple, transparent approach to propensity score adjustment
that allows visual inspection of balance within each subclass.
}
\details{
The algorithm:
\enumerate{
\item Estimate propensity scores via logistic regression (or use
pre-computed scores)
\item Divide the propensity score distribution into K quantile-based strata
\item For each stratum, check overlap (both treated and control units
present)
\item Compute within-stratum weights based on the target estimand:
\itemize{
\item \strong{ATT}: Treated units get weight 1; control units get
weight \code{n_treated_in_stratum / n_control_in_stratum}
\item \strong{ATE}: Both groups get weight proportional to stratum
size relative to total sample
\item \strong{ATC}: Control units get weight 1; treated units get
weight \code{n_control_in_stratum / n_treated_in_stratum}
}
}
}
\examples{
set.seed(42)
n <- 200
data <- data.frame(
  id = 1:n,
  age = rnorm(n, 40, 10),
  income = rnorm(n, 50000, 15000)
)
data$treatment <- rbinom(n, 1, plogis(-2 + 0.05 * data$age))
result <- subclass_match(treatment ~ age + income, data, treatment = "treatment")
print(result)

}
