% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/Imputation.R
\name{as_mild_list}
\alias{as_mild_list}
\title{Standardize multiple imputation outputs into a unified list}
\usage{
as_mild_list(x)
}
\arguments{
\item{x}{An imputation object. Accepted classes and formats:
\itemize{
\item \code{mids}: output of \code{mice::mice()}.
\item \code{data.frame}: long-format output of
\code{mice::complete(x, action = "long")}. Must contain a
\code{.imp} column.
\item \code{amelia}: output of \code{Amelia::amelia()}.
\item \code{imputationList}: output of \code{mitools::imputationList()}.
\item \code{list}: a plain list where every element is a
\code{data.frame} representing one completed dataset.
}}
}
\value{
A named list of \code{data.frame} objects, one per imputed
dataset. All datasets are guaranteed to have identical dimensions and
column names, and to contain no \code{NA}, \code{NaN}, \code{Inf}, or
all equal values in a column.
}
\description{
Converts multiple imputation outputs from different packages into a
standardized list of completed datasets, where each element corresponds
to one imputed dataset. Supported formats include \code{mids} objects
from \pkg{mice}, long-format data frames, \code{amelia} objects,
\code{imputationList} objects from \pkg{mitools}, and plain lists of
data frames. After conversion, consistency and data quality checks are
applied across all imputed datasets.

This function is designed as a preprocessing step for clustering
multiple imputed datasets, ensuring strict comparability across imputations.
}
\details{
The function performs the following consistency checks before returning:
\itemize{
\item Identical number of rows across all imputed datasets.
\item Identical number of columns across all imputed datasets.
\item Identical column names across all imputed datasets.
\item Absence of \code{NA}, \code{NaN}, and \code{Inf} values.
\item Absence of numeric columns with all values equal,
as such variables provide no information for distance-based
clustering and may lead to degenerate solutions.
}
All datasets are coerced to base \code{data.frame} to avoid
compatibility issues with \code{tibble} or other subclasses.
}
\examples{
# ------------------------------------------------------------
# Example 1: Simple list of completed datasets
# ------------------------------------------------------------
set.seed(123)

imp_list <- replicate(3, {
  data.frame(
    x = rnorm(10),
    y = rnorm(10)
  )
}, simplify = FALSE)

mild <- as_mild_list(imp_list)

length(mild)      # number of imputations
str(mild[[1]])    # structure of one dataset

\donttest{
# ------------------------------------------------------------
# Example 2: List of completed datasets with mice
# ------------------------------------------------------------

if (requireNamespace("mice", quietly = TRUE)) {

  set.seed(123)

  # Example 1: Using a mids object
  imp <- mice::mice(mice::nhanes, m = 5, printFlag = FALSE)
  mild <- as_mild_list(imp)

  length(mild)        # number of imputations
  str(mild[[1]])      # structure of one completed dataset

  # Example 2: Using long-format data
  long_df <- mice::complete(imp, action = "long", include = FALSE)
  mild2 <- as_mild_list(long_df)

  length(mild2)
}
}

}
\references{
Rubin, D. B. (1976).
Inference and missing data.
\emph{Biometrika}, \strong{63}(3), 581-592.
\doi{10.1093/biomet/63.3.581}

Rubin, D. B. (1987).
\emph{Multiple Imputation for Nonresponse in Surveys}. Wiley.

van Buuren, S., & Groothuis-Oudshoorn, K. (2011).
mice: Multivariate Imputation by Chained Equations in R.
\emph{Journal of Statistical Software}, \strong{45}(3), 1-67.
\doi{10.18637/jss.v045.i03}

Honaker, J., King, G., & Blackwell, M. (2011).
Amelia II: A Program for Missing Data.
\emph{Journal of Statistical Software}, \strong{45}(7), 1-47.
\doi{10.18637/jss.v045.i07}
}
\seealso{
\code{\link{cluster_imputations}}, \code{\link{consensus_clustering}}
}
