Web Analytics

missForest

⭐ 105 stars Simplified Chinese by stekhoven

missForest

CRAN status CRAN RStudio mirror downloads CRAN RStudio mirror downloads R-CMD-check test-coverage License: GPL (≥ 2)-blue.svg)

missForest 是 R 中用于 混合类型 表格数据的非参数插补方法。它通过迭代训练随机森林,从已观测的数据中预测缺失项,能够同时处理 数值型和分类型 变量。无需显式建模假设,无需矩阵分解——只是强大的预测基线,开箱即用,表现优异。

该包还包括用于衡量插补误差、生成缺失数据进行实验以及检查变量类型的实用工具。


安装

# CRAN (recommended)
install.packages("missForest")

Development version (from GitHub)

install.packages("remotes")

remotes::install_github("stekhoven/missForest")


Quick start

library(missForest)

Example data

data(iris)

Introduce ~20% MCAR missingness

set.seed(81) iris_mis <- prodNA(iris, noNA = 0.20)

Impute with default backend (ranger)

imp <- missForest(iris_mis, xtrue = iris, verbose = TRUE)

Imputed data

head(imp$ximp)

Estimated OOB errors (NRMSE for numeric, PFC for factors)

imp$OOBerror

True error if xtrue was provided (for benchmarking only)

imp$error

选择后端

# Legacy behavior using randomForest
imp_rf <- missForest(iris_mis, backend = "randomForest")

Explicitly use ranger with limited threads

imp_rg <- missForest(iris_mis, backend = "ranger", num.threads = 2)

并行化

通过 parallelize 提供两种模式:

# Not run:

library(doParallel)

registerDoParallel(2)

imp_vars <- missForest(iris_mis, parallelize = "variables", verbose = TRUE)

imp_fors <- missForest(iris_mis, parallelize = "forests", verbose = TRUE, num.threads = 2)


API 概述

missForest(xmis, ...)

核心插补函数。

主要参数:

backend = "ranger" 的部分参数映射:

工具函数

---

使用建议与最佳实践

  set.seed(123); imp <- missForest(x)
  ``
  • 你可以在原型设计阶段降低 ntree 来加快迭代速度。
---

引用

如果你使用 missForest,请引用:

Stekhoven, D. J. & Bühlmann, P. (2012). MissForest—混合类型数据的非参数缺失值插补方法。* Bioinformatics, 28(1), 112–118. https://doi.org/10.1093/bioinformatics/btr597

你也可以引用该包:

r citation("missForest") ``


Contributing

Issues and pull requests are welcome. Please include a minimal reproducible example when reporting bugs. For performance discussions, share small benchmarks and session info.


License

GPL (≥ 2)


Contact

Daniel J. Stekhoven — stekhoven@nexus.ethz.ch


--- Tranlated By Open Ai Tx | Last indexed: 2025-12-08 ---