missForest
missForest is een niet-parametrische imputatiemethode voor gemengde type tabelgegevens in R. Het verwerkt numerieke en categorische variabelen gelijktijdig door iteratief random forests te trainen om ontbrekende waarden te voorspellen op basis van de waargenomen gegevens. Geen expliciete modelaannames, geen matrixfactorisaties—alleen sterke voorspellende baselines die direct goed werken.
- Werkt met elke mix van numerieke en factor kolommen
- Vangt nonlineariteiten en interacties
- Rapporteert out-of-bag (OOB) imputeerfout (NRMSE/PFC)
- Ondersteunt parallelle uitvoering (per-variabele of per-bos)
- Twee forest backends:
ranger(standaard) enrandomForest(legacy/compat)
Installatie
# 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$OOBerrorTrue error if xtrue was provided (for benchmarking only)
imp$errorEen backend kiezen
# 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)Parallelisatie
Er zijn twee modi beschikbaar via parallelize:
"variables": bouw bossen voor verschillende variabelen parallel (registreer een foreach-backend)."forests": paralleliseer binnen het bos van één enkele variabele (ranger-threads; of foreach sub-bossen voor randomForest).
# 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-overzicht
missForest(xmis, ...)
Kernimputatiefunctie.
Belangrijkste argumenten:
xmis— data frame/matrix met ontbrekende waarden (kolommen moetennumericoffactorzijn).maxiter— maximum aantal iteraties (standaard10).ntree— bomen per bos (standaard100).mtry— aantal variabelen geprobeerd bij elke splitsing (standaardsqrt(p)).nodesize— length-2 numeriek: minimale knoopgrootte voor c(numeric, factor). Standaardc(5, 1).variablewise— geeft per-variabele OOB-fout terug alsTRUE.parallelize—"no","variables"of"forests".num.threads— threads voorranger(genegeerd doorrandomForest).backend—"ranger"(standaard) of"randomForest".xtrue— optionele volledige data voor benchmarking (voegt$errortoe).
backend = "ranger":ntree → num.treesnodesize → min.bucket(apart voor regressie/classificatie; standaardc(5,1))sampsize(aantallen) →sample.fraction(fracties; algemeen of per klasse)classwt → class.weightscutoffwordt afgehandeld door het trainen van probability forests en post-thresholding
Hulpprogramma's
mixError(ximp, xmis, xtrue)— berekent NRMSE (numeriek) en PFC (factor) over echte ontbrekende waarden.nrmse(ximp, xmis, xtrue)— NRMSE voor alleen continue data.prodNA(x, noNA = 0.1)— voegt MCAR-missingness toe aan een data frame.varClass(x)— retourneert"numeric"/"factor"per kolom.
Tips & beste praktijken
- Zet karakterkolommen om naar factoren voordat je
missForestaanroept. - Voor brede data, overweeg
parallelize = "variables". Voor diepe/kostbare bomen, overweegparallelize = "forests". - Stel een seed in voor quasi-reproduceerbare resultaten:
set.seed(123); imp <- missForest(x)
``
- Je kunt
ntree verlagen tijdens het prototypen om de iteratie te versnellen.---
Citaat
Als je missForest gebruikt, citeer dan:
Stekhoven, D. J. & Bühlmann, P. (2012). MissForest—nonparametric missing value imputation for mixed-type data.* Bioinformatics, 28(1), 112–118. https://doi.org/10.1093/bioinformatics/btr597
Je kunt ook het pakket citeren:
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: 2026-07-17 ---