emultimputation | R Documentation |
This is a wrap function for the Multiple Imputation package mice.
emultimputation( data, RHS.formula, dep.vars, ind.vars, m = 5, maxit = 50, method = "pmm", seed = 500, digits = 4 )
data |
a data.frame |
RHS.formula |
a string with the RHS of the regression model |
dep.vars |
a string vector with the names of the dependent variables. |
ind.vars |
a string vector with the names of the independent variables. |
m |
Number of multiple imputations. The default is |
maxit |
A scalar giving the number of iterations. The default is 5. |
method |
Can be either a single string, or a vector of strings with
length |
seed |
An integer that is used as argument by the |
digits |
integer, number of significant digits to return in the table |
See help(mice)
The function returns a list with the summary output of the models estimated after the multiple imputation is performed
library(magrittr) data = tibble::data_frame(x1 = rnorm(200,3,1), x2 = rexp(200), cat.var = sample(c(0,1), 200, replace=TRUE), cat.var2 = sample(letters[1:4], 200, replace=TRUE), y1 = 10*x1*cat.var+rnorm(200,0,10) + 3*x2*(6*(cat.var2=='a') -3*(cat.var2=='b') + 1*(cat.var2=='c') +1*(cat.var2=='d')), y2 = -10*x1*cat.var+rnorm(200,0,10) + 10*x2*(3*(cat.var2=='a') -3*(cat.var2=='b') + 1*(cat.var2=='c') -1*(cat.var2=='d')) ) %>% dplyr::mutate(cat.var=as.factor(cat.var)) data$x1[sample(1:nrow(data), 10)] = NA formula = "x1*cat.var+x2*cat.var2" imp = emultimputation(data, formula, dep.vars = c("y1", "y2"), ind.vars=c("x1", "x2", "cat.var", "cat.var2")) imp
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.