Description Usage Arguments Details Value Author(s) Examples
Multiple Imputation on a Model
1 2 3 4 5 6 7 8 9 |
model |
An R-friendly model. Currently, it only allows lm objects, but will eventually allow other objects (e.g., glm). |
data |
The dataset used for analysis. This dataset should contain predictors used to impute the missing values |
predictors |
A list of predictors (as a character vector) that identify which variables to keep (or drop; see below argument). |
keep |
Logical. Should the list of predictors be kept or dropped? Defaults to keep. |
imputations |
The number of imputations to be performed. Defaults to 20. |
This is a wrapper function for both the mice function in the mice package, as well as for basic models in R (e.g., lm). As input, it takes the model the user wishes to estimate using advanced missing data strategies, as well as a list of variables they wish to use to impute the missing values. The function takes the raw data and performs MI using mice, then re-analyzes the dataset and outputs the multiply imputed parameter estimates.
.mod Should the model be returned?
Dustin Fife
1 2 3 4 5 6 7 8 9 10 11 12 13 | data(exercise_data)
d = exercise_data
##### create missing data in motivation
missing.ld = which(d$motivation<quantile(d$motivation, .25))
notmissing = which(!(1:nrow(d) %in% missing.ld))
d$weight.loss.missing = d$weight.loss
d$weight.loss.missing[missing.ld] = NA
#### create model with missing data
model = lm(weight.loss.missing~motivation, data=d)
predictors = c("muscle.gain.missing", "weight.loss")
impute.me(mod, data=d, predictors=predictors, keep=F, imputations=5)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.