Dear R-experts!

I having trouble with the correct implementation of a mixed-model ANOVA in
R.

I my dataset subjects were tested in a cognitive performance test
(numerical outcome variable 'score'). This cognitive performance test is
devided into five blocks (categorical factor 'block').  All subjects were
tested two times in the cognitive performance test (in random order once
following placebo treatment and once following drug treatment: categorical
factor 'treatment'). In order to account for re-test effects I coded the
testing session (categorical factor 'session' with 1 coding for the first
and 2 coding for the second session).
Also all subjects once underwent a blood screening before the study in
which a stable blood marker was measured which is hypothesized to mediate
treatment effects (covariate 'blood').

I would like to look for treatment effects on my outcome variable 'score'
and whether the treatment effect is mediated by the covariate 'blood'. Also
I would like to use 'subject' as a random factor, include 'block' as a
within-subjects factor as performance is hypothesized to increase over
blocks and control for re-test/learning effects by including 'session' as a
within-subjects factor.

I would like to use lmer() for the model formulation as my data is
unbalanced (different number of subjects who first received drug and
subjects who first received placebo - I have been told aov() cannot handle
such data) and due to the fixed- and random-effects. Please find below some
dummy data and initially model formulation.

My questions are:

1. Can I include a random-effect 'subject' AND look for moderating effects
of 'blood' even though there is only one 'blood' measurement per subject?

2. Please note that the data (repeated-measures) is not aggregated. I hope
this is correct?

3. Could you advice me regarding the proper implementation of my model?


Many thanks & best wishes,
Jokel

# some dummy data
data <- structure(list(subject = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L), .Label = c("1", "2", "3", "4", "5"), class = "factor"),
    block = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L,
    3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L,
    1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L,
    2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
    2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L,
    3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L,
    1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L,
    2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
    2L, 3L, 3L, 3L, 3L), .Label = c("1", "2", "3"), class = "factor"),
    treatment = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L, 2L, 2L, 2L, 2L), .Label = c("drug", "placebo"), class =
"factor"),
    session = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L, 2L, 2L, 2L, 2L), .Label = c("1st", "2nd"), class = "factor"),
    blood = c(4.58, 4.58, 4.58, 4.58, 4.58, 4.58, 4.58, 4.58,
    4.58, 4.58, 4.58, 4.58, 4.58, 4.58, 4.58, 4.58, 4.58, 4.58,
    4.58, 4.58, 4.58, 4.58, 4.58, 4.58, 4.88, 4.88, 4.88, 4.88,
    4.88, 4.88, 4.88, 4.88, 4.88, 4.88, 4.88, 4.88, 4.88, 4.88,
    4.88, 4.88, 4.88, 4.88, 4.88, 4.88, 4.88, 4.88, 4.88, 4.88,
    5.27, 5.27, 5.27, 5.27, 5.27, 5.27, 5.27, 5.27, 5.27, 5.27,
    5.27, 5.27, 5.27, 5.27, 5.27, 5.27, 5.27, 5.27, 5.27, 5.27,
    5.27, 5.27, 5.27, 5.27, 5.3, 5.3, 5.3, 5.3, 5.3, 5.3, 5.3,
    5.3, 5.3, 5.3, 5.3, 5.3, 5.3, 5.3, 5.3, 5.3, 5.3, 5.3, 5.3,
    5.3, 5.3, 5.3, 5.3, 5.3, 5.62, 5.62, 5.62, 5.62, 5.62, 5.62,
    5.62, 5.62, 5.62, 5.62, 5.62, 5.62, 5.62, 5.62, 5.62, 5.62,
    5.62, 5.62, 5.62, 5.62, 5.62, 5.62, 5.62, 5.62), score = c(8.99,
    8.81, 10, 9.04, 9.4, 9.73, 10.98, 9.22, 8.27, 8.87, 8.59,
    9.55, 11, 10.4, 9.89, 8.97, 7.94, 12.26, 10.54, 9.83, 9.57,
    9.75, 11.99, 9.22, 9.71, 9.96, 10.3, 10.49, 10.22, 10.52,
    9.87, 11.31, 10.02, 11.32, 10.67, 11.35, 9.76, 8.57, 10.62,
    7.44, 9.54, 9.54, 8.35, 7.66, 8.62, 10.78, 9.95, 10.51, 10.29,
    10.58, 11.19, 11.64, 11.41, 10.05, 8.92, 10.79, 10.56, 9.85,
    9.49, 9.25, 8.36, 10.33, 11.41, 9.27, 12.16, 10.49, 8.08,
    10.58, 10.26, 8.99, 9.97, 9.14, 11.35, 10.15, 8.42, 9.23,
    10.28, 10.19, 9.18, 10.86, 11.79, 9.36, 8.91, 11.15, 9.54,
    8.5, 9.18, 9.75, 10.37, 10.28, 9.96, 10.34, 9.1, 9.73, 10.24,
    10.12, 9.21, 9.94, 11.5, 10.33, 9.72, 10.37, 11.43, 10.14,
    9.75, 10.58, 10.16, 9.19, 11.1, 10.3, 8.59, 8.46, 9.18, 9.44,
    10.72, 10.65, 10.53, 8.97, 8.77, 9.71)), .Names = c("subject",
"block", "treatment", "session", "blood", "score"), row.names = c(4L,
34L, 64L, 94L, 5L, 35L, 65L, 95L, 6L, 36L, 66L, 96L, 1L, 31L,
61L, 91L, 2L, 32L, 62L, 92L, 3L, 33L, 63L, 93L, 10L, 40L, 70L,
100L, 11L, 41L, 71L, 101L, 12L, 42L, 72L, 102L, 7L, 37L, 67L,
97L, 8L, 38L, 68L, 98L, 9L, 39L, 69L, 99L, 16L, 46L, 76L, 106L,
17L, 47L, 77L, 107L, 18L, 48L, 78L, 108L, 13L, 43L, 73L, 103L,
14L, 44L, 74L, 104L, 15L, 45L, 75L, 105L, 19L, 49L, 79L, 109L,
20L, 50L, 80L, 110L, 21L, 51L, 81L, 111L, 22L, 52L, 82L, 112L,
23L, 53L, 83L, 113L, 24L, 54L, 84L, 114L, 25L, 55L, 85L, 115L,
26L, 56L, 86L, 116L, 27L, 57L, 87L, 117L, 28L, 58L, 88L, 118L,
29L, 59L, 89L, 119L, 30L, 60L, 90L, 120L), class = "data.frame")

# some first try
library(lme4)
fm1 <- lmer(score ~ 1 + treatment + session + block + blood +(1|subject),
data=data)
summary(fm1)

	[[alternative HTML version deleted]]

