# Using lme4/ linear mixed model to model longitudinal data in which age at first test and duration between measurements vary

I need specify a model using lmer() with data (n > 3500) in which there is a lot of variability in the age of the (human) subjects and also the duration between measurements (5 measurements total but a lot of subjects have missing data for multiple measurements). The outcome measure is a cognitive performance assessment on a tablet, and there is a grouping factor (A vs B) that is of interest. This is what the data look like:

id   gender  group  org time age score
1      2      0.5     1    1  57    37
1      2      0.5     1    2  57    44
1      2      0.5     1    3  62    47
1      2      0.5     1    4  NA    NA
1      2      0.5     1    5  NA    NA
2      1     -0.5     3    1  58    56
2      1     -0.5     3    2  61    60


...

The data are messy but I'm looking to make use of most of it instead of trying to impose some order and losing half or more of the data in the process. I want to test whether there are group differences in how performance changes with repeat testing, such that the A group scores better after more testing, which could be indicative of more strategy use or learning, or motivation. To complicate things further, the subjects are nested within organizations that administered the testing.

There are two ways I'm thinking I could model this. One is like this:

lmer(score ~ time * group + age + gender + (time | org/id)


The other would be to create multiple change scores (e.g., time2-time1, time3-time4, etc.) and create a new 'time' variable that would indicate whether it was the first change score, second, third, etc. I'd also create a 'duration' variable to control for variability in the duration between the two time points related to the change score. I'd also control for age at time 1. The model would be something like:

lmer(change_score ~ time * group + age_at_time1 + duration_betw_timepoints + gender + (change_score | org/id)


The 'compact' model for each of these would not include the interaction term. The idea is to test whether there are group differences in how performance changes with repeat testing (first model above) OR group differences in growth (second model). What I'm not sure of is whether any of what I'm proposing is ok. It makes sense to me but maybe it's not the right way to model this kind of data?