library(miceFast)
library(dplyr)
library(data.table)
data(air_miss)
# dplyr: continuous variable with Bayesian linear model
air_miss %>%
mutate(Ozone_imp = fill_NA(
x = ., model = "lm_bayes",
posit_y = "Ozone", posit_x = c("Solar.R", "Wind", "Temp")
))
# dplyr: categorical variable with LDA
air_miss %>%
mutate(x_char_imp = fill_NA(
x = ., model = "lda",
posit_y = "x_character", posit_x = c("Wind", "Temp")
))
# dplyr: grouped imputation with weights
air_miss %>%
group_by(groups) %>%
do(mutate(., Solar_R_imp = fill_NA(
x = ., model = "lm_pred",
posit_y = "Solar.R",
posit_x = c("Wind", "Temp", "Intercept"),
w = .[["weights"]]
))) %>%
ungroup()
# data.table
data(air_miss)
setDT(air_miss)
air_miss[, Ozone_imp := fill_NA(
x = .SD, model = "lm_bayes",
posit_y = "Ozone", posit_x = c("Solar.R", "Wind", "Temp")
)]
# data.table: grouped
air_miss[, Solar_R_imp := fill_NA(
x = .SD, model = "lm_pred",
posit_y = "Solar.R",
posit_x = c("Wind", "Temp", "Intercept"),
w = .SD[["weights"]]
), by = .(groups)]
# See the vignette for full examples:
# vignette("miceFast-intro", package = "miceFast")
Run the code above in your browser using DataLab