## Not run:
# #############################################################################
# # EXAMPLE 1: nhanes data | combination of correlation coefficients
# #############################################################################
#
# library(mice)
# data(nhanes, package="mice")
# set.seed(9090)
#
# # nhanes data in one chain
# imp.mi <- mice.1chain( nhanes , burnin=5 , iter=20 , Nimp=4 ,
# imputationMethod=rep("norm" , 4 ) )
# # correlation coefficients of variables 4, 2 and 3 (indexed in nhanes data)
# res <- micombine.cor(mi.res=imp.mi, variables = c(4,2,3) )
# ## variable1 variable2 r rse fisher_r fisher_rse fmi t p
# ## 1 chl bmi 0.2458 0.2236 0.2510 0.2540 0.3246 0.9879 0.3232
# ## 2 chl hyp 0.2286 0.2152 0.2327 0.2413 0.2377 0.9643 0.3349
# ## 3 bmi hyp -0.0084 0.2198 -0.0084 0.2351 0.1904 -0.0358 0.9714
# ## lower95 upper95
# ## 1 -0.2421 0.6345
# ## 2 -0.2358 0.6080
# ## 3 -0.4376 0.4239
#
# # extract matrix with correlations and its standard errors
# attr(res, "r_matrix")
# attr(res, "rse_matrix")
#
# # inference for covariance
# res2 <- micombine.cov(mi.res=imp.mi, variables = c(4,2,3) )
#
# # inference can also be conducted for non-imputed data
# res3 <- micombine.cov(mi.res= nhanes , variables = c(4,2,3) )
#
# #############################################################################
# # EXAMPLE 2: nhanes data | comparing different correlation coefficients
# #############################################################################
#
# library(psych)
# library(mitools)
#
# # imputing data
# imp1 <- mice::mice( nhanes , imputationMethod=rep("norm" , 4 ) )
# summary(imp1)
#
# #*** Pearson correlation
# res1 <- micombine.cor(mi.res=imp1, variables = c(4,2) )
#
# #*** Spearman rank correlation
# res2 <- micombine.cor(mi.res=imp1, variables = c(4,2) , method="spearman")
#
# #*** Kendalls tau
# # test of computation of tau for first imputed dataset
# dat1 <- mice::complete(imp1, action=1)
# tau1 <- psych::corr.test(x=dat1[,c(4,2)], method = "kendall")
# tau1$r[1,2] # estimate
# tau1$se # standard error
#
# # results of Kendalls tau for all imputed datasets
# res3 <- with( data=imp1 ,
# expr = psych::corr.test( x = cbind( chl , bmi ) , method="kendall") )
# # extract estimates
# betas <- lapply( res3$analyses , FUN = function(ll){ ll$r[1,2] } )
# # extract variances
# vars <- lapply( res3$analyses , FUN = function(ll){ ll$se^2 } )
# # Rubin inference
# tau_comb <- mitools::MIcombine( betas , vars )
# summary(tau_comb)
#
# #############################################################################
# # EXAMPLE 3: Inference for correlations for nested multiply imputed datasets
# #############################################################################
#
# library(BIFIEsurvey)
# data(data.timss4 , package="BIFIEsurvey" )
# datlist <- data.timss4
#
# # object of class nested.datlist
# datlist <- nested.datlist_create(datlist)
# # inference for correlations
# res2 <- micombine.cor(mi.res= datlist , variables=c("lang", "migrant", "ASMMAT"))
# ## End(Not run)
Run the code above in your browser using DataLab