% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ild_ipw_refit.R
\name{ild_ipw_refit}
\alias{ild_ipw_refit}
\title{Refit an ILD model with inverse-probability weights (sensitivity analysis)}
\usage{
ild_ipw_refit(fit_or_formula, data, weights = ".ipw", ar1 = FALSE, ...)
}
\arguments{
\item{fit_or_formula}{Either a fitted model from [ild_lme()] (lmerMod), or a
formula. If a formula, \code{data} and \code{weights} are required.}

\item{data}{An ILD object (see [is_ild()]) containing a weight column (default \code{.ipw})
from [ild_ipw_weights()] or joint MSM weights from [ild_joint_msm_weights()], when refitting
from a fit (or the data to fit when \code{fit_or_formula} is a formula).}

\item{weights}{Character. Name of the weight column in \code{data} (default \code{".ipw"}).}

\item{ar1}{Logical. Must be \code{FALSE} for IPW refit (nlme weighted refit not supported).}

\item{...}{Passed to [ild_lme()] or \code{lme4::lmer()}.}
}
\value{
A fitted model (lmerMod) with \code{attr(..., "ild_data")} set so that
  [tidy_ild_model()] and [ild_diagnostics()] work. For inference under estimated
  weights, see [ild_msm_bootstrap()] and [ild_msm_inference].
}
\description{
Takes a fit from [ild_lme()] (or a formula and data) and refits the model
using observation weights from [ild_ipw_weights()]. Only the lme4 (lmer)
path is supported; nlme (ar1 = TRUE) is not supported for weighted refits.
This is a sensitivity tool, not a full MNAR solution.
}
\examples{
set.seed(1)
d <- ild_simulate(n_id = 12, n_obs_per = 10, seed = 1)
d$stress <- rnorm(nrow(d))
d$mood <- d$y
d$mood[sample(nrow(d), 25)] <- NA
x <- ild_prepare(d, id = "id", time = "time")
x <- ild_center(x, mood)
mm <- ild_missing_model(x, "mood", "stress")
xw <- ild_ipw_weights(x, mm, stabilize = TRUE)
fit0 <- ild_lme(mood ~ mood_bp + mood_wp + stress + (1 | id), data = xw,
  ar1 = FALSE, warn_no_ar1 = FALSE)
fitw <- ild_ipw_refit(fit0, data = xw)
tidy_ild_model(fitw)
}
