I searched many posts but could not find a solution to my particular problem.
I would like to implement in R a way to measure the association between a dependent variable Y and an independent variable X, and estimate if a treatment influencing both X and Y has an effect when comparing pre- and post-treatment X and Y (in a treated and control group) -- while accounting for covariates.
In other words I have:
- Dependent (continous) variable Y measured at PRE and POST
- Independent (continous) variable X measured at PRE and POST
- Covariates C1, C2, C3 (categorical and continuous) fixed (e.g. age, gender, occupation)
- Categorical variable TREATMENT (yes or no, i.e. treated and controls)
- Complete data for all subjects S at TIME = PRE and POST
And would ideally answer all the questions:
- what is the association between X and Y?
- does the treatment affect Y?
- does the treatment affect X?
- does the treatment affect the relationship between X and Y?
- what is the association between the value of X at PRE-treatment and the change in Y (i.e. what is the effect of the baseline value of X on treatment efficacy)?
I thought maybe using a mixed-effect model but I am really unsure about to formulate it:
library(lme4)
mle.model <- lmer(Y ~ X + TIME + TREATMENT + X*TREATMENT + (1 | S) + C1 + C2 + C3, data = my.data)
Then i guess the answers to the questions (in the same order) would be:
- look at beta coefficient of X
- look at beta coefficient of TREATMENT
- ?
- look at beta coefficient of X*TREATMENT
- ?
I would also think the model should include TIME*TREATMENT
but i am not sure how this would help answer any of the questions above
UPDATE This post seems to describe a very similar situation, although with several time points (defined as "sessions" there). So after the great answer by @matt-barstead I am not sure if I should go with a level 1 / level 2 approach (and how to implement it) or choose between the two models below (and which one to choose and why):
mle.model.1 <- lmer(Y ~ X*TIME*TREATMENT + (1|S), data)
mle.model.2 <- lmer(Y ~ X*TREATMENT + (1|S) + (1|TIME), data)