# Specification of longitudinal mixed-effects model with varying treatment times, varying observation times in lme4

I am familiar with fixed-effects linear regression models, and have done reading on mixed-effects models.

I am attempting to fit a model based on observational data, where treatments come at varying times and do not exist at all for a majority of subjects.

I am interested in whether or not the treatment has an effect on the trajectory of a subject's response over time. Graphically:

The most relevant analogous model I have found would be the one specified here, specifically Part 3. However, this example does not use R. I have read through all of Bates' lme4 paper, but I am still uncertain how to specify this effect.

An excerpt of my data:

     ID RESPONSE ID.CONST.1 ID.VAR.1 ID.VAR.2 TREATMENT_ACTIVE RESPONSE.TIME
1077415        7         41        0        5            FALSE           314
1077415        8         41        1        6            TRUE            316
1077415        9         41        10       7            TRUE            319
1077688        1         59        0        1            FALSE           313
1079475        1         85        0        1            FALSE           313
1080811        1         24        0        1            FALSE           314
1081156        1        502        0        1            FALSE           314
1082437        1         50        0        0            FALSE           315
1083154        1        257        0        0            FALSE           315
1083154        2        257        0        0            TRUE            316
1083527        1         69        0        0            FALSE           315
1086283        1         31        0        0            FALSE           316
1088810        1        120        2        1            FALSE           317
1090019        1         93        2        1            TRUE            317
1091048        1         27        0        0            FALSE           317
1091114        1         62        0        1            FALSE           317


Each subject (ID) has time-varying measurements (ID.VAR.X), constant measurements (ID.CONST.X), as well as the time of observation (RESPONSE.TIME). TREATMENT_ACTIVE indicates whether or not the treatment is active for a given subject at the corresponding RESPONSE.TIME. Some subjects have a single observation, others have multiple observations, and treatment times are rarely the same between subjects.

I've attempted to fit models as:

lmer(RESPONSE ~ ID.CONST.1 + ID.VAR.1 + ID.VAR.2 + TREATMENT_ACTIVE + RESPONSE.TIME + (1|ID) + (1|RESPONSE.TIME)
lmer(RESPONSE ~ ID.CONST.1 + ID.VAR.1 + ID.VAR.2 + RESPONSE.TIME + (1|ID) + (1+TREATMENT_ACTIVE|RESPONSE.TIME)


However, I'm fairly certain this is misspecified. I am not sure how to specify the random effects to ensure that the TREATMENT_ACTIVE variable is interpreted as I intend. I am interested in testing both an intercept-only model as well as a intercept+slope model for the treatment effect.

• I apologise for the very brief answer below. I found your question while I was looking for something slightly different. I hope to update the answer with an example very soon. – user02814 Oct 18 '15 at 5:47