JointAI (version 0.5.1)

get_MIdat: Extract multiple imputed datasets

Description

Creates a dataset containing multiple imputed datasets stacked onto each other (i.e., long format). These data can be automatically exported to SPSS (i.e., a .txt file containing the data and a .sps file containing syntax to generate a .sav file). For the export function the foreign package needs to be installed.

Usage

get_MIdat(object, m = 10, include = TRUE, start = NULL,
  minspace = 50, seed = NULL, export_to_SPSS = FALSE,
  resdir = NULL, filename = NULL)

Arguments

object

object inheriting from class 'JointAI'

m

number of imputed datasets

include

should the original, incomplete data be included?

start

the first iteration of interest (see window.mcmc)

minspace

minimum number of iterations between iterations chosen as imputed values.

seed

optional seed

export_to_SPSS

logical; should the completed data be exported to SPSS?

resdir

optional directory for results (if unspecified and export_to_SPSS = TRUE the current working directory is used)

filename

optional file name (without ending; if unspecified and export_to_SPSS = TRUE a name is generated automatically)

Value

A dataframe containing the imputed values (and original data) stacked. The variable Imputation_ identifies the imputations, while .rownr identifies rows of the rows of the original data. In cross-sectional datasets the variable .id is added as subject identifier.

See Also

plot_imp_distr

Examples

Run this code
# NOT RUN {
# fit a model and monitor the imputed values with monitor_params = c(imps = TRUE)
mod <- lm_imp(y~C1 + C2 + M2, data = wideDF, monitor_params = c(imps = TRUE), n.iter = 100)

# Example 1: without export to SPSS
MIs <- get_MIdat(mod, m = 3, seed = 123)

# }
# NOT RUN {
# Example 2: with export for SPSS (here: to the temporary directory "temp_dir")
temp_dir <- tempdir()
MIs <- get_MIdat(mod, m = 3, seed = 123, resdir = temp_dir,
                 filename = "example_imputation",
                 export_to_SPSS = TRUE)

# }

Run the code above in your browser using DataCamp Workspace