% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ild_iptw_msm_weights.R
\name{ild_iptw_msm_weights}
\alias{ild_iptw_msm_weights}
\title{Sequential MSM inverse probability of treatment weights (IPTW for A_t)}
\usage{
ild_iptw_msm_weights(
  x,
  treatment,
  history,
  time_var = ".ild_seq",
  stabilize = c("marginal", "prior_treatment", "none"),
  prior_treatment = NULL,
  trim = c(0.01, 0.99),
  ...
)
}
\arguments{
\item{x}{An ILD object (see [is_ild()]).}

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

\item{history}{Predictors \eqn{\bar{L}_t} for the **denominator** model: a
\code{character} vector of column names, or a one-sided \code{formula}
like \code{~ stress + trt_lag1}. Empty history fits an intercept-only model.}

\item{time_var}{Character. Occasion index column (default \code{".ild_seq"}).}

\item{stabilize}{Character: \code{"marginal"}, \code{"prior_treatment"}, or \code{"none"}.}

\item{prior_treatment}{Character. Required when \code{stabilize = "prior_treatment"}:
name of the \eqn{A_{t-1}} (or prior treatment) column for the numerator model.}

\item{trim}{Numeric of length 2. Quantiles applied to the **final** cumulative
\code{.ipw_treat} (default \code{c(0.01, 0.99)}). Use length-0 numeric to skip.}

\item{...}{Passed to \code{stats::glm()} for each occasion (denominator model;
numerator model when \code{prior_treatment} is used also uses \code{...}).}
}
\value{
\code{x} with \code{.ipw_treat} set to the cumulative sequential weight.
  Attributes: \code{ild_iptw_msm_fits} (named list of denominator \code{glm} fits
  by occasion), \code{ild_iptw_msm_numerator_fits} (same for numerator when
  \code{prior_treatment}).
}
\description{
For **time-varying binary treatment** \eqn{A_t}, fits a separate treatment
propensity model at each occasion \eqn{t} (pooling persons at that time):
\eqn{P(A_t \mid \bar{L}_t)} where \eqn{\bar{L}_t} is supplied by the user
(e.g. lags from [ild_lag()], prior treatment, time-varying confounders). The
stabilized factor at each person-occasion is multiplied **within person**
over time to yield a **cumulative** MSM IPTW in \code{.ipw_treat}.
}
\details{
This differs from [ild_iptw_weights()], which fits **one pooled** logistic
over all rows (appropriate for a single treatment decision or descriptive
pooling, not the standard sequential MSM estimand for \eqn{\bar{A}_K}).

**Assumptions:** Sequential exchangeability given \eqn{\bar{L}_t}, positivity
at each \eqn{t}, and correct models. Variance (e.g. bootstrap by person) is
not computed here.
}
\section{Stabilization}{

\describe{
  \item{\code{marginal}}{Numerator at each occasion uses the sample marginal
    \eqn{P(A_t = 1)} among rows at that time (same pattern as pooled stabilized
    IPTW).}
  \item{\code{prior_treatment}}{Numerator uses \eqn{P(A_t \mid A_{t-1})} from
    a logistic model \code{A_t ~ prior_treatment} fit at each occasion (pass
    \code{prior_treatment} column name). Denominator remains \eqn{P(A_t \mid \bar{L}_t)}.}
  \item{\code{none}}{Unstabilized \eqn{1/P(A_t \mid \bar{L}_t)} for the observed \eqn{A_t}.}
}
}

\section{Bundle integration}{

Sets \code{.ipw_treat} for use with [ild_ipcw_weights()] and
[ild_joint_msm_weights()].
}

\examples{
set.seed(11)
d <- ild_simulate(n_id = 20, n_obs_per = 6, seed = 11)
d$stress <- rnorm(nrow(d))
d$trt <- as.integer(stats::rbinom(nrow(d), 1L, 0.4))
d <- ild_prepare(d, id = "id", time = "time")
d <- ild_lag(d, stress, mode = "gap_aware", max_gap = Inf)
d <- ild_lag(d, trt, mode = "gap_aware", max_gap = Inf)
x <- ild_iptw_msm_weights(d, treatment = "trt", history = ~ stress_lag1 + trt_lag1)
summary(x$.ipw_treat)
}
\seealso{
[ild_iptw_weights()], [ild_ipcw_weights()], [ild_joint_msm_weights()]

Other ild_diagnostics_utilities: 
\code{\link{ild_design_check}()},
\code{\link{ild_ipcw_weights}()},
\code{\link{ild_iptw_weights}()},
\code{\link{ild_ipw_weights}()},
\code{\link{ild_joint_msm_weights}()},
\code{\link{ild_missing_cohort}()},
\code{\link{ild_missing_compliance}()},
\code{\link{ild_missing_hazard_first}()},
\code{\link{ild_missing_model}()},
\code{\link{ild_missing_pattern}()},
\code{\link{ild_missingness_report}()}
}
\concept{ild_diagnostics_utilities}
