Examples of combining PROC CAUSALMED results in PROC MIANALYZE


View the complete data and code for this example at the end Full Code section.

 

The following note demonstrates how results of the analyses from the CAUSALMED procedure of data imputed by the MI procedure can be combined using the MIANALYZE procedure. The data used are described in the Getting Started example in the CAUSALMED documentation and are further analyzed in the example titled "Mediation Analysis with Interaction Effects and Four-Way Decomposition." Missing values have been added to the data so that imputation can be performed.

To impute the missing values in the response variable (CogPerform) and the mediator variable (Motivation), the MCMC (default) method in the MI procedure is used in the statements below. The default 25 imputations are created and saved in the data set Cognitive_Imp.

     proc mi data=cognitive out=Cognitive_Imp seed=100;
       var cogperform encourage motivation famsize socstatus;
       run;

These statements fit a causal mediation model to each of the 25 imputed data sets. For demonstration purposes, the ALL option is used in CAUSALMED to generate all the tables that can be combined in MIANALYZE. The ODS OUTPUT statement creates data sets from each of the tables to be combined.

     proc causalmed data=Cognitive_imp all;
        by _imputation_;
        model    CogPerform = Encourage|Motivation;
        mediator Motivation = Encourage;
        covar    FamSize SocStatus;
        ods output OutcomeEstimates=Outcome_Est MediatorEstimates=Med_Est
                   PercentDecomp=pctdecomp EffectDecomp=effdecomp EffectSummary=effsum;
        run;

Combining the Outcome and Mediator Estimates

The estimates from the outcome model (OutcomeEstimates table) and the mediator model (MediatorEstimates table) are combined using the following MIANALYZE steps. The EDF= option value is based on the complete data degrees of freedom in order to correctly compute the p-values.

     proc mianalyze parms=outcome_est edf=290;
        modeleffects intercept FamSize SocStatus Encourage Motivation Encourage*Motivation;
        title 'Combined Estimates for the Outcome Model';
        run;
     proc mianalyze parms=Med_est edf=290;
        modeleffects intercept FamSize SocStatus Encourage;
        title 'Combined Estimates for the Mediator Model';
        run;

The results for both models are shown below.

Combined Estimates for the Outcome Model
 
The MIANALYZE Procedure
 
Parameter Estimates (25 Imputations)
ParameterEstimateStd Error95% Confidence LimitsDFMinimumMaximumTheta0t for H0:
Parameter=Theta0
Pr > |t|
intercept-93.5981383.265181-100.026-87.1706278.56-94.389804-92.5571560-28.67<.0001
FamSize-0.0237520.013822-0.0510.0035240.7-0.032914-0.0158250-1.720.0870
SocStatus0.0108100.019419-0.0270.0491233.79-0.0012170.02374300.560.5783
Encourage1.0048420.1074270.7931.2163284.470.9801561.02228009.35<.0001
Motivation1.0476680.0949990.8611.2347272.931.0190401.083973011.03<.0001
Encourage*Motivation0.0823280.0024030.0780.0871280.710.0817120.083036034.26<.0001
 
Combined Estimates for the Mediator Model
 
The MIANALYZE Procedure
 
Parameter Estimates (25 Imputations)
ParameterEstimateStd Error95% Confidence LimitsDFMinimumMaximumTheta0t for H0:
Parameter=Theta0
Pr > |t|
intercept11.3177340.8437209.6570912.97838287.8611.28874711.357641013.41<.0001
FamSize-0.1106110.012978-0.13616-0.08507287.92-0.111345-0.1102990-8.52<.0001
SocStatus0.1568430.0180940.121230.19246287.740.1560650.15815508.67<.0001
Encourage0.6868740.0361400.615740.75801287.820.6847600.688236019.01<.0001

Combining the Effect Summary Table

CAUSALMED also produces a summary of effects table (EffectSummary) that can be combined to provide a single set of estimates using MIANALYZE. However, because the estimates to be combined are not model parameters, the DATA= option must be used rather than the PARMS= option. Because the estimates are input using the DATA= option, the MODELEFFECTS and STDERR statements must be used to identify the variables that contain the point estimates and standard errors, respectively. It is also necessary to sort the table data by the effect names before the imputation number so that MIANALYZE can be run for each effect using the BY statement.

     proc sort data=effsum;
        by effect _imputation_;
        run;
     proc mianalyze data=effsum edf=290;
        by effect;
        modeleffects estimate;
        stderr stderr;
        title 'Summary of Causal Effects';
        run;

The combined estimate for the Total Effect is shown below.

Summary of Causal Effects
 
The MIANALYZE Procedure
 
Parameter Estimates (25 Imputations)
ParameterEstimateStd Error95% Confidence LimitsDFMinimumMaximumTheta0t for H0:
Parameter=Theta0
Pr > |t|
estimate6.8378900.1445896.5532947.122486285.616.8160456.860487047.29<.0001

Combining the Decomposition Effects and Percentages

The ALL option in the CAUSALMED statement also invokes the DECOMP option to provide tables of decomposition effects (EffectDecomp) and percentages (PercentDecomp). MIANALYZE can be used to combine these estimates. As above, it is necessary to first sort the table data. For these tables, the data must be sorted by both the decomposition (DECOMP) and the effect names (EFFECT) before the imputation number so that MIANALYZE can be run using the appropriate BY statement.

     proc sort data=effdecomp;
       by decomp effect _imputation_;
       run;
     proc mianalyze data=effdecomp edf=290;
       by decomp effect;
       modeleffects estimate;
       stderr stderr;
       title 'Decompositions of the Total Effect';
       run;
       
     proc sort data=pctdecomp;
       by decomp effect _imputation_;
       run;
     proc mianalyze data=pctdecomp edf=290;
       by decomp effect;
       modeleffects estimate;
       stderr stderr;
       title 'Percentage Decompositions of the Total Effect';
       run;

The decompositions of the CDE are shown below.

Decompositions of the Total Effect
 
The MIANALYZE Procedure
   
Parameter Estimates (25 Imputations)
ParameterEstimateStd Error95% Confidence LimitsDFMinimumMaximumTheta0t for H0:
Parameter=Theta0
Pr > |t|
estimate4.1720060.0499744.0736204.270392271.874.1518444.192110083.48<.0001
 
Percentage Decompositions of the Total Effect
 
The MIANALYZE Procedure
   
Parameter Estimates (25 Imputations)
ParameterEstimateStd Error95% Confidence LimitsDFMinimumMaximumTheta0t for H0:
Parameter=Theta0
Pr > |t|
estimate61.0130631.37521858.3062563.71987286.5660.82138761.142442044.37<.0001

 


Full Code for this example: 

data Cognitive;
   input  SubjectID FamSize  SocStatus  Encourage  Motivation  CogPerform;
   datalines;
  1      7       31          .           40          103
  2      3       27          36           40          103
  3      0       25          35           40           99
  4      6       29          36           40          103
  5      4       22          33           37           79
  6      2       23          34           38           87
  7      0       29          37           41          112
  8      4       23          34           38           87
  9      3       20          32           36          .
 10      3       28          36           40          103
 11      5       24          34           38           87
 12      1       25          35           39           95
 13      3       29          .           41          112
 14      2       31          38           42          120
 15      2       21          33           37           79
 16      3       30          37           41          112
 17      1       25          35           39           95
 18      2       21          33           37           79
 19      3       22          33           37           79
 20      3       26          35           39           95
 21      7       25          33           37           79
 22      4       31          38           41          116
 23      4       25          34           38           87
 24      5       22          33           37           79
 25      4       26          35           39           95
 26      6       24          33           37           79
 27      5       28          36           40          103
 28      6       20          32           36         .
 29      4       20          32           36           71
 30      3       21          33           37           79
 31      5       20          .           35           64
 32      3       27          36           40          .
 33      2       26          35           39           95
 34      7       24          33           37           79
 35      5       25          34           38           87
 36      4       25          34           38           87
 37      3       32          38           42          120
 38      4       23          33           37           79
 39      4       25          34           38           87
 40      7       29          35           39           95
 41      6       25          34           38           87
 42      5       24          33           37           79
 43      2       27          36           40          103
 44      3       26          35           39           95
 45      4       32          38           42          120
 46      5       31          37           41          111
 47      4       23          33           37           79
 48      2       29          37           41          112
 49      4       26          35           39           95
 50      3       26          35           39           95
 51      3       25          34           39           91
 52      6       27          35           39           95
 53      4       26          35           39           95
 54      2       25          35           39           95
 55      2       23          34           38           87
 56      7       23          33           37           79
 57      7       22          32           36           71
 58      4       26          35           39           95
 59      4       32          38           42          120
 60      3       20          32           36           71
 61      2       30          37           41          112
 62      4       32          38           42          120
 63      5       28          36           40          103
 64      0       28          37           41          112
 65      3       27          36           40          103
 66      5       15          29           33           49
 67      4       24          34           38           87
 68      6       21          32           36           71
 69      5       27          35           39           95
 70      3       14          29           33           49
 71      3       23          33           38           83
 72      6       26          34           38           87
 73      3       27          36           40          103
 74      3       29          36           41          107
 75      7       23          32           36           71
 76      3       27          35           40           99
 77      2       25          35           39           95
 78      5       32          38           42          120
 79      5       23          33           37           79
 80      2       30          37           42          116
 81      7       23          33           37           79
 82      5       25          34           38           87
 83      5       24          34           38           87
 84      5       27          35           39           95
 85      6       17          30           34           56
 86      2       30          37           41          112
 87      5       21          32           36           71
 88      5       27          35           39           95
 89      1       31          38           42          120
 90      3       22          33           37           79
 91      1       32          39           43          129
 92      3       26          35           39           95
 93      4       24          34           38           87
 94      5       21          32           36           71
 95      4       26          35           39           95
 96      4       24          34           38           87
 97      5       27          35           39           95
 98      4       26          35           39           95
 99      5       21          32           36           71
100      3       23          34           38           87
101      6       25          34           38           87
102      5       24          33           37           79
103      4       26          35           39           95
104      4       26          35           39           95
105      1       24          35           39           95
106      4       32          38           42          121
107      3       33          39           43          129
108      4       31          37           41          112
109      2       20          32           37           75
110      2       28          36           40          103
111      4       23          34           38           87
112      4       26          35           39           95
113      4       25          34           38           87
114      5       28          35           40           99
115      6       22          32           36           71
116      4       26          35           39           95
117      4       29          36           40          103
118      3       24          34           38           87
119      6       29          35           40           99
120      2       22          34           38           87
121      2       28          36           41          107
122      0       26          36           40          103
123      3       20          32           36           71
124      5       20          31           35           64
125      2       25          35           39           95
126      4       17          31           35           64
127      2       25          35           39           95
128      1       25          35           39           95
129      6       25          34           38           87
130      3       25          35           39           95
131      3       29          36           40          103
132      3       22          33           37           79
133      6       20          31           35           64
134      4       22          33           37           79
135      7       28          35           39           95
136      2       24          34           38           87
137      6       23          33           37           79
138      2       24          35           39           95
139      5       26          34           38           87
140      2       29          37           41          112
141      4       22          33           37           79
142      3       28          36           40          103
143      5       28          35           39           95
144      2       24          34           39           91
145      2       26          35           39           95
146      4       25          34           38           87
147      5       24          34           38           87
148      3       27          36           40          103
149      0       27          37           41          112
150      1       25          35           39           95
151      3       22          33           37           79
152      4       25          34           38           87
153      5       25          33           38           83
154      3       28          37           40          108
155      3       21          33           37           79
156      3       25          35           39           95
157      2       21          33           37           79
158      5       21          32           36           71
159      2       27          36           40          .
160      2       29          37           41          112
161      4       29          37           41          112
162      3       25          34           39           91
163      4       23          33           37           79
164      6       26          34           38           87
165      2       23          34           38           87
166      5       24          33           37           79
167      4       28          36           40          103
168      3       22          33           37           79
169      3       24          34           38           87
170      7       22          32           36           71
171      2       25          35           39           95
172      1       28          37           41          112
173      3       28          36           40          103
174      3       25          34           38           87
175      3       23          34           38           87
176      4       21          32           36           71
177      4       19          31           35           64
178      7       25          34           38           87
179      2       29          37           41          112
180      4       25          34           38           87
181      4       19          31           35           64
182      4       24          34           38           87
183      4       31          37           41          112
184      3       22          33           37           79
185      5       30          37           41          112
186      6       28          35           39           95
187      4       21          32           36           71
188      3       27          35           40           99
189      3       17          31           35           64
190      3       22          33           37           79
191      3       26          35           39           95
192      3       22          33           37           79
193      3       25          35           39           95
194      4       31          37           41          112
195      6       22          32           36           71
196      2       24          34           38           87
197      4       22          33           37           79
198      6       25          34           38           87
199      5       16          30           34           56
200      6       32          37           41          112
201      1       24          34           39           91
202      5       24          33           37           79
203      3       18          31           35           64
204      6       28          35           39           95
205      4       20          32           36           71
206      8       33          37           41          112
207      4       30          36           41          107
208      2       29          37           41          .
209      6       15          29           33           49
210      4       24          34           38           87
211      2       18          32           36           71
212      5       17          30           34           56
213      3       24          34           38           87
214      4       19          32           36           71
215      6       23          32           36           71
216      6       27          35           39           95
217      3       32          38           42          120
218      5       27          35           39           95
219      6       20          31           35           64
220      4       21          32           36           71
221      4       23          33           37           79
222      4       25          35           39           95
223      4       21          33           37           79
224      3       28          36           40          103
225      6       23          33           37           79
226      4       26          35           39           95
227      5       22          33           37           79
228      5       30          36           40          103
229      2       31          38           42          120
230      6       23          33           37           79
231      5       30          37           41          112
232      3       24          34           38           87
233      5       24          34           38           87
234      4       25          34           38           87
235      1       23          34           38           87
236      6       30          36           40          103
237      3       23          34           38           87
238      3       22          33           37           79
239      6       26          34           38           87
240      6       22          32           36           71
241      4       24          34           38           87
242      2       23          34           38           87
243      5       28          36           40          103
244      4       30          37           41          112
245      4       26          35           39           95
246      6       28          35           39           95
247      3       23          33           37           79
248      7       28          35           39           95
249      3       21          33           37           79
250      2       25          36           40          103
251      3       29          37           41          112
252      3       30          37           41          112
253      1       26          36           40          103
254      4       26          35           39           95
255      4       29          36           40          103
256      4       29          36           40          103
257      0       27          36           40          103
258      1       29          37           41          112
259      4       31          37           41          112
260      4       26          35           39           95
261      2       23          34           38           87
262      5       22          33           37           79
263      2       26          35           39           95
264      4       24          34           38           87
265      5       20          31           35           64
266      6       21          32           36           71
267      3       26          35           39           95
268      2       21          33           37           79
269      4       29          36           40          103
270      4       29          36           40          103
271      5       24          33           37           79
272      6       21          32           36           71
273      0       27          37           41          112
274      3       26          35           39           95
275      4       24          34           38           87
276      3       20          32           36           71
277      5       27          35           39           95
278      0       27          36           41          107
279      4       28          36           40          103
280      4       27          36           40          103
281      4       27          35           39           95
282      6       24          34           38           87
283      4       22          33           37           79
284      4       26          35           39           95
285      4       24          34           38           87
286      6       21          32           36           71
287      2       14          29           33           49
288      5       24          34           38           87
289      4       24          34           38           87
290      5       30          36           40          103
291      2       24          35           39           95
292      7       30          36           40          103
293      3       25          35           39           95
294      5       25          34           38           87
295      4       19          31           35           64
296      5       24          34           38           87
297      4       27          35           39           95
298      0       28          37           41          112
299      3       29          36           41          107
300      5       30          37           41          111
;
proc mi data=cognitive out=Cognitive_Imp seed=100;
var cogperform encourage motivation famsize socstatus;
run; 

proc causalmed data=Cognitive_imp all;
by _imputation_;
   model    CogPerform  = Encourage|Motivation;
   mediator Motivation  = Encourage;
   covar    FamSize SocStatus;
   ods output outcomeEstimates=Outcome_Est MediatorEstimates=Med_Est PercentDecomp=pctdecomp EffectDecomp=effdecomp Effectsummary=effsum;
run;


proc mianalyze parms=outcome_est edf=290;
modeleffects intercept FamSize SocStatus Encourage Motivation Encourage*Motivation;
title 'Combined Estimates for the Outcome Model';
ods select ParameterEstimates;
run;

proc mianalyze parms=Med_est edf=290;
modeleffects intercept FamSize SocStatus Encourage;
title 'Combined Estimates for the Mediator Model';
ods select ParameterEstimates;
run;

proc sort data=effsum;
by effect _imputation_;
run;

proc mianalyze data=effsum edf=290;
by effect;
title 'Summary of Causal Effects';
modeleffects estimate;
stderr stderr;
run;

proc sort data=pctdecomp;
by decomp effect _imputation_;
run;

proc mianalyze data=pctdecomp edf=290;
by decomp effect;
title 'Percentage Decompositions of the Total Effect';
modeleffects estimate;
stderr stderr;
run;

proc sort data=effdecomp;
by decomp effect _imputation_;
run;

proc mianalyze data=effdecomp edf=290;;
by decomp effect;
title 'Decompositions of the Total Effect';
modeleffects estimate;
stderr stderr;
run;