# Multivariate hierarchical linear model via nlme

I'm running a multivarialte repeated measures hierarchical linear model in r's nlme package. I have three dependent variables D1, D2, and D3.

My variable structure is such that a time point is nested within a participant, which is nested within their respective group.

A snapshot of my data is below: In order to bring this to a multivariate space, I've dummy coded my three dependent variables, as per this tutorial

However, I'm having trouble conceptualizing the model with three nests, rather than 2. I've come up with two possible solutions and could use someone's help in determining which one is implementing the correct structure (i.e., group/id/time)

Thus, my possible equations are:

model <- lme(value ~ 0 + D1:Time + D2:Time + D3:Time, random = ~0 + D1:Time + D2:Time + D3:Time | Group/ID , data = Fixed_Data)


or

model <- lme(value ~ 0 + D1 + D2 + D3, random = ~0 + D1 + D2 + D3| Group/ID/Time , data = Fixed_Data)


Am I on the right track for either of these solutions?

Thanks for the help?

• Hard to say without looking at the code you used to build these variables, but I would not expect that you need to include Time in the random effects part of the model as an intercept. It is quite common to see time modeled as a random slope.But I have not tried to run one of these models in nlme. – Erik Ruzek Jun 4 at 23:05
• Thanks for the response! In most examples i've seen, Time is usually treated as a fixed factor with a random slope across the nested structure. In what cases would treating time as a random slope be inappropriate? – Lgleather Jun 5 at 23:19
• When the trend is relatively uniform across persons...that is, there is not a lot of heterogeneity/variation in the slopes across persons. – Erik Ruzek Jun 8 at 20:04