# Mediation analysis with depent observations. Is it possible with mixed models?

I wonder whether it is possible in principles to conduct a mediation analysis with dependent measures. The problem is of course that we are violating the assumption of independence of observations. Mixed model seem to be able to work around that (in principles). I have done some study on the matter at this point and I think the solution below could work. Caveat: I am a student so I may have overlooked some things. Below is a working example where I develop the idea:

## Background and Methods

130 patients were seen for a 10 week physiotherapy treatment that was designed to improve their performance to a particular physical test. Performance was recorded for each participant before and after the intervention. All participants undertook the same treatment.

The level of fitness (our potential mediator) was also measured before and after the physiotherapy treatment for each participant.

Aim: We would like to test the level of fitness as a mediator variable. That is, we suspected that improvements in the level of fitness between the two time points mediate the effect of physiotherapy on the performance test.

• The dependent variable $$Y$$ is numeric and here we will call it Performance
• The independent variable $$X$$ is categorical (2 levels: pre and post) and here we will call it Time
• The mediator variable $$M$$ is numeric and we can call it Fitness.

In a mediation model there is a distinction between a $$direct$$ and an $$indirect$$ effect.

### Direct effect

The direct effect we will call $$c$$ and can be represented as follow:

Now, in lme4::lmer() we can control for the level of $$Y$$ (Performance) at baseline as our random effect with the following model:

    model <- lme(performance ~ Time,
random = ~ 1|id,
data= longformat
)


Then, if we want to consider the autocorrelation of the residuals that is due to the fact that the same individual is measured twice:

    model <- lmer(performance ~ Time,
random = ~ 1|id,
correlation = corAR1(form = ~ Time|id)
data= longformat
)


### Indirect effect

Considering the following classic mediation model:

In this approach to mediation testing, it is paramount to assume the independence of observations - among other important assumptions.

Knowing that with mixed effect we can specifically model such dependency, my humble question is the following:

## QUESTION: can we calculate the indirect effect modelling dependency within mixed models?

$$X$$: Time; $$Y$$ Performance; $$M$$: Fitness;

• path a: this regression estimates Fitness $$M$$ as a function of "Time".

model_a <- lme(Fitness ~ Time,
random = ~ 1|id,
data= longformat
)

• path b: this regression estimates Performance as a function of "Time" and "Fitness".

model_b <- lme(Performance ~ Time + Fitness + Time*Fitness,
random = ~ 1|id,
correlation = corAR1(form = ~ Time|id)
data= longformat
)