Error lme: covariate must have unique values within groups I am trying to create a linear mixed model for longitudinal data using data that looks similar as the data in the following:
> head(df, 10)
   ID   S  A    BT AT outcome Time
1   1   0 0.40  0  5      90    4
2   1   0 0.40  0  5      90    6
3   1   0 0.40  0  5      90    7
4   1   0 0.40  0  5      90   11
5   2   0 1.32  0  7      90    5
6   2   0 1.32  0  7      90    7
7   2   0 1.32  0  7      90   11
8   3   1 5.78  0  3      85    0
9   3   1 5.78  0  3      85    2
10  4   1 5.98  1  3      58    2

# Model (1)
model <- lme(outcome ~ S + BT + A + AT*Time, random = ~ 1 + Time|ID,
             data = df, na.action = na.exclude, method = "REML",
             correlation = corAR1(form = ~ Time)


The data is unbalanced in the sense that a different number of observations exists for each subject with irregular time intervals. Unfortunately, with the data as specified in the former, a model with random slopes (or other more complex random structures) does not converge, however I added the data for illustration of the real data, since the real data looks similar.
When trying to fit a model using nlme::lme() with e.g. random intercepts and slopes and corCAR1 for specifying a specific correlation structure on the real data, I get the following error:
Error in Initialize.corAR1(X[[i]], ...) : 
  covariate must have unique values within groups for "corAR1" objects

After searching for similar questions, unfortunately I have not found what is causing the error. I have checked whether duplicate values of time exist for each "group" (so for each subject), but this is not the case. Unfortunately, I cannot share the real data for confidentiality reasons, so an actual reproducible example is not included.
What might be causing this error?

I guess that in the correlation structure of the error you have to provide the ID like this
model <- lme(outcome ~ S + BT + A + AT*Time, random = ~ 1 + Time|ID,
             data = df, na.action = na.exclude, method = "REML",
             correlation = corAR1(form = 1 |ID)

Provided you have enough data, a model with a more general correlation structure in the error could be:
model <- lme(outcome ~ S + BT + A + AT*Time, random = ~ 1 + Time|ID,
             data = df, na.action = na.exclude, method = "REML",
             correlation = corARMA(c(0.2,0.3,-0.3),
                                   form = 1 |ID),
                                   p=2,q=1)

