% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ild_msm_balance.R
\name{ild_msm_balance}
\alias{ild_msm_balance}
\title{Covariate balance (weighted SMD) for MSM / IPW}
\usage{
ild_msm_balance(
  data,
  treatment,
  covariates,
  weights_col = ".ipw_treat",
  by_occasion = FALSE,
  time_var = ".ild_seq"
)
}
\arguments{
\item{data}{An ILD object with \code{treatment}, \code{covariates}, and \code{weights_col}.}

\item{treatment}{Character. Binary treatment column (\code{0}/\code{1} or two-level factor).}

\item{covariates}{Character vector of numeric or binary covariate columns.}

\item{weights_col}{Analysis weights (e.g. \code{".ipw_treat"} or \code{".ipw"}).}

\item{by_occasion}{If \code{TRUE}, stratify by \code{time_var}.}

\item{time_var}{Occasion index column (default \code{".ild_seq"}).}
}
\value{
A \code{tibble} with columns \code{stratum}, \code{covariate}, \code{smd},
  \code{mean_treated}, \code{mean_control}, \code{ess_stratum}, \code{weight_col}.
}
\description{
Computes **standardized mean differences** between weighted treated and control groups for
each named covariate. When \code{by_occasion = TRUE}, balance is computed **within** each
occasion (stratum); when \code{FALSE}, all rows are pooled into one pseudo-population.
}
\examples{
set.seed(2)
d <- ild_simulate(n_id = 12, n_obs_per = 6, seed = 2)
d$stress <- rnorm(nrow(d))
d$trt <- as.integer(stats::rbinom(nrow(d), 1L, 0.45))
x <- ild_prepare(d, id = "id", time = "time")
x$.ipw_treat <- runif(nrow(x), 0.8, 1.2)
ild_msm_balance(x, treatment = "trt", covariates = "stress", weights_col = ".ipw_treat")
}
