Skip to contents

This function takes a list of data frames, performs multiple imputation to fill in missing values using the 'mice' package, and combines the imputed datasets into a single dataset. The imputations are performed separately for each data frame in the list, and the results are combined into a 'mids' object, which is then cleaned and returned.

Usage

impute_and_combine(
  list_df,
  m = 10,
  exclude_vars = c("t0_sample_frame", "id", "t0_sample_origin_names_combined")
)

Arguments

list_df

A list containing data frames on which to perform multiple imputation.

m

The number of multiple imputations to perform for each data frame.

exclude_vars

A vector of variable names to be excluded from the imputation model.

Value

A data frame that combines all imputed datasets, with unnecessary columns removed and row names reset.

Examples

if (FALSE) { # \dontrun{
  # Assuming list_df is a list of data frames with missing values
  imputed_data <- impute_and_combine(list_df, m = 5)
  print(imputed_data)
} # }