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 (lme()
function).
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$residuals
after 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.
my_lme = lme(V5 ~ V4*V7 + V6, data=df, random = ~ 1 | V1, na.action=na.omit)
? If so, would this correct for V6 in analysing the effect of the other variables (i.e. V4 and V7)? With correct I mean regressing out V6. Sorry I am a complete newby on this. 2) Yes, I think my dataset allow for this, I have more than 10k observations. Thank you in advance. $\endgroup$