Skip to contents

In this empirical example, we use data from a study by Elliot and others (2007) on the effects of an intervention on healthy dietary behavior mediated by knowledge of healthy dietary behavior. This data was used as an empirical example in Yuan and MacKinnon (2009) and Wu and Jia (2013).

Data

The data frame elliot2007(), which is included in the manMCMedMiss package, has 354 cases and 3 variables:

  • x - Intervention group membership.
  • m - Knowledge of healthy dietary behavior (knowledge post-intervention minus knowledge pre-intervention).
  • y - Healthy dietary behavior (behavior post-intervention minus behavior pre-intervention).
knitr::kable(head(elliot2007))
x m y
0 1.0 1.666666
0 0.0 4.000000
0 0.0 0.000000
0 -0.5 -0.666667
0 0.5 1.333333
0 1.0 2.333334

Arguments

Variables Values Notes
m 100 Number of imputations.
R 20000 Number of Monte Carlo replications.
B 5000 Number of bootstrap samples.
mplus_bin “/opt/mplusdemo/mpdemo” Path to Mplus binary.

NOTE: If you are using manmcmedmiss-rocker or manmcmedmiss.sif described in the Containers article, set mplus_bin = "mpdemo".

Amputation

Generate sample data with missing values. The missing data mechanism is missing at random (MAR). The proportion of missing cases is 0.30.

set.seed(42)
data_missing <- AmputeData(
  elliot2007,
  mech = "MAR",
  prop = 0.10
)
knitr::kable(head(data_missing, n = 10))
x m y
0 1.000000 1.666666
0 0.000000 4.000000
0 0.000000 0.000000
0 -0.500000 -0.666667
0 0.500000 1.333333
0 1.000000 2.333334
NA 1.166667 3.333333
NA 0.833333 NA
0 1.666667 1.666667
0 -0.333333 1.666666

Imputation

Perform multiple imputations

data_mi <- ImputeData(
  data_missing,
  m = m,
  mplus_bin = mplus_bin
)

Model Fitting

Maximum Likelihood

Parameters of the simple mediation model are estimated using full-information maximum likelihood to handle missing data.

fit_ml <- FitModelML(
  data_missing,
  mplus_bin = mplus_bin
)
fit_ml
#> $fit
#>  free_parameters h0_loglikelihood h1_loglikelihood              aic 
#>     9.000000e+00    -1.225911e+03    -1.225911e+03     2.469821e+03 
#>              bic            sabic            chisq         chisq_df 
#>     2.504645e+03     2.476093e+03     8.237393e-06     0.000000e+00 
#>          chisq_p              cfi              tli            rmsea 
#>     0.000000e+00     9.999994e-01     1.000000e+00     0.000000e+00 
#>        rmsea_low         rmsea_up          rmsea_p             srmr 
#>     0.000000e+00     0.000000e+00     0.000000e+00     5.887405e-05 
#> condition_number 
#>     1.837067e-02 
#> 
#> $coef
#>         m~1         y~1         x~1         m~x         y~m         y~x 
#> 0.006934506 0.336487350 0.411909970 0.369397850 0.152114330 0.151127860 
#>        m~~m        y~~y        x~~x 
#> 1.211989500 1.149110200 0.241468090 
#> 
#> $vcov
#>                m~1           y~1           x~1           m~x           y~m
#> m~1   6.200529e-03  4.010312e-05 -7.774377e-05 -6.518637e-03  6.355296e-05
#> y~1   4.010312e-05  6.012550e-03 -7.506271e-05 -7.453915e-05  1.085284e-04
#> x~1  -7.774377e-05 -7.506271e-05  7.515655e-04  1.438111e-04 -9.078051e-06
#> m~x  -6.518637e-03 -7.453915e-05  1.438111e-04  1.649430e-02  3.655520e-05
#> y~m   6.355296e-05  1.085284e-04 -9.078051e-06  3.655520e-05  3.115320e-03
#> y~x  -1.365620e-04 -6.342203e-03  1.720138e-04  8.861812e-05 -1.121932e-03
#> m~~m  1.191213e-04  1.111450e-05 -2.519574e-05 -2.088454e-04 -2.211516e-06
#> y~~y -9.056253e-06  4.214630e-05 -1.378773e-05 -3.796332e-05 -3.804997e-05
#> x~~x -5.274115e-06 -4.978534e-06  7.624901e-06  6.937207e-06 -1.102431e-06
#>                y~x          m~~m          y~~y          x~~x
#> m~1  -1.365620e-04  1.191213e-04 -9.056253e-06 -5.274115e-06
#> y~1  -6.342203e-03  1.111450e-05  4.214630e-05 -4.978534e-06
#> x~1   1.720138e-04 -2.519574e-05 -1.378773e-05  7.624901e-06
#> m~x   8.861812e-05 -2.088454e-04 -3.796332e-05  6.937207e-06
#> y~m  -1.121932e-03 -2.211516e-06 -3.804997e-05 -1.102431e-06
#> y~x   1.622654e-02 -3.583622e-05 -7.859534e-05  1.124238e-05
#> m~~m -3.583622e-05  8.808493e-03 -4.183286e-06 -4.881001e-06
#> y~~y -7.859534e-05 -4.183286e-06  8.050239e-03 -1.407881e-06
#> x~~x  1.124238e-05 -4.881001e-06 -1.407881e-06  3.625790e-04
#> 
#> $output
#>   [1] "Mplus VERSION 8.8 DEMO (Linux)"                                                                     
#>   [2] "MUTHEN & MUTHEN"                                                                                    
#>   [3] "09/18/2023   9:24 AM"                                                                               
#>   [4] ""                                                                                                   
#>   [5] "INPUT INSTRUCTIONS"                                                                                 
#>   [6] ""                                                                                                   
#>   [7] "  DATA:"                                                                                            
#>   [8] "  FILE = file8ff46918c33;"                                                                          
#>   [9] "  VARIABLE:"                                                                                        
#>  [10] "  NAMES = X M Y;"                                                                                   
#>  [11] "  USEVARIABLES = X M Y;"                                                                            
#>  [12] "  MISSING = ALL (-999);"                                                                            
#>  [13] "  ANALYSIS:"                                                                                        
#>  [14] "  TYPE = GENERAL;"                                                                                  
#>  [15] "  ESTIMATOR = ML;"                                                                                  
#>  [16] "  MODEL:"                                                                                           
#>  [17] "  Y ON X;"                                                                                          
#>  [18] "  Y ON M (B);"                                                                                      
#>  [19] "  M ON X (A);"                                                                                      
#>  [20] "  X WITH X;"                                                                                        
#>  [21] "  SAVEDATA:"                                                                                        
#>  [22] "  RESULTS ARE file8ff6dd44a44;"                                                                     
#>  [23] "  TECH3 IS file8ff10ac78d0;"                                                                        
#>  [24] ""                                                                                                   
#>  [25] ""                                                                                                   
#>  [26] ""                                                                                                   
#>  [27] ""                                                                                                   
#>  [28] "INPUT READING TERMINATED NORMALLY"                                                                  
#>  [29] ""                                                                                                   
#>  [30] ""                                                                                                   
#>  [31] ""                                                                                                   
#>  [32] ""                                                                                                   
#>  [33] "SUMMARY OF ANALYSIS"                                                                                
#>  [34] ""                                                                                                   
#>  [35] "Number of groups                                                 1"                                 
#>  [36] "Number of observations                                         354"                                 
#>  [37] ""                                                                                                   
#>  [38] "Number of dependent variables                                    2"                                 
#>  [39] "Number of independent variables                                  1"                                 
#>  [40] "Number of continuous latent variables                            0"                                 
#>  [41] ""                                                                                                   
#>  [42] "Observed dependent variables"                                                                       
#>  [43] ""                                                                                                   
#>  [44] "  Continuous"                                                                                       
#>  [45] "   M           Y"                                                                                   
#>  [46] ""                                                                                                   
#>  [47] "Observed independent variables"                                                                     
#>  [48] "   X"                                                                                               
#>  [49] ""                                                                                                   
#>  [50] ""                                                                                                   
#>  [51] "Estimator                                                       ML"                                 
#>  [52] "Information matrix                                        OBSERVED"                                 
#>  [53] "Maximum number of iterations                                  1000"                                 
#>  [54] "Convergence criterion                                    0.500D-04"                                 
#>  [55] "Maximum number of steepest descent iterations                   20"                                 
#>  [56] "Maximum number of iterations for H1                           2000"                                 
#>  [57] "Convergence criterion for H1                             0.100D-03"                                 
#>  [58] ""                                                                                                   
#>  [59] "Input data file(s)"                                                                                 
#>  [60] "  file8ff46918c33"                                                                                  
#>  [61] ""                                                                                                   
#>  [62] "Input data format  FREE"                                                                            
#>  [63] ""                                                                                                   
#>  [64] ""                                                                                                   
#>  [65] "SUMMARY OF DATA"                                                                                    
#>  [66] ""                                                                                                   
#>  [67] "     Number of missing data patterns             7"                                                 
#>  [68] ""                                                                                                   
#>  [69] ""                                                                                                   
#>  [70] "COVARIANCE COVERAGE OF DATA"                                                                        
#>  [71] ""                                                                                                   
#>  [72] "Minimum covariance coverage value   0.100"                                                          
#>  [73] ""                                                                                                   
#>  [74] ""                                                                                                   
#>  [75] "     PROPORTION OF DATA PRESENT"                                                                    
#>  [76] ""                                                                                                   
#>  [77] ""                                                                                                   
#>  [78] "           Covariance Coverage"                                                                     
#>  [79] "              M             Y             X"                                                        
#>  [80] "              ________      ________      ________"                                                 
#>  [81] " M              0.946"                                                                              
#>  [82] " Y              0.890         0.929"                                                                
#>  [83] " X              0.879         0.876         0.910"                                                  
#>  [84] ""                                                                                                   
#>  [85] ""                                                                                                   
#>  [86] ""                                                                                                   
#>  [87] "UNIVARIATE SAMPLE STATISTICS"                                                                       
#>  [88] ""                                                                                                   
#>  [89] ""                                                                                                   
#>  [90] "     UNIVARIATE HIGHER-ORDER MOMENT DESCRIPTIVE STATISTICS"                                         
#>  [91] ""                                                                                                   
#>  [92] "         Variable/         Mean/     Skewness/   Minimum/ % with                Percentiles"        
#>  [93] "        Sample Size      Variance    Kurtosis    Maximum  Min/Max      20%/60%    40%/80%    Median"
#>  [94] ""                                                                                                   
#>  [95] "     M                     0.148      -0.290      -5.000    0.30%      -0.667      0.000      0.000"
#>  [96] "             335.000       1.244       2.398       4.000    0.30%       0.333      1.000"           
#>  [97] "     Y                     0.412       0.246      -3.000    0.30%      -0.333      0.000      0.333"
#>  [98] "             329.000       1.186       0.597       4.000    0.61%       0.667      1.333"           
#>  [99] "     X                     0.407       0.379       0.000   59.32%       0.000      0.000      0.000"
#> [100] "             322.000       0.241      -1.856       1.000   40.68%       1.000      1.000"           
#> [101] ""                                                                                                   
#> [102] ""                                                                                                   
#> [103] "THE MODEL ESTIMATION TERMINATED NORMALLY"                                                           
#> [104] ""                                                                                                   
#> [105] ""                                                                                                   
#> [106] ""                                                                                                   
#> [107] "MODEL FIT INFORMATION"                                                                              
#> [108] ""                                                                                                   
#> [109] "Number of Free Parameters                        9"                                                 
#> [110] ""                                                                                                   
#> [111] "Loglikelihood"                                                                                      
#> [112] ""                                                                                                   
#> [113] "          H0 Value                       -1225.911"                                                 
#> [114] "          H1 Value                       -1225.911"                                                 
#> [115] ""                                                                                                   
#> [116] "Information Criteria"                                                                               
#> [117] ""                                                                                                   
#> [118] "          Akaike (AIC)                    2469.821"                                                 
#> [119] "          Bayesian (BIC)                  2504.645"                                                 
#> [120] "          Sample-Size Adjusted BIC        2476.093"                                                 
#> [121] "            (n* = (n + 2) / 24)"                                                                    
#> [122] ""                                                                                                   
#> [123] "Chi-Square Test of Model Fit"                                                                       
#> [124] ""                                                                                                   
#> [125] "          Value                              0.000"                                                 
#> [126] "          Degrees of Freedom                     0"                                                 
#> [127] "          P-Value                           0.0000"                                                 
#> [128] ""                                                                                                   
#> [129] "RMSEA (Root Mean Square Error Of Approximation)"                                                    
#> [130] ""                                                                                                   
#> [131] "          Estimate                           0.000"                                                 
#> [132] "          90 Percent C.I.                    0.000  0.000"                                          
#> [133] "          Probability RMSEA <= .05           0.000"                                                 
#> [134] ""                                                                                                   
#> [135] "CFI/TLI"                                                                                            
#> [136] ""                                                                                                   
#> [137] "          CFI                                1.000"                                                 
#> [138] "          TLI                                1.000"                                                 
#> [139] ""                                                                                                   
#> [140] "Chi-Square Test of Model Fit for the Baseline Model"                                                
#> [141] ""                                                                                                   
#> [142] "          Value                             17.825"                                                 
#> [143] "          Degrees of Freedom                     3"                                                 
#> [144] "          P-Value                           0.0005"                                                 
#> [145] ""                                                                                                   
#> [146] "SRMR (Standardized Root Mean Square Residual)"                                                      
#> [147] ""                                                                                                   
#> [148] "          Value                              0.000"                                                 
#> [149] ""                                                                                                   
#> [150] ""                                                                                                   
#> [151] ""                                                                                                   
#> [152] "MODEL RESULTS"                                                                                      
#> [153] ""                                                                                                   
#> [154] "                                                    Two-Tailed"                                     
#> [155] "                    Estimate       S.E.  Est./S.E.    P-Value"                                      
#> [156] ""                                                                                                   
#> [157] " Y        ON"                                                                                       
#> [158] "    X                  0.151      0.127      1.186      0.235"                                      
#> [159] "    M                  0.152      0.056      2.725      0.006"                                      
#> [160] ""                                                                                                   
#> [161] " M        ON"                                                                                       
#> [162] "    X                  0.369      0.128      2.876      0.004"                                      
#> [163] ""                                                                                                   
#> [164] " Means"                                                                                             
#> [165] "    X                  0.412      0.027     15.025      0.000"                                      
#> [166] ""                                                                                                   
#> [167] " Intercepts"                                                                                        
#> [168] "    M                  0.007      0.079      0.088      0.930"                                      
#> [169] "    Y                  0.336      0.078      4.339      0.000"                                      
#> [170] ""                                                                                                   
#> [171] " Variances"                                                                                         
#> [172] "    X                  0.241      0.019     12.681      0.000"                                      
#> [173] ""                                                                                                   
#> [174] " Residual Variances"                                                                                
#> [175] "    M                  1.212      0.094     12.914      0.000"                                      
#> [176] "    Y                  1.149      0.090     12.807      0.000"                                      
#> [177] ""                                                                                                   
#> [178] ""                                                                                                   
#> [179] "QUALITY OF NUMERICAL RESULTS"                                                                       
#> [180] ""                                                                                                   
#> [181] "     Condition Number for the Information Matrix              0.184E-01"                            
#> [182] "       (ratio of smallest to largest eigenvalue)"                                                   
#> [183] ""                                                                                                   
#> [184] ""                                                                                                   
#> [185] "RESULTS SAVING INFORMATION"                                                                         
#> [186] ""                                                                                                   
#> [187] "  Order of data"                                                                                    
#> [188] ""                                                                                                   
#> [189] "    Parameter estimates"                                                                            
#> [190] "     (saved in order shown in Technical 1 output)"                                                  
#> [191] "    Standard errors"                                                                                
#> [192] "     (saved in order shown in Technical 1 output)"                                                  
#> [193] "    Number of Free Parameters"                                                                      
#> [194] "    H0 Loglikelihood"                                                                               
#> [195] "    H1 Loglikelihood"                                                                               
#> [196] "    Akaike (AIC)"                                                                                   
#> [197] "    Bayesian (BIC)"                                                                                 
#> [198] "    Sample-Size Adjusted BIC"                                                                       
#> [199] "    Chi-square : Value"                                                                             
#> [200] "    Chi-square : Degrees of Freedom"                                                                
#> [201] "    Chi-square : P-Value"                                                                           
#> [202] "    CFI"                                                                                            
#> [203] "    TLI"                                                                                            
#> [204] "    RMSEA : Estimate"                                                                               
#> [205] "    RMSEA : Low CI"                                                                                 
#> [206] "    RMSEA : High CI"                                                                                
#> [207] "    RMSEA : Probability"                                                                            
#> [208] "    SRMR"                                                                                           
#> [209] "    Condition Number"                                                                               
#> [210] ""                                                                                                   
#> [211] "  Save file"                                                                                        
#> [212] "    file8ff6dd44a44"                                                                                
#> [213] ""                                                                                                   
#> [214] "  Save file format           Free"                                                                  
#> [215] ""                                                                                                   
#> [216] ""                                                                                                   
#> [217] "SAVEDATA INFORMATION"                                                                               
#> [218] ""                                                                                                   
#> [219] ""                                                                                                   
#> [220] "  Estimated Covariance Matrix for the Parameter Estimates"                                          
#> [221] ""                                                                                                   
#> [222] "  Save file"                                                                                        
#> [223] "    file8ff10ac78d0"                                                                                
#> [224] "  Save format      Free"                                                                            
#> [225] ""                                                                                                   
#> [226] "     Beginning Time:  09:24:24"                                                                     
#> [227] "        Ending Time:  09:24:24"                                                                     
#> [228] "       Elapsed Time:  00:00:00"                                                                     
#> [229] ""                                                                                                   
#> [230] ""                                                                                                   
#> [231] "Mplus VERSION 8.8 DEMO (Linux) has the following limitations:"                                      
#> [232] "  Maximum number of dependent variables: 6"                                                         
#> [233] "  Maximum number of independent variables: 2"                                                       
#> [234] "  Maximum number of between variables: 2"                                                           
#> [235] "  Maximum number of continuous latent variables in time series analysis: 2"                         
#> [236] ""                                                                                                   
#> [237] ""                                                                                                   
#> [238] "MUTHEN & MUTHEN"                                                                                    
#> [239] "3463 Stoner Ave."                                                                                   
#> [240] "Los Angeles, CA  90066"                                                                             
#> [241] ""                                                                                                   
#> [242] "Tel: (310) 391-9971"                                                                                
#> [243] "Fax: (310) 391-8971"                                                                                
#> [244] "Web: www.StatModel.com"                                                                             
#> [245] "Support: Support@StatModel.com"                                                                     
#> [246] ""                                                                                                   
#> [247] "Copyright (c) 1998-2022 Muthen & Muthen"

Multiple Imputation

Parameters of the simple mediation model are estimated using normal theory maximum likelihood for each of the imputed data sets. The parameter estimates and their sampling covariance matrix are pooled.

fit_mi <- FitModelMI(
  data_mi,
  mplus_bin = mplus_bin
)
fit_mi
#> $coef
#>         m~1         y~1         x~1         m~x         y~m         y~x 
#> 0.005019703 0.332799419 0.412956299 0.377266653 0.150139986 0.153136568 
#>        m~~m        y~~y        x~~x 
#> 1.211805873 1.146497984 0.242038727 
#> 
#> $vcov
#>                m~1           y~1           x~1           m~x           y~m
#> m~1   6.281569e-03  4.792023e-05 -9.324596e-05 -6.536580e-03  9.710301e-05
#> y~1   4.792023e-05  6.055600e-03 -6.372941e-05 -3.871823e-05  4.660348e-05
#> x~1  -9.324596e-05 -6.372941e-05  7.506654e-04  1.650903e-04 -8.964939e-06
#> m~x  -6.536580e-03 -3.871823e-05  1.650903e-04  1.636016e-02  2.054703e-04
#> y~m   9.710301e-05  4.660348e-05 -8.964939e-06  2.054703e-04  3.194082e-03
#> y~x  -6.691576e-05 -6.394353e-03  1.484601e-04  3.590605e-06 -1.068989e-03
#> m~~m  1.478045e-04  6.851728e-06 -3.582386e-05 -1.735251e-04  1.950598e-05
#> y~~y -3.229702e-05  5.311397e-05 -3.383887e-06  6.281239e-05 -1.973814e-05
#> x~~x  2.838276e-06 -1.069720e-05  1.271110e-05  5.582597e-06  2.221033e-05
#>                y~x          m~~m          y~~y          x~~x
#> m~1  -6.691576e-05  1.478045e-04 -3.229702e-05  2.838276e-06
#> y~1  -6.394353e-03  6.851728e-06  5.311397e-05 -1.069720e-05
#> x~1   1.484601e-04 -3.582386e-05 -3.383887e-06  1.271110e-05
#> m~x   3.590605e-06 -1.735251e-04  6.281239e-05  5.582597e-06
#> y~m  -1.068989e-03  1.950598e-05 -1.973814e-05  2.221033e-05
#> y~x   1.623913e-02  9.434976e-05 -9.770793e-05  1.040343e-05
#> m~~m  9.434976e-05  8.866444e-03  2.301444e-05 -4.864670e-06
#> y~~y -9.770793e-05  2.301444e-05  7.891514e-03 -3.294018e-05
#> x~~x  1.040343e-05 -4.864670e-06 -3.294018e-05  3.692912e-04
#> 
#> $vcov_tilde
#>                m~1           y~1           x~1           m~x           y~m
#> m~1   6.506328e-03  2.295136e-20  3.436532e-21 -6.513577e-03 -6.495798e-21
#> y~1   2.295136e-20  6.157602e-03 -3.839789e-21 -3.685758e-20 -1.408258e-05
#> x~1   3.436532e-21 -3.839789e-21  7.621849e-04 -1.200686e-20 -4.103301e-22
#> m~x  -6.513577e-03 -3.685758e-20 -1.200686e-20  1.577610e-02  1.893660e-20
#> y~m  -6.495798e-21 -1.408258e-05 -4.103301e-22  1.893660e-20  2.980379e-03
#> y~x  -3.090516e-20 -6.160213e-03  6.016538e-21  6.635324e-20 -1.125836e-03
#> m~~m  1.131546e-06 -4.854797e-21  1.522422e-24 -2.193906e-06  2.148737e-20
#> y~~y -1.025535e-21  3.430788e-07 -3.969870e-25  2.327993e-21  4.900495e-08
#> x~~x  7.277823e-21  1.524870e-21  1.754247e-19 -1.740443e-20  6.227598e-22
#>                y~x          m~~m          y~~y          x~~x
#> m~1  -3.090516e-20  1.131546e-06 -1.025535e-21  7.277823e-21
#> y~1  -6.160213e-03 -4.854797e-21  3.430788e-07  1.524870e-21
#> x~1   6.016538e-21  1.522422e-24 -3.969870e-25  1.754247e-19
#> m~x   6.635324e-20 -2.193906e-06  2.327993e-21 -1.740443e-20
#> y~m  -1.125836e-03  2.148737e-20  4.900495e-08  6.227598e-22
#> y~x   1.535902e-02  2.688057e-21 -6.866015e-07 -3.851020e-21
#> m~~m  2.688057e-21  9.252007e-03 -2.232232e-21 -1.277703e-22
#> y~~y -6.866015e-07 -2.232232e-21  8.281364e-03  1.063728e-23
#> x~~x -3.851020e-21 -1.277703e-22  1.063728e-23  3.691856e-04
#> 
#> $vcov_between
#>                [,1]          [,2]          [,3]          [,4]          [,5]
#>  [1,]  4.405999e-04  4.744578e-05 -9.232273e-05 -6.866482e-04  9.614160e-05
#>  [2,]  4.744578e-05  5.265992e-04 -6.309842e-05 -3.833489e-05  5.864989e-05
#>  [3,] -9.232273e-05 -6.309842e-05  6.627736e-05  1.634557e-04 -8.876177e-06
#>  [4,] -6.866482e-04 -3.833489e-05  1.634557e-04  2.186203e-03  2.034359e-04
#>  [5,]  9.614160e-05  5.864989e-05 -8.876177e-06  2.034359e-04  5.153510e-04
#>  [6,] -6.625323e-05 -8.596794e-04  1.469902e-04  3.555055e-06 -5.846278e-05
#>  [7,]  1.453361e-04  6.783889e-06 -3.546917e-05 -1.698585e-04  1.931285e-05
#>  [8,] -3.197724e-05  5.228337e-05 -3.350383e-06  6.219048e-05 -1.958624e-05
#>  [9,]  2.810174e-06 -1.059128e-05  1.258525e-05  5.527323e-06  2.199042e-05
#>                [,6]          [,7]          [,8]          [,9]
#>  [1,] -6.625323e-05  1.453361e-04 -3.197724e-05  2.810174e-06
#>  [2,] -8.596794e-04  6.783889e-06  5.228337e-05 -1.059128e-05
#>  [3,]  1.469902e-04 -3.546917e-05 -3.350383e-06  1.258525e-05
#>  [4,]  3.555055e-06 -1.698585e-04  6.219048e-05  5.527323e-06
#>  [5,] -5.846278e-05  1.931285e-05 -1.958624e-05  2.199042e-05
#>  [6,]  2.436800e-03  9.341561e-05 -9.613070e-05  1.030043e-05
#>  [7,]  9.341561e-05  5.612308e-04  2.278657e-05 -4.816505e-06
#>  [8,] -9.613070e-05  2.278657e-05  4.580570e-04 -3.261404e-05
#>  [9,]  1.030043e-05 -4.816505e-06 -3.261404e-05  3.773239e-05
#> 
#> $vcov_within
#>                m~1           y~1           x~1           m~x           y~m
#> m~1   5.836563e-03  2.058873e-20  3.082773e-21 -5.843066e-03 -5.827117e-21
#> y~1   2.058873e-20  5.523735e-03 -3.444519e-21 -3.306344e-20 -1.263291e-05
#> x~1   3.082773e-21 -3.444519e-21  6.837252e-04 -1.077087e-20 -3.680905e-22
#> m~x  -5.843066e-03 -3.306344e-20 -1.077087e-20  1.415210e-02  1.698725e-20
#> y~m  -5.827117e-21 -1.263291e-05 -3.680905e-22  1.698725e-20  2.673577e-03
#> y~x  -2.772376e-20 -5.526077e-03  5.397193e-21  5.952281e-20 -1.009942e-03
#> m~~m  1.015064e-06 -4.355042e-21  1.365703e-24 -1.968064e-06  1.927545e-20
#> y~~y -9.199656e-22  3.077621e-07 -3.561210e-25  2.088349e-21  4.396036e-08
#> x~~x  6.528640e-21  1.367899e-21  1.573664e-19 -1.561281e-20  5.586526e-22
#>                y~x          m~~m          y~~y          x~~x
#> m~1  -2.772376e-20  1.015064e-06 -9.199656e-22  6.528640e-21
#> y~1  -5.526077e-03 -4.355042e-21  3.077621e-07  1.367899e-21
#> x~1   5.397193e-21  1.365703e-24 -3.561210e-25  1.573664e-19
#> m~x   5.952281e-20 -1.968064e-06  2.088349e-21 -1.561281e-20
#> y~m  -1.009942e-03  1.927545e-20  4.396036e-08  5.586526e-22
#> y~x   1.377796e-02  2.411347e-21 -6.159224e-07 -3.454594e-21
#> m~~m  2.411347e-21  8.299601e-03 -2.002445e-21 -1.146176e-22
#> y~~y -6.159224e-07 -2.002445e-21  7.428876e-03  9.542269e-24
#> x~~x -3.454594e-21 -1.146176e-22  9.542269e-24  3.311815e-04
#> 
#> $ariv
#> [1] 0.1147533
#> 
#> $m
#> [1] 100
#> 
#> $k
#> [1] 9
#> 
#> $nu1
#> [1] 9
#> 
#> $nu2
#> [1] 83372.16
#> 
#> $d1
#> [1] 86.11739

Monte Carlo Method

Maximum Likelihood

mc_ml <- MCML(
  fit_ml,
  R = R
)
mc_ml
#>         0.05%          0.5%          2.5%         97.5%         99.5% 
#> -0.0140360145  0.0001377727  0.0094455357  0.1233982450  0.1509750184 
#>        99.95% 
#>  0.1878755830

Multiple Imputation

The two versions are based on the pooled covariance matrix used. vcov uses the total covariance matrix \(\mathbf{V}_{T}\) while vcov_tilde uses the adjusted total covariance matrix \(\tilde{\mathbf{V}}_{T}\).

mc_mi <- MCMI(
  fit_mi,
  R = R
)
mc_mi
#>                   0.05%         0.5%        2.5%     97.5%     99.5%    99.95%
#> vcov       -0.014975761 -0.001060201 0.008691238 0.1244539 0.1533265 0.2002091
#> vcov_tilde -0.009596199  0.001044739 0.010304272 0.1212996 0.1455524 0.1753921

Nonparametric Bootstrapping

Maximum Likelihood Nested within Nonparametric Bootstrap (NB(ML))

nb_ml <- NBML(
  data_missing,
  B = B,
  mplus_bin = mplus_bin
)
nb_ml
#>    Lower .5% Lower 2.5% Lower 5% Estimate Upper 5% Upper 2.5% Upper .5%
#> bc     0.002      0.012    0.018    0.056    0.127      0.142     0.171
#> pc    -0.001      0.008    0.013    0.056    0.114      0.129     0.160

Multiple Imputation

Multiple Imputation Nested Within Nonparametric Bootstrap (NB(MI))

nb_mi <- NBMI(
  data_missing,
  data_mi,
  B = B,
  m = m,
  mplus_bin = mplus_bin
)
nb_mi
#>           0.05%         0.5%        2.5%     97.5%     99.5%    99.95%
#> bc -0.006549636  0.002779928 0.012916304 0.1429212 0.1703444 0.2140131
#> pc -0.010102987 -0.001063635 0.007508727 0.1272201 0.1598429 0.1940216

Nonparametric Bootstrap Nested Within Multiple Imputation (MI(NB))

mi_nb <- MINB(
  data_mi,
  B = B
)
mi_nb
#>           0.05%          0.5%      2.5%     97.5%     99.5%    99.95%
#> bc -0.009698788  0.0026598776 0.0123565 0.1410420 0.1716812 0.2120889
#> pc -0.015155326 -0.0006408286 0.0085043 0.1298082 0.1603919 0.1994659

Joint Significance Test

The JointSigML() and JointSigMI() functions return 1 for a significant result and 0 otherwise. Note that the output vector’s name corresponds to the alpha level. The default value of alpha is alpha = c(0.05, 0.01, 0.001).

Maximum Likelihood

joint_ml <- JointSigML(
  fit_ml
)
joint_ml
#>  0.05  0.01 0.001 
#>     1     1     0

Multiple Imputation

The two versions are based on the two types of pooled covariance matrices \(\mathbf{V}_{T}\) and \(\tilde{\mathbf{V}}_{T}\).

joint_mi <- JointSigMI(
  fit_mi
)
joint_mi
#>            0.05 0.01 0.001
#> vcov          1    1     0
#> vcov_tilde    1    1     0

Results

Here is a summary of the \(95\%\) confidence intervals.

ci <- rbind(
  mc_ml[c(3, 4)],
  mc_mi[, c(3, 4)],
  nb_ml[, c(2, 6)],
  nb_mi[, c(3, 4)],
  mi_nb[, c(3, 4)]
)
rownames(ci) <- c(
  "MC.FIML",
  "MC.MI",
  "MC.MI.ADJ",
  "NBBC(FIML)",
  "NBPC(FIML)",
  "NBBC(MI)",
  "NBPC(MI)",
  "MI(NBBC)",
  "MI(NBPC)"
)
knitr::kable(ci)
2.5% 97.5%
MC.FIML 0.0094455 0.1233982
MC.MI 0.0086912 0.1244539
MC.MI.ADJ 0.0103043 0.1212996
NBBC(FIML) 0.0120000 0.1420000
NBPC(FIML) 0.0080000 0.1290000
NBBC(MI) 0.0129163 0.1429212
NBPC(MI) 0.0075087 0.1272201
MI(NBBC) 0.0123565 0.1410420
MI(NBPC) 0.0085043 0.1298082

References

Elliot, D. L., Goldberg, L., Kuehl, K. S., Moe, E. L., Breger, R. K., & Pickering, M. A. (2007). The PHLAME (Promoting Healthy Lifestyles: Alternative Models’ Effects) firefighter study: Outcomes of two models of behavior change. Journal of occupational and environmental medicine, 49(2), 204–213. http://doi.org/10.1097/JOM.0b013e3180329a8d

Wu, W., & Jia, F. (2013). A new procedure to test mediation with missing data through nonparametric bootstrapping and multiple imputation, Multivariate Behavioral Research, 48(5), 663-691. http://doi.org/10.1080/00273171.2013.816235

Yuan, Y., & MacKinnon, D. P. (2009). Bayesian mediation analysis. Psychological methods, 14(4), 301–322. http://doi.org/10.1037/a0016972