impute | R Documentation |
Imputation is the process of replacing missing data with substituted values. This is done because of three main problems that missing data causes: missing data can introduce a substantial amount of bias, make the handling and analysis of the data more arduous, and create reductions in efficiency.
impute(
.data,
vars = everything(),
algorithm = "mice",
m = 10,
method = NULL,
FUN = median,
info = TRUE,
...
)
is_imputed(.data)
get_mice(.data)
.data |
data set with missing values to impute |
vars |
variables of |
algorithm |
algorithm to use for imputation, must be |
m |
number of multiple imputations if using MICE, see |
method |
method to use if using MICE, see |
FUN |
function to use for single-point imputation (directly) or for MICE to summarise the results over all |
info |
print info about imputation |
... |
arguments to pass on to |
Imputation can be done using single-point, such as the mean or the median, or using Multivariate Imputations by Chained Equations (MICE). Using MICE is a lot more reliable, but also a lot slower, than single-point imputation.
The suggested and default method is MICE. The generated MICE object will be stored as an attribute with the data, and can be retrieved with get_mice()
, containing all specifics about the imputation. MICE is also known as fully conditional specification and sequential regression multiple imputation. It was designed for data with randomly missing values, though there is simulation evidence to suggest that with a sufficient number of auxiliary variables it can also work on data that are missing not at random.
Use is_imputed()
to get a data.frame with TRUE
s for all values that were imputed.
iris2 <- dplyr::as_tibble(iris)
iris2[2, 2] <- NA
iris2[3, 3] <- NA
iris2[4, 5] <- NA
iris
iris2
result <- iris2 |> impute()
result
iris2 |> impute(algorithm = "single-point")
iris2 |>
impute(vars = starts_with("Sepal"),
algorithm = "single-point")
iris2 |>
impute(vars = where(is.double),
algorithm = "single-point",
FUN = median)
result |> is_imputed()
result |> get_mice()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.