Contributor
Posts: 58

# Multilevel Mediation Analysis for Repeated Measures RCT

Hi SAS Users,

I am trying to do a multilevel mediation analysis using a 2x4 RCT design, where there are 2 conditions (control vs. experimental) and 4 time points (baseline, 1 month, 3 month and 6 month). A cut of the person-time dataset is shown below.

ObsIdnumcondtimeMediatorOutcome
1200011, control0 Baseline406.75
2200011, control1 month386.75
3200011, control3 month387.75
4200011, control6 month205.50
5200051, control0 Baseline63.25
6200051, control1 month42.25
7200051, control3 month22.50
8200051, control6 month121.75
9200061, control0 Baseline126.00
10200061, control1 month146.00
11200061, control3 month126.50
12200061, control6 month125.25
13200071, control0 Baseline107.75
14200071, control1 month87.00
15200071, control3 month27.00
16200071, control6 month67.50
17200082, experimental0 Baseline345.00
18200082, experimental1 month407.50
19200082, experimental3 month385.25
20200082, experimental6 month404.25
21200091, control0 Baseline123.75
22200091, control1 month23.25
23200091, control3 month204.75
24200091, control6 month204.00
25200102, experimental0 Baseline206.25

26

200102, experimental1 month205.75
27200102, experimental3 month182.25
28200102, experimental6 month104.75

The intervention cond id coded as 0 and 1; putative mediator and outcome were  measured at baseline and all follow ups.

Is there a way to evaluate mediation effects using this longitudinal data set with time varying measures?

If so, what is the best way of measuring the direct and indirect effects?

I used a random residual statement to account for within subject correlation, but the issue is that this solution of fixed effects is the marginal means. I need to evaluate the temporal effects as well, i.e., intervention -> mediates the intermediary putative mediator between 1 and 3 month -> changes outcome at 6 month.

This may be complicated but any help is much appreciated!

Posts: 2,655

## Re: Multilevel Mediation Analysis for Repeated Measures RCT

Can you share the GLIMMIX/GENMOD code that you are currently using?  At least for me, it is easier to adapt what you already have in hand, rather than starting from square one.  The mediator variable intrigues me--it is a response variable, but is also a covariate of sorts.  There might be a way to use PROC PHREG, since it is set up for time-dependent covariates, but we are rapidly moving towards the edge of my experience.

Steve Denham

Contributor
Posts: 58

## Re: Multilevel Mediation Analysis for Repeated Measures RCT

Steve,

The code I am tying to test is below. Also there is a correction in the post, the condition is codes 1 and 2 not 0 and 1.

/*-----------------------------------------------------*/
/* Mediation model 1                          */
/* Intervention on Outcome                 */
/*-----------------------------------------------------*/

proc glimmix data=work;
class idnum cond time;
model outcome = cond time cond*time / s;
random time/ subject=idnum type=un residual;

lsmeans cond*time;
run;

/*-----------------------------------------------------*/
/* Mediation model 2                          */
/* Intervention on Mediator                  */
/*-----------------------------------------------------*/

proc glimmix data=work;
class idnum cond time;
model mediator = cond time cond*time / s;
random time/ subject=idnum type=un residual;

lsmeans cond*time;
run;

/*-----------------------------------------------------*/
/* Mediation model 3                         */
/* Intervention and Mediator on Outcome*/
/*-----------------------------------------------------*/

proc glimmix data=work;
class idnum cond time;
model outcome = cond time cond*time mediator mediator*time / s;
random time/ subject=idnum type=un residual;

lsmeans cond*time;

lsmeans mediator*time;
run;

I have added the interaction terms with time to test the time dependent fixed effects.

Here is the scenario: lets assume that the intervention changes the mediator at 3 months which then mediates a change in the outcome at 6 months. If I set the reference category to baseline, it is possible to test the fixed effects for these changes: (1) cond*time (where cond=experimental and time=6 month in Model 1); (2) cond*time (where cond=experimental and time=3 month in Model 2) and (3) mediator*time in Model 3.

However, it is complicated to get the direct and indirect effects from this.

Posts: 2,655

## Re: Multilevel Mediation Analysis for Repeated Measures RCT

Parts 1 and 2 certainly make sense to me.  In model 3, however, we run into the problem that mediator is a continuous covariate.  Consequently, I would attack things just a bit differently.

First, since we are in GLIMMIX, I would use type=chol for the Cholesky root of the unstructured matrix--guarantees positive semidefinite G matrix.

Second, I would have the second lsmeans statement with multiple AT mediator= values, if the time by mediator interaction is significant:

lsmeans time/AT mediator=mean;

lsmeans time/AT mediator=<lowest value observed>;

lsmeans time/AT mediator=<highest value observed>;

If the time by mediator interaction is not significant, well, then I would seriously consider dropping it from the model, as now the slopes are parallel, so comparisons will not depend on the values that mediator takes on.

Steve Denham

Contributor
Posts: 58

## Re: Multilevel Mediation Analysis for Repeated Measures RCT

Thank You Steve! Is there any way to get the direct and indirect effects? Otherwise, I might just have to report the betas and p-values.

Posts: 2,655

## Re: Multilevel Mediation Analysis for Repeated Measures RCT

Look at the solution vector (the betas).  Which do you consider direct?  I would say condition and time and their interaction.  To get the indirect effect, look at the change in these betas when mediator is added in (this includes all mediator and mediator interaction terms).  If this is missing your point entirely, then I think you may need to work this through a structural equation model approach (PROC CALIS for example, or PROC MODEL in SAS/ETS) that specifies direct and indirect effects more specifically.

Steve Denham

Contributor
Posts: 58

## Re: Multilevel Mediation Analysis for Repeated Measures RCT

Hello Steve,

Sorry for not following up on this earlier.

I took your suggestion and tried two methods: (1) using a person time data set and modeled the time, cond and mediator interaction using GLIMMIX. I used a random residual statement to account for within subject correlation (code shown below).

/*-----------------------------------------------------*/

/* Mediation model 1                          */

/* Intervention on Outcome                 */

/*-----------------------------------------------------*/

proc glimmix data=work;

class idnum cond time;

model &outcome = cond|time/s;

random time/ subject=idnum type=chol residual;

lsmeans cond*time;

run;

/*-----------------------------------------------------*/

/* Mediation model 2                          */

/* Intervention on Mediator                  */

/*-----------------------------------------------------*/

proc glimmix data=work;

class idnum cond time;

model &med = cond|time / s;

random time/ subject=idnum type=chol residual;

lsmeans cond*time;

run;

/*-----------------------------------------------------*/

/* Mediation model 3                          */

/* Intervention and Mediator on Outcome*/

/*-----------------------------------------------------*/

proc glimmix data=work;

class idnum cond time;

model &outcome = cond|time|&med / s;

random time/ subject=idnum type=chol residual;

lsmeans cond*time;

lsmeans time/AT &med=12.9236111 /*mean*/;

lsmeans time/AT &med=12 /*median*/;

run;

Contributor
Posts: 58

## Re: Multilevel Mediation Analysis for Repeated Measures RCT

The solution of fixed effects and type II test of fixed effects from the final model (Model 3) is shown below. The reference was set as baseline and  DASS_anxiety is the mediator.

 Solutions for Fixed Effects Effect Condition time Estimate Standard Error DF t Value Pr > |t| Intercept 4.9622 0.121 667 41.01 <.0001 cond 1, control -0.057 0.1681 667 -0.34 0.7347 cond 2, experimental 0 . . . . time 1 month -0.5048 0.1092 1691 -4.62 <.0001 time 3 month -0.6054 0.127 1691 -4.77 <.0001 time 6 month -0.8472 0.1357 1691 -6.24 <.0001 time Baseline (reference group) 0 . . . . cond*time 1, control 1 month 0.2916 0.1501 1691 1.94 0.0522 cond*time 1, control 3 month 0.1661 0.1754 1691 0.95 0.3437 cond*time 1, control 6 month 0.5023 0.1857 1691 2.71 0.0069 cond*time 1, control Baseline (reference group) 0 . . . . cond*time 2, experimental 1 month 0 . . . . cond*time 2, experimental 3 month 0 . . . . cond*time 2, experimental 6 month 0 . . . . cond*time 2, experimental Baseline (reference group) 0 . . . . DASS_ANXIETY 0.03509 0.008233 1691 4.26 <.0001 DASS_ANXIETY*cond 1, control 0.0177 0.01172 1691 1.51 0.131 DASS_ANXIETY*cond 2, experimental 0 . . . . DASS_ANXIETY*time 1 month 0.01697 0.009498 1691 1.79 0.0741 DASS_ANXIETY*time 3 month 0.01906 0.01159 1691 1.64 0.1004 DASS_ANXIETY*time 6 month 0.02687 0.01274 1691 2.11 0.0352 DASS_ANXIETY*time Baseline (reference group) 0 . . . . DASS_ANXIE*cond*time 1, control 1 month -0.01377 0.01297 1691 -1.06 0.2886 DASS_ANXIE*cond*time 1, control 3 month -0.01029 0.01591 1691 -0.65 0.5178 DASS_ANXIE*cond*time 1, control 6 month -0.02023 0.01675 1691 -1.21 0.2274 DASS_ANXIE*cond*time 1, control Baseline (reference group) 0 . . . . DASS_ANXIE*cond*time 2, experimental 1 month 0 . . . . DASS_ANXIE*cond*time 2, experimental 3 month 0 . . . . DASS_ANXIE*cond*time 2, experimental 6 month 0 . . . . DASS_ANXIE*cond*time 2, experimental Baseline (reference group) 0 . . . . Type III Tests of Fixed Effects Effect Num DF Den DF F Value Pr > F cond 1 667 1.57 0.2105 time 3 1691 17.53 <.0001 cond*time 3 1691 2.89 0.0344 DASS_ANXIETY 1 1691 134.49 <.0001 DASS_ANXIETY*cond 1 1691 0.5 0.4776 DASS_ANXIETY*time 3 1691 1.73 0.1581 DASS_ANXIE*cond*time 3 1691 0.62 0.6036

Based on my understanding, if the type II tests of fixed effects for mediator*time is significant then mediation is present. The solution vectors are shown in solution for fixed effects, but for the life of me I can not figure out how best to present this finding or figure out a way to find direct/indirect effects.

Posts: 2,655

## Re: Multilevel Mediation Analysis for Repeated Measures RCT

The F tests for mediator*time and mediator*condition*time are not significant, but the mediator "main effect" (which is really an intercept measure) is significant.

OK.  I am walking out on a very thin limb here, and my interpretation may not fit your field.  I would say that  I see two populations, defined by the level of dass_anxiety, and the responses over time being essentially identical for those two.  There seems to be an indication that the time course differs somewhat by condition as well.  So, in a guess as to what is going on--direct effects are time and dass_anxiety, and condition an indirect effect on the time course of the response.  Plots over time should make this apparent.

Steve Denham

Contributor
Posts: 58

## Re: Multilevel Mediation Analysis for Repeated Measures RCT

Thanks for the suggestion Steve. I will try to look at the plots for interpretation. I also tried specifying line equations in proc CALIS (code shown below) which gives direct and indirect effects at each time point. The only issue is that I am not sure if I should specify a line equation for baseline as there should be no mediation at baseline in any case. However, that means baseline will be excluded from the error matrix.

ods html;

proc calis cov data=work_wide g4=1000 gconv=1e-10 all technique=levmar;

/*------------------------*/

LINEQS

outcome1_month = b1 cond + c1 mediator1_month + e11,

mediator1_month = a1 cond + e21,

outcome3_month = b2 cond + c2 mediator3_month + e12,

mediator3_month = a2 cond + e22,

outcome6_month = b3 cond + c3 mediator6_month + e13,

mediator6_month = a3 cond + e23

;

STD

cond=vartrt,

e11 = var11,

e21 = var21,

e12 = var12,

e22 = var22,

e13 = var13,

e23 = var23

;

COV

e11 e12 e13= COV1,

e21 e22 e23= COV2

;

run;

Posts: 2,655