Description Usage Arguments Value See Also Examples
View source: R/impute_missing_values.R
Impute missing values, using knn by default or alternatively median-impute numerics, mode-impute factors. Add missingness indicators.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
data |
Dataframe or matrix. |
type |
"knn" or "standard" (median/mode). NOTE: knn will result in the data being centered and scaled! |
add_indicators |
Add a series of missingness indicators. |
prefix |
String to add at the beginning of the name of each missingness indicator. |
skip_vars |
List of variable names to exclude from the imputation. |
all_vars |
Calculate imputation value for all variables, in cases where the imputation info may be used for future datasets. |
remove_constant |
Remove constant missingness indicators, if applicable. |
remove_collinear |
Remove collinear missingness indicators, if applicable. |
values |
Named list with imputation value to use from another dataset. |
h2o_glrm |
Optional h2o glrm model for imputing on new data (e.g. test set) |
glrm_k |
Number of principal components to estimate (up to the # of columns in the data). |
verbose |
If True display extra information during execution. |
List with the following elements:
$data - imputed dataset.
$impute_info - if knn, caret preprocess element for imputing test data.
$impute_values - if standard, list of imputation values for each variable.
missingness_indicators
preProcess
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # Load a test dataset.
data(PimaIndiansDiabetes2, package = "mlbench")
# Check for missing values.
colSums(is.na(PimaIndiansDiabetes2))
# Impute missing data and add missingness indicators.
# Don't impute the outcome though.
result = impute_missing_values(PimaIndiansDiabetes2, skip_vars = "diabetes")
# Confirm we have no missing data.
colSums(is.na(result$data))
#############
# K-nearest neighbors imputation
result2 = impute_missing_values(PimaIndiansDiabetes2, type = "knn",
skip_vars = "diabetes")
# Confirm we have no missing data.
colSums(is.na(result2$data))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.