# Multilevel modeling: longitudinal data with within-subjects factors

I have a data set with experimental data that I am analysing with multilevel modeling. Data are structured as follows:

• 24 Sessions
• 6 Subjects per Session
• 10 Rounds per Subject

There was one between-subjects variable (Role: three subjects each per Session were Role 0 and Role 1) and one within-subjects variable (Treatment). Treatment varied at the Round level: five rounds each were Treatment 0 and Treatment 1. Thus, data looks as follows:

> str(data)
$Session : Factor w/ 24 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...$ Subject             : Factor w/ 144 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...
$Round : num 1 2 3 4 5 6 7 8 9 10 ...$ Role                : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
$Treatment : Factor w/ 2 levels "0","1": 1 1 1 1 1 2 2 2 2 2 ...$ Investment          : num  19 1 17 0 13 15 16 6 17 14 ...

I am fitting a three-level mixed-effects model using the R package lme4 and the function lmer() (largely following Douglas Bates' lme4 book). The following code is for a model with correlated random effects:

model.1 <- lmer(Investment ~ 1 + Treatment + Role + Round +
(1 + Round|Subject) + (1 + Round|Session),
data=data, REML=TRUE, na.action=na.omit)

Now, my longitudinal data consists of 2×5 Rounds per Subject, and the above code does not (in my understanding) take that into account.

One attempt to remedy this was to recode the Round variable s.th. Round is numbered 1:5:

\$ Round               : num  1 2 3 4 5 1 2 3 4 5 ...

However, I assume (but am not sure, for failure of finding relevant instructions/examples) that I would have to explicitly implement an interaction effect. Therefore my question: what would be the correct way to implement a multilevel model in which longitudinal data clustered within subjects is split by a within-subjects factor?

Simulated data and example code are here.

• I'm having trouble figuring this out. Surely "Round" is the lowest level -- so the "investment" response is measured on each round. The levels are Session - Person - Round. If that's the case, you don't need to include Round in the model. But if not, then where do you take the outcome measurement? – Placidia Jun 3 '14 at 3:39
• @Placidia Round is indeed the lowest level, and Investment is the response measured each round. In including Round in the model, I am following the instructions by Bates for a longitudinal (two-level) model with correlated random effects (sidenote: just realised I wrote "correlated fixed effects" in the question; I edited that). The code Bates supplies (using the sleepstudy data set) is fm06 <- lmer(Reaction ~ 1 + Days + (1 + Days|Subject), sleepstudy, REML=FALSE) – simoncolumbus Jun 3 '14 at 8:59

I tried the sample code that you posted and the first model, in which Round goes from 1 - 10 fails. You don't get convergence and a lot of parameters come out as 0. Role=2 always corresponds to Round=6-10, which is the source of the problem.

You basically have 5 rounds for each Person/Treatment, so it's best to label the rounds 1 through 5, as you then did.

So now, your model predicts that the mean level of Investment depends on the sessions (randomly), the subject(randomly), the treatment and the role. There is also a linear effect in "Round" - the slope of Round varies in accordance with the subject and the session.

You do not include any fixed interaction effects, or random ones. Nor is the relationship to Round affected by Treatment or Role.

• First of all, thank you for your effort. I just tried it again, and I cannot replicate the failure of convergence with my code and example data. Beyond that, the Slope should vary not just in accordance with Subject and Session, but also Role, I assume (since otherwise there are two times the same Round per Subject, and they are not distinguished). Does that make sense? – simoncolumbus Jun 3 '14 at 19:05
• The optimizer in lmer uses a random starting point, so does not always fail to converge. But look at your parameter values: they are basically 0. – Placidia Jun 3 '14 at 21:25

I'm working on similarly structured data and am having the same issue. I had participants within groups/sessions, and also had (four) conditions within subjects and (five) rounds within conditions. I too am unsure of whether I should treat the data as 20 rounds (four conditions and five rounds per condition) or whether I should treat it as five rounds, repeated four times.

What did you end up doing with your data? Any updates? Hearing what you ultimately did would likely help me out.

• Hi psyjoseph and welcome to the site! Your answer looks more like a comment to the original question. Please consider deleting this answer and re-post it as a comment under the original question. Alternatively, you may ask a new question altogether. – COOLSerdash Mar 20 '15 at 19:11