| knn_imp | R Documentation |
Impute missing values in a numeric matrix using full K-nearest neighbors (K-NN).
knn_imp(
obj,
k,
colmax = 0.9,
method = c("euclidean", "manhattan"),
cores = 1,
post_imp = TRUE,
subset = NULL,
dist_pow = 0,
na_check = TRUE,
.progress = FALSE
)
obj |
A numeric matrix with samples in rows and features in columns. |
k |
Integer. Number of nearest neighbors to use for K-NN imputation. |
colmax |
Numeric scalar between |
method |
Character. K-NN imputation distance method: either |
cores |
Integer. Number of cores to use for K-NN imputation. Defaults
to |
post_imp |
Logical. If |
subset |
Optional character or integer vector specifying columns to
target for imputation. If |
dist_pow |
Numeric. Power used to penalize more distant neighbors in
the weighted average. |
na_check |
Logical. If |
.progress |
Logical. If |
knn_imp() performs imputation column-wise, treating rows as observations
and columns as features.
Nearest neighbors are found using brute-force K-NN.
When dist_pow > 0, imputed values are computed as distance-weighted
averages. Weights are inverse distances raised to the power of dist_pow.
A numeric matrix of the same dimensions as obj, with missing
values imputed. The returned object has class slideimp_results.
Use subset when only specific columns need imputation.
Use grouped or sliding-window imputation for very large matrices.
Troyanskaya O, Cantor M, Sherlock G, Brown P, Hastie T, Tibshirani R, Botstein D, Altman RB (2001). Missing value estimation methods for DNA microarrays. Bioinformatics, 17(6), 520-525. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1093/bioinformatics/17.6.520")}
set.seed(123)
obj <- sim_mat(20, 20, perc_col_na = 1)$input
sum(is.na(obj))
# Select `k` with `tune_imp()`.
result <- knn_imp(obj, k = 10, .progress = FALSE)
result
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.