Preface

R packages

In this practical, a number of R packages are used. If any of them are not installed you may be able to follow the practical but will not be able to run all of the code. The packages used (with versions that were used to generate the solutions) are:

  • R version 3.6.0 (2019-04-26)
  • mice (version: 3.4.0)
  • mitools (version: 2.4)
  • miceadds (version: 3.2.48)
  • plyr (version: 1.8.4)

Help files

You can find help files for any function by adding a ? before the name of the function.

Alternatively, you can look up the help pages online at https://www.rdocumentation.org/ or find the whole manual for a package at https://cran.r-project.org/web/packages/available_packages_by_name.html

Dataset & imputed data

For this practical, we will again use the NHANES dataset that we have seen in previous practicals.

Download the file NHANES_for_practicals.RData from here. To load this dataset, you can use the command file.choose() which opens the explorer and allows you to navigate to the location of the file NHANES_for_practicals.RData on your computer. If you know the path to the file, you can also use load("<path>/NHANES_for_practicals.RData").

To save some time, we will work with the mids object called imp that we created in the practical Multiple Imputation using MICE.

You can load it into your workspace by clicking the object saved_imps.RData if you are using RStudio. Alternatively, you can load this workspace using load("<path>/saved_imps.RData"). You then need to run:

Aim of this practical

Working with multiply imputed data can get a lot more complex, for example, when the research question cannot be answered by just one regression model, or when the data need some further processing after imputation.

In the lecture, we have seen that the mice package allows post-processing of variables, but for more complex calculations it is often more convenient to perform them after imputation.

When data have been imputed with a different R package, but you want to use the convenient functions of the mice package, the imputed data needs to be converted to mids or mira objects first.

The focus of this practical is on functions to convert multiply imputed data between different formats. An overview of possible workflows and the necessary functions is given in this flow diagram: