Per your questions...
How does the main predictor affect the outcome?
The predictor will affect the outcome in the same way it does in a fixed effects linear regression. The only difference is how the point estimates look after accounting for the random effects.
How does time affect the outcome?
Time affects the outcome in two ways:
- If the response changes over time (positive/negative trend), then it could mean that your outcome is not stable longitudinally and may be affected by temporal effects (such as developmental age , which will initially show large increases in letter reading ability but will quickly plateau as children fully learn their letters).
- Because this measure is repeated (e.g. a subject is rated on depression at Year 1 and Year 2), the errors tend to be correlated, which means that they will downward bias the standard errors and produce inaccurate measurements of the fixed effects in a regression. As such, it is useful to model this directly by simply adding in time as a fixed effects predictor.
I'm not sure how to handle this/set up the random effects. I never had the situation of including two random effects and I don't think that's the right way here. I would probably include all covariates as fixed effects, plus an interaction term Time * Main Predictor, but what about the random effects?
Yes, you can include the main effects of time and the main predictor here as well as their interaction if you believe the main predictor changes relationship with the outcome over time. If one assumes there is no change across time, you probably wouldn't need to include this as an interaction at all.
In terms of what that means for estimating a mixed model, you could fit the model with the following syntax:
model <- lmer(y ~ x * time + (1 + x | subject), data = data)
This would model the main effects and interaction of $x$ and time, while estimating how the slope between $x$ and $y$ varies by person (subject is a cluster which has repeated measures across time, thus this produces an individual intercept and slope for $x$ and $y$ for each subject). You could include time and $x$ as random slopes like below (with our without the *
operator for an interaction):
model <- lmer(y ~ x * time + (1 + x + time | subject), data = data)
But I doubt it would be that useful and would be more prone to non-convergence or singularity (as complexity of random effects increases, the likelihood of the model converging decreases). In fact, it may be the case that even a simple random slope is too complex, in which case you may be better off simply estimating random intercepts like below, modeling only how intercepts vary by subject:
model <- lmer(y ~ x * time + (1 | subject), data = data)
How you decide on that will depend largely on what your data actually looks like and whether it can fit such models.