# Simple Mixed Effects Modelling - is it correct?

I completed an intervention where participants engaged with an exercise programme and specific outcomes were measured in 4 different times (longitudinal study). For this example, the outcome distance was my response variable. I want to use subject (ID) as a random effect and time as fixed effect.

Therefore, I prepared the following model:

M<-lmer(distance ~ time + (1|ID),L)

The output that I get from anova(M)is:

And the output from summary(M)is the following:

Is it the correct way to do it? Could I then say that there were significant differences between time points that resulted in time3 being significantly different? (in some examples I have not seen time being displayed as levels and that confused me...)

Finally, another question that I have is how can I add covariates? I would like to account for the effect of Age in my model.

• Plot of my data

Plot of the residuals:

Any help would be greatly appreciated!

Best wishes, Anna

Is it the correct way to do it?

It is one way to do it ! With only 4 time points it is perfectly reasonable to treat time as discrete, particularly since there appears to be some non-linearity. I would suggest that you plot the data to assess this further.

Could I then say that there were significant differences between time points that resulted in time3 being significantly different? (in some examples I have not seen time being displayed as levels and that confused me...)

You may be confused because if you treat time as numeric you will only get 1 estimate (for the linear slope) whereas when you treat it as discrete, as you have, then each of time points 2, 3 and 4 get their own estimate, which is interpreted as the expected change in the outcome between the time point in question, and time point 1. So there is very little evidence of any difference between time 1 and time 2, but there is strong evidence of a difference of 21.9 between time 1 and time 3; and finally, weak evidence of small difference between time 1 and time 4. Since the difference between time 1 and 2 is much larger than between 1 and 3, this suggests a nonlinear association. As mentioned above, you should also plot the data to assess this.

Finally, another question that I have is how can I add covariates? I would like to account for the effect of Age in my model.

All you need to do is add it to the model:

distance ~ time + age + (1|ID)

• Thank you so much for your answer! When I plot the residuals they look fairly randomly distributed, without any pattern. If I understand it properly, in nonlinearity they would be showing a patterns (is this correct?). If my data is linear, is it still okay to treat time as discrete? If not, how can I treat is as numeric? Commented Jul 9, 2021 at 11:20
• (Edited)Thank you so much for your answer! When I plot the residuals they look fairly randomly distributed, without any pattern. If I understand it properly, in nonlinearity they would be showing a patterns (is this correct?).If my data is linear, is it still okay to treat time as discrete? If not, how can I treat is as numeric? If it is then showing non-linearity, can I still report my results? When I plot the data I do see an increase in t3, which makes me think that participants need to engage till t3 at least to elicit improvements (I assess a population of people with Parkinson's Disease) Commented Jul 9, 2021 at 11:27
• You're very welcome :) Perhaps you could edit the question to include a plot of the data ? It's perfectly OK to treat time as discrete even when the association is linear, but if you wanted to treat it as numeric then just make a new variable, let it have the values 1,2,3,4 as appropriate and ensure that it is numeric. You might be able to do this simply by using L\$time1 <- as.numeric(time) and then using time1 in the model. If the association is actually linear then using time as numeric will be a little more parsimoneous. Commented Jul 9, 2021 at 11:35
• As for plottng the residuals, if you had treated time as continuous/numeric, this would fit a linear slope for time, and in that case, if the residuals showed some pattern, then you would be right to consider nonlinearity. However, since you have treated time as discrete, if there is some nonlinearity this may be cpatured in the 3 estimates for time and the residuals would indeed show no pattern. Commented Jul 9, 2021 at 11:43
• Many thanks again, your replies are extremely useful! I have tried to use time as numeric with lmer(distance ~ as.numeric(time) + (1|ID),L) but then the p value changes quite a lot: F value= 2.4664 & p value = .1203 (I have added some plots in the main question). Let me know what you think :) Many thanks, Anna Commented Jul 9, 2021 at 12:43