
⚠ Deprecation notice
rMIDAS is deprecated. Please use rMIDAS2, which replaces rMIDAS with a faster PyTorch-based backend, a simpler API (no manual preprocessing), and no
reticulatedependency at runtime. rMIDAS will remain on CRAN for existing users but will not receive new features or bug fixes. Source repository: https://github.com/MIDASverse/rMIDAS2A migration guide is included as a vignette in both packages:
vignette("migrating-to-rMIDAS2", package = "rMIDAS").Install the replacement:
install.packages("rMIDAS2")
rMIDAS is an R package for accurate and efficient multiple imputation using deep learning methods. The package provides a simplified workflow for imputing and then analyzing data:
convert() carries out all necessary preprocessing
stepstrain() constructs and trains a MIDAS imputation
modelcomplete() generates multiple completed datasets from
the trained modelcombine() runs regression analysis across the complete
data, following Rubin’s combination rulesrMIDAS is based on the Python package MIDASpy.
rMIDAS also incorporates several features to streamline and improve the the efficiency of multiple imputation analysis:
data.table and
mltools packagesglm (applying
Rubin’s combination rules)For more information on MIDAS, the method underlying the software, see:
Lall, Ranjit, and Thomas Robinson. 2022. “The MIDAS Touch: Accurate and Scalable Missing-Data Imputation with Deep Learning.” Political Analysis 30, no. 2: 179-196. Published version.
Lall, Ranjit, and Thomas Robinson. 2023. “Efficient Multiple Imputation for Diverse Data in Python and R: MIDASpy and rMIDAS.” Journal of Statistical Software 107, no. 9: 1-38. doi:10.18637/jss.v107.i09. Published version.
rMIDAS is available on CRAN. To install the package in R, you can use the following code:
install.packages("rMIDAS")To install the latest development version, use the following code:
# install.packages("devtools")
devtools::install_github("MIDASverse/rMIDAS")Note that rMIDAS uses the reticulate package to
interface with Python. When the package is first loaded, it will prompt
the user on whether to set up a Python environment and its dependencies
automatically. Users that choose to set up the environment and
dependencies manually, or who use rMIDAS in headless mode can specify a
Python binary using set_python_env() (examples below).
Currently, Python versions from 3.6 to 3.10 are supported. For a custom
Python environment the following dependencies are also required:
Setting a custom Python install must be performed before training or imputing data occurs. To manually set up a Python environment:
library(rMIDAS)
# Decline the automatic setup
# Point to a Python binary
set_python_env(x = "path/to/python/binary")
# Or point to a virtualenv binary
set_python_env(x = "virtual_env", type = "virtualenv")
# Or point to a conda environment
set_python_env(x = "conda_env", type = "conda")
# Now run rMIDAS::train() and rMIDAS::complete()...You can also download the rmidas-env.yml
conda environment file from this repository to set up all dependencies
in a new conda environment. To do so, download the .yml file, navigate
to the download directory in your console and run:
conda env create -f rmidas-env.ymlThen, prior to training a MIDAS model, make sure to load this environment in R:
# First load the rMIDAS package
library(rMIDAS)
# Decline the automatic setup
set_python_env(x = "rmidas", type = "conda")Note: reticulate only allows you to set a
Python binary once per R session, so if you wish to switch to a
different Python binary, or have already run train() or
convert(), you will need to restart or terminate R prior to
using set_python_env().
rMIDAS is packaged with four vignettes:
vignette("imputation_demo", "rMIDAS")
demonstrates the basic workflow and capacities of
rMIDASvignette("custom_python_versions", "rMIDAS")
provides detailed guidance on configuring Python binaries and
environments, including some troubleshooting tipsvignette("use_server", "rMIDAS")
provides guidance for running rMIDAS in headless
modevignette("migrating-to-rMIDAS2", "rMIDAS") guides
migration to the new rMIDAS2 packageAn additional example that showcases rMIDAS core functionalities can be found here.
rMIDAS is deprecated and is being retained for existing workflows. If you need new development or a simpler installation path, please migrate to rMIDAS2. The successor package source repository is https://github.com/MIDASverse/rMIDAS2. If you encounter an issue that affects an existing rMIDAS workflow, please raise it here.