% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ild_msm_balance.R
\name{ild_ipw_ess}
\alias{ild_ipw_ess}
\title{Effective sample size from weights}
\usage{
ild_ipw_ess(
  data,
  weights_col = ".ipw",
  by_occasion = FALSE,
  time_var = ".ild_seq"
)
}
\arguments{
\item{data}{An ILD object.}

\item{weights_col}{Name of the nonnegative weight column (e.g. \code{".ipw"} or \code{".ipw_treat"}).}

\item{by_occasion}{If \code{TRUE}, one ESS per level of \code{time_var}.}

\item{time_var}{Column for occasion index (default \code{".ild_seq"}).}
}
\value{
A single numeric (pooled) or a \code{tibble} with \code{occasion} and \code{ess} when
  \code{by_occasion = TRUE}.
}
\description{
For nonnegative weights \eqn{w}, \eqn{\mathrm{ESS} = (\sum w)^2 / \sum w^2}.
}
\examples{
set.seed(1)
d <- ild_simulate(n_id = 10, n_obs_per = 5, seed = 1)
x <- ild_prepare(d, id = "id", time = "time")
x$.ipw <- runif(nrow(x), 0.5, 1.5)
ild_ipw_ess(x, ".ipw")
ild_ipw_ess(x, ".ipw", by_occasion = TRUE)
}
