3
$\begingroup$

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?

$\endgroup$

1 Answer 1

2
$\begingroup$

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)
$\endgroup$
6
  • $\begingroup$ Thank you for your response! It does seem to solve the problem indeed! Just for my understanding: With the correlational structure, I wanted to model the correlation between observations over time, is that indeed how Formula: ~1 | PMC_ResearchID (resulting from your anwser) works? Additionally, what do you mean by more general in the case of corARMA? I was unsure of the usability of ARMA with unbalanced data, so that is why I have not used it so far. $\endgroup$
    – yentl02
    Commented Sep 9, 2022 at 12:09
  • $\begingroup$ lme can handle unbalanced data safely. With 1 | ID you are doing precisely what you are looking for; this is described in Pinheiro & Bates (2000) Mixed-effects models in S and SPULS, Sect. 5.3. $\endgroup$
    – utobi
    Commented Sep 9, 2022 at 12:25
  • $\begingroup$ Yes I read Pinheiro & Bates (2000) Mixed-effects models in S and SPULS indeed, however I seem to get stuck on the explanation of the types of structures. What I understood from it is that, when using a likelihood-based method like a mixed model, unbalanced data is not problematic, however some correlational structures do assume that the intervals between observations are regular, which is why I was unsure whether it is still valid to use, or whether it would make more sense to only include random slopes, such that an unstructured covariance matrix for the residuals is used. Would you agree? $\endgroup$
    – yentl02
    Commented Sep 9, 2022 at 12:32
  • $\begingroup$ Oh I see now. Yes, you are right, for an arma type correlation structure, time points should be regular although not necessarily even spaced. But if for some reason, in your data it is the time ordering that’s relevant and not the time points per se you can still use it. $\endgroup$
    – utobi
    Commented Sep 9, 2022 at 12:45
  • 1
    $\begingroup$ Ah I think I see, so as long as my interest is not in the time points specifically, but rather in the modelling of the repeated measures data and therefore the "time"-element, a correlation structure such as corAR1 or corARMA should be fine? $\endgroup$
    – yentl02
    Commented Sep 9, 2022 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.