I have a dataset
df describing repeated scores (variable = V5) for each subject (coded in V1). Subjects belong to different groups (variable = V7), and have different age (variable = V6). The dataset is composed of 6 variables:
V2: continuous variable
V4: factor with 75 levels
V5: dependent variable
V6: continuous variable (age)
V7: factor with two levels (groups)
I am fitting a linear mixed effect model in R from the
nlme package (
my_lme = lme(V5 ~ V4*V7, data=df, random = ~ 1 | V1, na.action=na.omit)However, I am interested in first of all regressing out the effect of V6 before applying the linear mixed effect model. Which is the most reasonable approach to do so? Would be ok to:
- First, regressing out V6 from V5 by applying a linear model, e.g.
my_lm = lm(V5 ~ V6, data = df)
- Then apply the linear mixed effect model on the
my_lm$residualsafter putting them on my dataset naming them as V9, hence:
my_lme = lme(V9 ~ V4*V7, data=df, random = ~ 1 | V1, na.action=na.omit)
Is this a correct approach in your expert opinion? I am sort of a newby.
I have a second question:
If I then want to additionally estimate the effect of the continuous variable V2 on the prediction of V5 in my model, would the following syntax be correct?
my_lme = lme(V9 ~ V4*V7 + V2, data=df, random = ~ 1 | V1, na.action=na.omit)
Thank you in advance.