For analysis of a longitudinal data with repeated measures, should you use continuous or categorical variable for time? I have performed a study over 6 months: measuring pain between two groups of patients at baseline, and at 3 and 6 months after an intervention.
I am performing a LMM analysis: but just now getting confused if I should use time as a categorical variable (ordered or non-ordered) or a continuous variable.
If I use the former (categorical factor), and try the following for a random slope, intercept using R:
pain ~ 1 + intervention*interval + (interval|subject)

I get an error that the number of observations is smaller than number of random effects.
Any help appreciated: the more I read, the more confused I become.
EDIT: Included image of boxplot of scores against time, per study group

 A: With your categorization of time, you presumably have the pre-intervention time as reference and 2 time-associated coefficients representing the other 2 time categories (3 and 6 months). With your mixed model for fixed effects you are modeling an intercept, an intervention coefficient, 2 time coefficients, and 2 intervention:time interaction terms. With a random intercept and 2 random time coefficients, you are also effectively estimating the individual differences of those 3 values from the corresponding fixed-effect values. Yet you only seem to have 3 observations per individual. Hence your problem with too few observations.
There are a few ways to proceed.
First, you could try to use continuous time as a simple linear predictor and maintain the random slopes. But even if that doesn't throw an error you are then assuming that the effects of time on outcome are linear, other things being equal. That might not be a good assumption.
Second, you could continue with the mixed model and time categories but not include random slopes.
Third, you could use a different way to handle the repeated measures. With a simple design like this you could use repeated-measures multivariate ANOVA or generalized least squares instead. Chapter 7 of Frank Harrell's course notes or book outlines different approaches to repeated-measures data like yours, with an emphasis on generalized least square.
A: By treating time as a categorical variable in this situation, you ensure that there is no constraint in your model between the effect of the two time periods.  This is generally preferable when you have enough data to do so, since it allows greater flexibility in the model.  The boxplot you show in your question makes it clear that the effect of time is nonlinear, so the categorical approach will capture this well.  As to the computational problem you are having, since you haven't told us anything about how much data you have in the categories, we can't possibly help.
A: The answer will depend on the particulars of the research question. Time is, with the possible exception of durations near Planck scale, continuous. However, aggregations of time are often meaningful and justified by theory.
For example, one might treat time in one time to event model using a continuous variable for time (say, when modeling mean continuous time before failure in units of years), but in another time to event model using a discrete variable for time (say, when modeling time to graduation since matriculation in units of discrete academic terms). The former example "half a year" is meaningful, "but half a term" is not meaningful: people do not graduate mid-way through a term.
The answer for your (or anyone's) specific case must be driven by a temporal theory of the process being modeled.
