# Model for longitudinal study design with confounding variable(s)

I'm conducting a study with the following ("hierarchical") design: There are two measures for each participant (2 time points, pre and post the study's intervention). There are control and test participants, for one of currently two different groups, but there will be more in the future.

So that's a 2-by-2-by-2 design:

• 2 time points (pre-post)
• 2 conditions (control-test)
• 2 groups (group A-group B). There will be more groups in the future.

Additionally, I would like to control for some measured variable, called pred.

I have 3 questions:

1. What is the "correct" statistical design to use? I'm struggling to choose between a linear mixed-effects model and using the differences in a multiple linear regression model.
2. If LMM is the correct choice - should the "confounding" variable be considered a fixed effect?
3. Given the choice in (1), how can I perform a power analysis to detect the required sample size? Given pilot data (for which I can fit the chosen model), how can I calculate the effect size and corresponding sample size? The required power is 0.8, and the alpha is 0.05.

Attaching a python code example to make it more clear, but answers are welcome to be written in R if it's more comfortable.

## Linear Mixed Model

import pandas as pd
from statsmodels.formula.api import mixedlm

data = pilot_features.copy()
data["target"] = pilot_target["target"]

model = mixedlm("target ~ C(session, Treatment('pre')) * C(condition) * C(group) + pred",groups = data["participant"]).fit()


# Multiple Regression

import pandas as pd
from statsmodels.formula.api import ols

data = pilot_diff_features.copy()
data["delta_target"] = pilot_diff_target["delta_target"]

model = ols("delta_target ~ C(condition) + C(condition):C(group) + delta_pred",data=data).fit()


There are several effects of interest:

• Main effect of the condition.
• Main effect of the session, only for test participants.
• Interaction between condition and session
• interaction between condition, session, and group.

• If you have missing data in your outcome variable target it is preferable to use a linear mixed model.
• Working with differences (i.e., target at post minus the target at pre) is, generally, considered suboptimal. It is better to use an ANCOVA model (i.e., linear regression), in which you put as the outcome the target at post, and you include as a covariate the target at pre.