write.mice.imputation: Export Multiply Imputed Datasets from a 'mids' Object

Description Usage Arguments Value Author(s) See Also Examples

View source: R/write.mice.imputation.R

Description

Exports multiply imputed datasets and information about the imputation. Objects of class mids (generated by mice::mice) and mids.1chain (generated by mice.1chain) are supported.

Usage

1
2
write.mice.imputation(mi.res, name, include.varnames = TRUE,
      long = TRUE, mids2spss = TRUE, spss.dec = ",", dattype = NULL)

Arguments

mi.res

Object of class mids or mids.1chain

name

Name of created subdirectory and datasets

include.varnames

An optional logical indicating whether variable names should be included in the imputed dataset. The default is TRUE.

long

An optional logical indicating whether the dataset should also be saved in a long format?

mids2spss

An optional logical indicating whether a syntax for reading imputed datasets in SPSS should be included

spss.dec

SPSS decimal separator (can be "," or ".")

dattype

Format of the saved dataset: csv or csv2

Value

Several files are saved using impxxx (the name) as the prefix:

impxxx.Rdata

Saved object of class mids

impxxx__DATALIST.Rdata

Saved object of a list containing multiply imputed datasets

impxxx__IMP_LIST

File with list of multiply imputed datasets

impxxx__IMP_SUMMARY

Summary file of the imputation

impxxx__IMPDATA_nn

Imputed datasets nn

impxxx__IMPMETHOD

File containing imputation methods

impxxx__LEGENDE

File with variable names of the dataset

impxxx__LONG

Imputed datasets in long format

impxxx__PREDICTORMATRIX

File containing the predictor matrix

impxxx__SPSS.sps

SPSS syntax for reading the corresponding txt file into SPSS format.

Author(s)

Alexander Robitzsch

See Also

See also mice::mids2mplus and mice::mids2spss

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 
#############################################################################
# EXAMPLE 1: Imputation of nhanes data and write imputed datasets on disk
#############################################################################

data(nhanes,package="mice")

#**********
# Model 1: Imputation using mice
imp1 <- mice::mice( nhanes , m=3 , maxit=5 )
# write results
write.mice.imputation(mi.res=imp1 , name="mice_imp1" )

#**********
# Model 2: Imputation using mice.1chain
imp2 <- miceadds::mice.1chain( nhanes , burnin=10 , iter=20 , Nimp=4 )
# write results
write.mice.imputation(mi.res=imp2 , name="mice_imp2" )

## End(Not run)

Example output

Loading required package: mice
* miceadds 2.5-9 (2017-06-17 14:42:44)

 iter imp variable
  1   1  bmi  hyp  chl
  1   2  bmi  hyp  chl
  1   3  bmi  hyp  chl
  2   1  bmi  hyp  chl
  2   2  bmi  hyp  chl
  2   3  bmi  hyp  chl
  3   1  bmi  hyp  chl
  3   2  bmi  hyp  chl
  3   3  bmi  hyp  chl
  4   1  bmi  hyp  chl
  4   2  bmi  hyp  chl
  4   3  bmi  hyp  chl
  5   1  bmi  hyp  chl
  5   2  bmi  hyp  chl
  5   3  bmi  hyp  chl
2017-06-28 08:20:51 

 /work/tmp/mice_imp1 

Multiply imputed data set
Call:
mice::mice(data = nhanes, m = 3, maxit = 5)
Number of multiple imputations:  3
Missing cells per column:
age bmi hyp chl 
  0   9   8  10 
Imputation methods:
  age   bmi   hyp   chl 
   "" "pmm" "pmm" "pmm" 
VisitSequence:
bmi hyp chl 
  2   3   4 
PredictorMatrix:
    age bmi hyp chl
age   0   0   0   0
bmi   1   0   1   1
hyp   1   1   0   1
chl   1   1   1   0
Random generator seed value:  NA 
NULL


  variable MissProp Rhat.M.imp Rhat.Var.imp
1      bmi       36  1.0548643    0.9854180
2      hyp       32  1.0512677    0.9914977
3      chl       40  0.9011566    1.0711612
  variable MissProp Rhat.M.imp Rhat.Var.imp
1      bmi       36      1.055        0.985
2      hyp       32      1.051        0.991
3      chl       40      0.901        1.071

To cite R in publications use:

  R Core Team (2017). R: A language and environment for statistical
  computing. R Foundation for Statistical Computing, Vienna, Austria.
  URL https://www.R-project.org/.

A BibTeX entry for LaTeX users is

  @Manual{,
    title = {R: A Language and Environment for Statistical Computing},
    author = {{R Core Team}},
    organization = {R Foundation for Statistical Computing},
    address = {Vienna, Austria},
    year = {2017},
    url = {https://www.R-project.org/},
  }

We have invested a lot of time and effort in creating R, please cite it
when using it for data analysis. See also 'citation("pkgname")' for
citing R packages.


To cite mice in publications use:

  Stef van Buuren, Karin Groothuis-Oudshoorn (2011). mice: Multivariate
  Imputation by Chained Equations in R. Journal of Statistical
  Software, 45(3), 1-67. URL http://www.jstatsoft.org/v45/i03/.

A BibTeX entry for LaTeX users is

  @Article{,
    title = {{mice}: Multivariate Imputation by Chained Equations in R},
    author = {Stef {van Buuren} and Karin Groothuis-Oudshoorn},
    journal = {Journal of Statistical Software},
    year = {2011},
    volume = {45},
    number = {3},
    pages = {1--67},
    url = {http://www.jstatsoft.org/v45/i03/},
  }

                                       sysname 
                                       "Linux" 
                                       release 
                          "3.13.0-121-generic" 
                                       version 
"#170-Ubuntu SMP Wed Jun 14 09:04:33 UTC 2017" 
                                      nodename 
                            "ip-172-31-17-161" 
                                       machine 
                                      "x86_64" 
                                         login 
                                     "unknown" 
                                          user 
                                     "unknown" 
                                effective_user 
                                     "unknown" 
sh: 1: cannot create /dev/null: Permission denied
R version 3.4.0 (2017-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)

Matrix products: default
BLAS: /usr/lib/atlas-base/atlas/libblas.so.3.0
LAPACK: /usr/lib/lapack/liblapack.so.3.0

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] miceadds_2.5-9 mice_2.30     

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.11          ape_4.1               mvtnorm_1.0-6        
 [4] lattice_0.20-35       corpcor_1.6.9         zoo_1.8-0            
 [7] gtools_3.5.0          assertthat_0.2.0      psych_1.7.5          
[10] R6_2.2.2              ic.infer_1.1-5        plyr_1.8.4           
[13] MatrixModels_0.4-1    stats4_3.4.0          survey_3.32          
[16] coda_0.19-1           rlang_0.1.1           cubature_1.3-8       
[19] minqa_1.2.4           SparseM_1.77          car_2.1-4            
[22] multiwayvcov_1.2.3    nloptr_1.0.4          kernlab_0.9-25       
[25] rpart_4.1-11          Matrix_1.2-10         WrightMap_1.2.1      
[28] combinat_0.0-8        pbivnorm_0.6.0        lavaan.survey_1.1.3.1
[31] splines_3.4.0         lme4_1.1-13           MCMCglmm_2.24        
[34] foreign_0.8-68        igraph_1.0.1          CDM_5.6-16           
[37] compiler_3.4.0        GPArotation_2014.11-1 mnormt_1.5-5         
[40] mgcv_1.8-17           mitools_2.3           nnet_7.3-12          
[43] mirt_1.24             tibble_1.3.3          tensorA_0.36         
[46] lpSolve_5.6.13        polycor_0.7-9         kappalab_0.4-7       
[49] quadprog_1.5-5        dplyr_0.7.0           MASS_7.3-47          
[52] grid_3.4.0            nlme_3.1-131          magrittr_1.5         
[55] TAM_2.2-49            sm_2.2-5.4            boot_1.3-19          
[58] sandwich_2.3-4        sjlabelled_1.0.0      blme_1.0-4           
[61] tools_3.4.0           glue_1.1.0            purrr_0.2.2.2        
[64] sfsmisc_1.1-1         parallel_3.4.0        sirt_2.0-25          
[67] pbkrtest_0.4-7        survival_2.41-3       grouped_0.6-0        
[70] haven_1.0.0           lavaan_0.5-23.1097    quantreg_5.33        

 1
 2
 3
Data values written to /work/tmp/mice_imp1/mice_imp1__SPSS.txt 
Syntax file written to /work/tmp/mice_imp1/mice_imp1__SPSS.sps 
************ BURNIN PHASE | Iterations 1 - 10 ******************

 iter imp variable
  1   1  bmi  hyp  chl
  2   1  bmi  hyp  chl
  3   1  bmi  hyp  chl
  4   1  bmi  hyp  chl
  5   1  bmi  hyp  chl
  6   1  bmi  hyp  chl
  7   1  bmi  hyp  chl
  8   1  bmi  hyp  chl
  9   1  bmi  hyp  chl
  10   1  bmi  hyp  chl


************ IMPUTATION PHASE | Iterations 11 - 20 ******************

 --- Imputation 1 | Iterations 10 - 12 

 iter imp variable
  1   1  bmi  hyp  chl
  2   1  bmi  hyp  chl

 --- Imputation 2 | Iterations 12 - 15 

 iter imp variable
  1   1  bmi  hyp  chl
  2   1  bmi  hyp  chl
  3   1  bmi  hyp  chl

 --- Imputation 3 | Iterations 15 - 18 

 iter imp variable
  1   1  bmi  hyp  chl
  2   1  bmi  hyp  chl
  3   1  bmi  hyp  chl

 --- Imputation 4 | Iterations 18 - 20 

 iter imp variable
  1   1  bmi  hyp  chl
  2   1  bmi  hyp  chl
2017-06-28 08:20:52 

 /work/tmp/mice_imp2 

Multiply imputed data set
Call:
miceadds::mice.1chain(data = nhanes, burnin = 10, iter = 20, 
    Nimp = 4)
Number of multiple imputations:  4
Missing cells per column:
age bmi hyp chl 
  0   9   8  10 
Imputation methods:
  age   bmi   hyp   chl 
   "" "pmm" "pmm" "pmm" 
VisitSequence:
bmi hyp chl 
  2   3   4 
PredictorMatrix:
    age bmi hyp chl
age   0   0   0   0
bmi   1   0   1   1
hyp   1   1   0   1
chl   1   1   1   0
Random generator seed value:  NA 
NULL



To cite R in publications use:

  R Core Team (2017). R: A language and environment for statistical
  computing. R Foundation for Statistical Computing, Vienna, Austria.
  URL https://www.R-project.org/.

A BibTeX entry for LaTeX users is

  @Manual{,
    title = {R: A Language and Environment for Statistical Computing},
    author = {{R Core Team}},
    organization = {R Foundation for Statistical Computing},
    address = {Vienna, Austria},
    year = {2017},
    url = {https://www.R-project.org/},
  }

We have invested a lot of time and effort in creating R, please cite it
when using it for data analysis. See also 'citation("pkgname")' for
citing R packages.


To cite mice in publications use:

  Stef van Buuren, Karin Groothuis-Oudshoorn (2011). mice: Multivariate
  Imputation by Chained Equations in R. Journal of Statistical
  Software, 45(3), 1-67. URL http://www.jstatsoft.org/v45/i03/.

A BibTeX entry for LaTeX users is

  @Article{,
    title = {{mice}: Multivariate Imputation by Chained Equations in R},
    author = {Stef {van Buuren} and Karin Groothuis-Oudshoorn},
    journal = {Journal of Statistical Software},
    year = {2011},
    volume = {45},
    number = {3},
    pages = {1--67},
    url = {http://www.jstatsoft.org/v45/i03/},
  }

                                       sysname 
                                       "Linux" 
                                       release 
                          "3.13.0-121-generic" 
                                       version 
"#170-Ubuntu SMP Wed Jun 14 09:04:33 UTC 2017" 
                                      nodename 
                            "ip-172-31-17-161" 
                                       machine 
                                      "x86_64" 
                                         login 
                                     "unknown" 
                                          user 
                                     "unknown" 
                                effective_user 
                                     "unknown" 
sh: 1: cannot create /dev/null: Permission denied
R version 3.4.0 (2017-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)

Matrix products: default
BLAS: /usr/lib/atlas-base/atlas/libblas.so.3.0
LAPACK: /usr/lib/lapack/liblapack.so.3.0

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] miceadds_2.5-9 mice_2.30     

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.11          ape_4.1               mvtnorm_1.0-6        
 [4] lattice_0.20-35       corpcor_1.6.9         zoo_1.8-0            
 [7] gtools_3.5.0          assertthat_0.2.0      psych_1.7.5          
[10] R6_2.2.2              ic.infer_1.1-5        plyr_1.8.4           
[13] MatrixModels_0.4-1    stats4_3.4.0          survey_3.32          
[16] coda_0.19-1           rlang_0.1.1           cubature_1.3-8       
[19] minqa_1.2.4           SparseM_1.77          car_2.1-4            
[22] multiwayvcov_1.2.3    nloptr_1.0.4          kernlab_0.9-25       
[25] rpart_4.1-11          Matrix_1.2-10         WrightMap_1.2.1      
[28] combinat_0.0-8        pbivnorm_0.6.0        lavaan.survey_1.1.3.1
[31] splines_3.4.0         lme4_1.1-13           MCMCglmm_2.24        
[34] foreign_0.8-68        igraph_1.0.1          CDM_5.6-16           
[37] compiler_3.4.0        GPArotation_2014.11-1 mnormt_1.5-5         
[40] mgcv_1.8-17           mitools_2.3           nnet_7.3-12          
[43] mirt_1.24             tibble_1.3.3          tensorA_0.36         
[46] lpSolve_5.6.13        polycor_0.7-9         kappalab_0.4-7       
[49] quadprog_1.5-5        dplyr_0.7.0           MASS_7.3-47          
[52] grid_3.4.0            nlme_3.1-131          magrittr_1.5         
[55] TAM_2.2-49            sm_2.2-5.4            boot_1.3-19          
[58] sandwich_2.3-4        sjlabelled_1.0.0      blme_1.0-4           
[61] tools_3.4.0           glue_1.1.0            purrr_0.2.2.2        
[64] sfsmisc_1.1-1         parallel_3.4.0        sirt_2.0-25          
[67] pbkrtest_0.4-7        survival_2.41-3       grouped_0.6-0        
[70] haven_1.0.0           lavaan_0.5-23.1097    quantreg_5.33        

 1
 2
 3
 4
Data values written to /work/tmp/mice_imp2/mice_imp2__SPSS.txt 
Syntax file written to /work/tmp/mice_imp2/mice_imp2__SPSS.sps 

miceadds documentation built on Aug. 25, 2017, 1:03 a.m.