Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(mice)
- library(missForest)
- set.seed(123)
- # Create a dataset with missing values on 2 columns
- iris.mis = prodNA(iris[, c('Sepal.Length', 'Petal.Length')], 0.20)
- iris.mis = cbind(iris.mis, iris[, c('Sepal.Width', 'Petal.Width', 'Species')])
- # Setup MICE
- init = mice(iris.mis, maxit = 0)
- iris.metod = init$method
- iris.method['Sepal.Length'] = "" # Do not impute Sepal.Length
- # Run MICE
- imp = mice(iris.mis, m = 5, maxit = 5, method = iris.method)
- # Inspect Result
- res = mice::complete(imp, 1)
- print(length(res$Petal.Length[is.na(res$Petal.Length)]))
- # [1] 8
- # i.e. still 8 missing values in Petal.Length, when we wanted 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement