Help! Am I specifying my mixed-effects model formula correctly? I have a dataset where 50 Subjects were each exposed to 2 Testing Conditions over 5 Time Periods and they reported their Happiness Levels at every time point (i.e., I have 50 * 2 * 5 Happiness data points in total). Based on past work, I know I need to run a "linear mixed-effects model with a fully specified random-effects structure, with subjects as a non-nested random factor, and all intercepts and slopes included".
If I just had 50 Subjects with 5 Time Periods, I know that my lme4 formula would be:
Happiness ~ Time + (Time | Subjects)

But if I have 50 Subjects with 5 Time Periods AND 2 Testing Conditions, would this be:
Happiness ~ Time * TestingCondition + (Time * TestingCondition | Subjects)

I'm still learning more complicated LMM designs at the moment, so if I'm completely off the mark here, I'd appreciate any help or advice I can get!

This is almost right, although it probably needs to be adjusted for practical/identifiability purposes. The rubric is that any condition or treatment that varies within groups should be allow to vary across groups; since you have measurements for both testing conditions and every time point for every subject, you can in principle measure the variation of all of these effects (for example: "how does the difference in testing conditions at time point 3 vary across subjects?" [this quantity isn't explicitly estimated by the model]).
There are a few important points to consider, however, in two cases.
Time considered as categorical
In this case you have two problems:

*

*since you only have one measurement per time point $\times$ treatment combination per subject, the among-subject variance in the interaction is confounded with the residual variance term. There are a few different options for overriding this, but ...

*in addition, your model will almost certainly be overparameterized/too complex. With two time points and 5 treatments, you have 10 parameters that vary across subjects, which implies a 10 $\times$ 10 covariance matrix with (10*11)/2 = 55 parameters to estimate. It's extremely unlikely that you will be able to do this with 50 subjects/500 data points ... you could:

*

*use a Bayesian framework (e.g. blme, MCMCglmm, or brms) to put regularizing priors on the covariance matrix

*simplify the model, at least to (Time + Treatment|Subject) (this will "only" require a 6 $\times$ 6 covariance matrix with 21 parameters ...)

*simplify in some other way, e.g. use glmmTMB to fit a factor-analytic covariance matrix, or afex::mixed to fit a zero-covariance model



Time considered as continuous
This version is much easier, although it requires you to assume a linear trend across time points.
Now (Treatment*Time|Subject) only implies a 4 $\times$ 4 covariance matrix = 10 parameters.  Still a little bit ambitious, but it might work.
