% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data-impute.R
\name{tr_impute}
\alias{tr_impute}
\title{Impute missing values in a clinical dataset}
\usage{
tr_impute(data, method = c("mice", "missForest"), m = 5, seed = 123)
}
\arguments{
\item{data}{A data frame with missing values, typically the output of
\code{tr_load_clinical()}.}

\item{method}{Character. Either \code{"mice"} (default) or \code{"missForest"}.}

\item{m}{Integer. Number of multiple imputations to run if \code{method = "mice"}.
Defaults to 5. Ignored for \code{"missForest"}.}

\item{seed}{Integer. Random seed for reproducibility. Defaults to 123.}
}
\value{
A completed data frame with missing values filled in. If
\code{method = "mice"}, the first completed dataset is returned, and the
full \code{mids} object is attached as an attribute (\code{"mice_object"}) in
case the user wants to inspect all imputations.
}
\description{
Fills in missing values using either multiple imputation (\code{mice}) or
a random-forest based approach (\code{missForest}). The method must be
chosen explicitly, this function does not guess for you.
}
\examples{
df <- data.frame(
  a = c(5, 7, 3, 9, 2, 8, 6, 4, 5, 7),
  b = c(1, 3, 2, 4, 5, 3, 2, NA, 1, 3)
)
completed <- tr_impute(df, method = "mice", m = 2)
}
