In my design, I have two groups of subjects and every subject is tested in four different conditions. So, I have a within-subject factor ('span_num', which ranges from 0 to 3) and a between-subject factor (group, which can be 'Linear' or 'U-shape').

My goal is to show that the slope between the spans (from 0 to 3) is higher in the Linear group than in the U-shape group.

The slopes look very different and are significantly different when I compare the regression models I get when I ignore that my within-factor is a within-factor and treat it as a between-factor.

I compared the slopes like this (but I don't trust the comparison because I don't trust the SE values of the slopes because I am treating my within-factor like a between-factor):

linear_lm <- lm(RT ~ span_num, dat = data[data$group == "Linear",])
ushape_lm <- lm(RT ~ span_num, dat = data[data$group == "U-shape",])
linear_intercept <- summary(linear_lm)$coefficients[[1]]; linear_ise <- summary(linear_lm)$coefficients[[3]]; linear_slope <- summary(linear_lm)$coefficients[[2]]; linear_sse <- summary(linear_lm)$coefficients[[4]]
ushape_intercept <- summary(ushape_lm)$coefficients[[1]]; ushape_ise <- summary(ushape_lm)$coefficients[[3]]; ushape_slope <- summary(ushape_lm)$coefficients[[2]]; ushape_sse <- summary(ushape_lm)$coefficients[[4]]

z_intercept <- (ushape_intercept - linear_intercept) / sqrt(linear_ise^2 + ushape_ise^2)   #z = -0.45; p = .67, n.s.
z_slope <- (ushape_slope - linear_slope) / sqrt(linear_sse^2 + ushape_sse^2)   #z = -1.50; p = .93, sig.
  • 1
    $\begingroup$ You have "repeated measures" in your title, but don't use packages nlme or lme4. Seek advice from a statistician. $\endgroup$
    – Roland
    Aug 26, 2014 at 7:25

1 Answer 1


You should probably use a linear mixed model to fit a random-slopes model:

m1 <- lme(RT ~ span_num*group,
          random = ~span_num|subject, data=data)

(You need to be careful here as I believe summary.lme gets the denominator degrees of freedom wrong for random-slopes models. If you have a large (>40) total number of subjects it won't matter much.)


m2 <- lmer(RT ~ span_num*group+(span_num|subject),
           data=data, method="ML")

The latter case ignores the denominator DF issue entirely. pbkrtest::KRmodcomp gets it right.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.