knitr::opts_chunk$set(echo = TRUE)
Multiple imputation is a method for analyzing incomplete multivariate data. Amelia II (Multiple Imputation of Incomplete Multivariate Data) is a R package which allows users to impute ("fill in" or rectangularize) incomplete data sets so that analyses which require complete observations can appropriately use all the information present in a dataset with missingness, and avoid the biases, ineﬃciencies, and incorrect uncertainty estimates that can result from dropping all partially observed observations from the analysis.
This package include a function to wrap the functinos in Amelia package to automate the MI prcodures required by Simmons Research. Compared to Amelia package, our new function has the following features:
One function related to missing imputation are included in the package:
library(dplyr) library(Amelia) library(SimmonsResearchR)
Load the data.
We want to impute the missing AT variables.
imputed1 <- amelia_impute(data = magdwt, ID = "RESPID", m = 5, rounded = TRUE)
All the data except the ID will be used for the missing imputation. We may want to assign the variables to be imputed (dependent variables) and the variables used for the imputation (independent variables)
imputed.vars <- paste0("AT", 1:10) indep.vars <- c(paste0("d",4:6), paste0("d28_",10:26)) imputed2 <- amelia_impute(data = magdwt, ID = "RESPID", m = 5, rounded = TRUE, imputed.vars = imputed.vars, indep.vars = indep.vars)
We can also include a grouping variable, all the observations falling in the same group will be in the same MI session. If the MI fails, the function can adopt fewer variables defined in indep.vars2 to rerun the procedures.
imputed.vars <- paste0("AT", 1:10) indep.vars <- c(paste0("d",4:6), paste0("d28_",10:26)) indep.vars2 <- c(paste0("d",4:6)) #if MI fails, rerun using variables in indep.vars2 #grouping the obs into segments using MAG variable before IM imputed2 <- amelia_impute(data = (magdwt %>% filter(MAG<=10)), ID = "RESPID", m = 5, rounded = TRUE, imputed.vars = imputed.vars, indep.vars = indep.vars, indep.vars2 = indep.vars2, by.vars = "MAG")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.