I want to specify a mixed effects model using lme4:lmer() to determine if sex (M vs. F) and treatment group (control vs. test) are related to how people's memory errors evolve over time for different objects. My time variable is in terms of trial number for a particular object, with independent numbering per object:

subjectID, sex, group, memErr, object, objTrialNo
       1,    M,   ctl,   0.32,   obj1,     1
       1,    M,   ctl,   0.23,   obj1,     2
       1,    M,   ctl,   0.67,   obj2,     1
       1,    M,   ctl,   0.44,   obj2,     2

I'm not sure how I need to specify the random effect term to capture this "multiple" interleaved time series, for lack of the correct term. That is, how do I capture the fact that the time is a counter that resets for each object?

Would the following be appropriate? (When I plot my memory error, memErr, against time, objTrialNo, I see there is what looks like an exponential decay -- hence all the transformations).

I(log(memErr)) ~ grp * sex * I(objTrialNo^2) + (1+object|subject) + (0+objTrialNo|object)

From what I understand, 0+ is okay (model won't converge otherwise) because at time 0, error is maximum anyway.

However, when I run this model, the residuals vs. fitted plot shows model seems heteroskedastic (and qqnorm plot of residuals indicates non-normality)? residVSfitted

Thanks very much in advance for any advice/tips/help!


1 Answer 1


What you have now doesn't seem appropriate to me. For one thing, you can't have object listed both on the left and right hand side of the | operator.

If you have enough objects (say, 5 or more) and are willing to view them as representative of a larger set of objects in which you are really interested from an inferential viewpoint, then you could consider that both subject and object are two random grouping variables. (The subjects included in your study would also be representative of a larger set of subjects in which you are really interested in terms of inferences.)

If each subject in your study sees all objects included in the study, then the random grouping factors subject and object are fully crossed. If each subject sees only some of the objects included in the study, then the random grouping factors are only partially crossed. Either way, you would represent this in your model using syntax like:

 (1|subject) + (1|object)

There is a reason subject and object are called random grouping factors - they act as 'containers' for a group of memErr observations. In the scenario I outlined here, each subject-object combination would be a 'container' holding two memErr observations corresponding to the object viewed by that subject during the 2 trials.

Since you only have 2 trials per object, why not define objTrial as a categorical variable with 2 levels: "first" and "last" (or something like this)? Then the right side of your model could look like this:

grp * sex * objTrial + (1|subject) + (1|object)

On the left-hand side of the model, perhaps start off by using memErr (untransformed) and see what the model residuals look like. If the residuals have a skewed distribution, then consider transforming memErr.

If the situation described above does not capture your study design, you will need to provide further details to enable others on this forum to help you.

  • $\begingroup$ Thank you for the answer! I will try and be clearer. All subjects see the same 8 objects. The task was self paced, so the number of trials per object vary from subject but are on the order of 25-50 trials -- and for this reason I was hoping to analyze each object as a separate time series. $\endgroup$
    – gj.
    Mar 17, 2019 at 9:17
  • $\begingroup$ I wanted to make sure that each object's time series is treated separately - thought I needed to capture this in a random term? I did try untransformed variables (residuals had fanned distrib). So my question is two fold -- how do I capture multiple time series and what can I infer from the resid vs. fitted plot to troubleshoot my model? Why can't you have object on the left and right of |? Thanks again $\endgroup$
    – gj.
    Mar 17, 2019 at 9:41

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.