impute.me: Multiple Imputation on a Model

Description Usage Arguments Details Value Author(s) Examples

View source: R/impute.me.R

Description

Multiple Imputation on a Model

Usage

1
2
3
4
5
6
7
8
9
impute.me(
  model,
  data,
  predictors = NULL,
  keep = T,
  imputations = 20,
  silent = F,
  return.mod = F
)

Arguments

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.

Details

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.

Value

.mod Should the model be returned?

Author(s)

Dustin Fife

Examples

 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)

dustinfife/fifer documentation built on Oct. 31, 2020, 3:36 p.m.