Growth curve analysis in R - time variable as a polynomial I have narrowed down some specific questions and was advised that it's more appropriate to post them here than on stackoverflow
I'm building a growth curve model using lmer in R and I'm unsure about some of the steps.
I have a study where 20 participants see 20 cues, and for each cue they give 20 responses, and I believe there is a time component to the responses (i.e. they are not given in a random order, so that's why I'm looking at a longitudinal analysis).
Currently my baseline model looks like this
Model0 <- lmer(logRT~  (1|Cue) + (1|Participant), data=Data, REML=FALSE)

Random effects:
 Groups       Name        Variance Std.Dev.
 Participant  (Intercept) 0.042230 0.2055  
 Cue          (Intercept) 0.003943 0.0628  
 Residual                 0.224097 0.4734  


I want to add a variable that corresponds to the response number (1 to 20), which I'm thinking of as the time variable, and test whether a quadratic model of the change over time fits better than a linear model. But I'm not sure how to code that and how to interpret the results.
So would this be the right code
QuadrTime <- Time^2

Time_linear <- lmer(logRT~ Time + (1|Cue) + (1|Participant), data=Data, REML=FALSE)
Time_quadratic <- lmer(logRT~ Time + QuadrTime + (1|Cue) + (1|Participant), data=Data, REML=FALSE)

or can the first Time be excluded in the Time_quadratic model?
Second, can the Time variable be nested within something? in this case, Time corresponds to 20 responses that participants give to each cue, and for each cue the responses are slightly different (and will have different values of subsequent predictors) so is it possible to code it as:
Time_quadratic <- lmer(logRT~ (Time/Cue) + (QuadrTime/Cue) + (1|Cue) + (1|Participant), data=Data, REML=FALSE)


It's not always a good idea to use a simple polynomial, as you propose, to account for non-linear time courses. That can miss (and thus misfit) a lot of interesting behavior.  Restricted cubic splines (regression splines) or penalized splines provide ways to let the data tell you the shape of the non-linear change with time. They let you evaluate changes with time and associated nonlinearities. See this page for a useful introduction. Searches on this site for terms like spline mixed model will provide more examples and advice.
With respect to Time and Cue, I think that what you are asking for is whether you can have the slope/shape with respect to Time differ among values of Cue. For a linear change with Time, that could simply be a random slope term of form (Time|Cue). See the lmer cheat sheet for how to code with respect to correlations between intercepts and slopes.
That gets more complicated with nonlinear modeling of time. If you want to include random effects in a mixed model for the non-linear aspects of time, you might need to include multiple random coefficients (with an underlying assumption that each coefficient has a Gaussian distribution among Cue values).
There's an example here of doing mixed modeling with random coefficients for all the terms introduced by the restricted cubic splines implemented by the rcs() function in the R rms package. If you want to simplify the random effect of Time to just be the linear trend I couldn't easily find a way to use rcs() that way, but you can do that with the ns() function in the splines package that's part of the base R distribution.
You might also consider the penalized splines approach implemented in generalized additive modeling with the mgcv package. That can accommodate random effects, but I don't have experience using that package with mixed models.
