2

I am trying to use the lmer function to investigate if there is an interaction effect on the reaction time (RT) between 3 different conditions (cond=0, 1, 2) and the presence of the target (target=False or True) in patients (Patient).

I wrote the following equation:

lmer(RT~cond*target+(1|Patient))

My problem is that the default intercept for this function is cond = 0 and target = False, whereas I would like the intercept to be cond= 0 and target=True (in order to see if there is a significant difference between cond0*target=True and cond1*target=True).

I would really appreciate your help.

Here is the output I have

stu3<-lmer(RT~cond*target+(1|Patient), 
   data=subset(ss, Groupe=="ugs" & primeable ==TRUE     & 
          Correct==TRUE & NoPrac==TRUE))

pvals.fnc(stu3)


$fixed
                  Estimate MCMCmean HPD95lower HPD95upper  pMCMC Pr(>|t|)
(Intercept)         0.5511   0.5513     0.5258     0.5807 0.0001   0.0000
cond1               0.0618   0.0619     0.0498     0.0741 0.0001   0.0000
cond2               0.0285   0.0285     0.0142     0.0438 0.0002   0.0001
targetFALSE         0.1389   0.1389     0.1239     0.1549 0.0001   0.0000
cond1:targetFALSE  -0.0752  -0.0751    -0.0943    -0.0545 0.0001   0.0000
cond2:targetFALSE  -0.0788  -0.0786    -0.0998    -0.0564 0.0001   0.0000

$random
    Groups        Name Std.Dev. MCMCmedian MCMCmean HPD95lower HPD95upper
1  Patient (Intercept)   0.0610     0.0583   0.0599     0.0425     0.0797
2 Residual               0.1674     0.1674   0.1674     0.1650     0.1699

Based on my data, the intercept being chosen is cond0:targetTRUE and the other levels in the output are cond1:targetFALSE and cond2:targetFALSE.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
Alba
  • 193
  • 1
  • 2
  • 8
  • so the `cond1` parameter should exactly correspond to a test of the difference between `cond==0` and `cond==1` when `target` is `TRUE` (provided that you haven't done anything else clever with your contrasts ...), which is what it sounds like you wanted. – Ben Bolker Feb 27 '13 at 23:53

2 Answers2

1

See if standard "factor management" is effective:

target=factor(target, levels=c("TRUE", "FALSE")
lmer(RT~cond*target+(1|Patient))

(I would have used the phrase "changing the reference levels" rather than "changing the intercept", but I suppose it's really the same process. I suspect the phrase "change reference level" would have gotten you quite few hits on a MarkMail Rhelp or SO search.)

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • and be careful with exact matches of the levels -- i.e. are your factor levels `TRUE` and `FALSE`, or `"True"` and `"False"`, or `"TRUE"` and `"FALSE"` ... ? – Ben Bolker Feb 27 '13 at 20:54
  • I constructed my advice on the assumption that 'target' was a logical vector, In which case they would have been as written, but if they were factors spelled as Ben fears (and as you wrote) then do follow his advice and make sure they match the spelling. It's always best to provide str() on your data elements. – IRTFM Feb 27 '13 at 20:59
  • The factor levels are TRUE and FALSE Ben. I tried to follow your advice DWin but it only switches things around: this time the intercept is the interaction cond0*targetTrue but it compares it to cond1*targetFalse. – Alba Feb 27 '13 at 21:07
  • I suspect you don't understand what the output means. The coefficients in a model with interactions are NOT comparisons. – IRTFM Feb 27 '13 at 21:12
  • I might not have expressed myself well, sorry. But the problem still holds, I need the interactions in the levels to be the same as the level of reference in order to evaluate if there is a significant difference between the conditions and the presence of the target. But thank you for clarifying my phrasing mistake Dwin. – Alba Feb 27 '13 at 21:22
  • I think we need to see full output and I also wonder if this might be better conducted on CrossValidated because I am still of the opinion that we no longer have coding issues to resolve but rather conceptual ones. – IRTFM Feb 27 '13 at 21:24
1

If I understood correctly, your model is already doing the interpretation you would wish to have inside target==TRUE. If I am correct, you could translate the model terms in your example as follows:

"(Intercept)"       -> target==TRUE, cond==0 (even if model matrix contains all conds)
"cond1"             -> target==TRUE, cond==1 on top of cond==0
"cond2"             -> target==TRUE, cond==2 on top of cond==0
"targetFALSE"       -> target==FALSE, cond==0 (even if model matrix contains all conds)
"cond1:targetFALSE" -> target==FALSE, cond==1 on top of cond==0
"cond2:targetFALSE" -> target==FALSE, cond==2 on top of cond==0

So isn't the interesting difference detected in terms "(Intercept)", "cond1" and "cond2"? Taking a look at the fixed effects' model matrix structure in getME(stu3,'X') may be helpful.

Below is an example data I constructed to test your case. Notice that I built three different responses: one without any effect, one with just target==TRUE effect, and one with an effect for target==TRUE and an interaction effect with target==TRUE and the different levels of cond. The artificially introduced effect is detected in fit1 and fit2:

set.seed(0)
struct <- expand.grid(target = c(FALSE,TRUE), cond = as.factor(0:2), patient = LETTERS[1:20])
attach(struct)
ranpatient <- rep(rnorm(20), each=6)
rerror <- rnorm(120)
# Just random noise
response0 <- ranpatient + rerror
# When target==TRUE we increment the response by 1 and add errors
response1 <- 1*target + ranpatient + rerror
# When target==TRUE we increment the response by  1,
# to which we also add an interaction effect condition {0,1,2} * target {0,1}
# notice that numeric transformation of cond {0,1,2} transforms to ranks {1,2,3}
response2 <- 1*target + target*(as.numeric(cond)-1) + ranpatient + rerror

dat <- data.frame(cond, target, patient, response0, response1, response2)   
detach(struct)

require(lme4)
fit0 <- lmer(response0 ~ cond*target + (1|patient), data=dat)
fit1 <- lmer(response1 ~ cond*target + (1|patient), data=dat)
fit2 <- lmer(response2 ~ cond*target + (1|patient), data=dat)

head(dat)
round(coef(summary(fit0)),2) # Notice low t values
round(coef(summary(fit1)),2) # High t value for targetTRUE
round(coef(summary(fit2)),2) # High t value for interaction cond0/1/2 with targetTRUE
# Notice how cond==1 adds 1, and cond==2 adds 2 in comparison to cond==0 when targetTRUE
# Notice also that coefficient "cond2:targetTRUE" is incremental to term "targetTRUE", not "cond1:targetTRUE"
head(getME(fit2,'X')) # Columns correspond to the fixed effect terms

With the output

> head(dat)
  cond target patient response0 response1 response2
1    0  FALSE       A  1.038686  1.038686  1.038686
2    0   TRUE       A  1.640350  2.640350  2.640350
3    1  FALSE       A  1.396291  1.396291  1.396291
4    1   TRUE       A  2.067144  3.067144  4.067144
5    2  FALSE       A  1.205848  1.205848  1.205848
6    2   TRUE       A  1.766562  2.766562  4.766562
> round(coef(summary(fit0)),2) # Notice low t values
                 Estimate Std. Error t value
(Intercept)         -0.13       0.31   -0.40
cond1                0.18       0.29    0.62
cond2                0.00       0.29    0.00
targetTRUE           0.00       0.29   -0.01
cond1:targetTRUE     0.13       0.41    0.32
cond2:targetTRUE     0.08       0.41    0.19
> round(coef(summary(fit1)),2) # High t value for targetTRUE
                 Estimate Std. Error t value
(Intercept)         -0.13       0.31   -0.40
cond1                0.18       0.29    0.62
cond2                0.00       0.29    0.00
targetTRUE           1.00       0.29    3.42
cond1:targetTRUE     0.13       0.41    0.32
cond2:targetTRUE     0.08       0.41    0.19
> round(coef(summary(fit2)),2) # High t value for interaction cond0/1/2 with targetTRUE
                 Estimate Std. Error t value
(Intercept)         -0.13       0.31   -0.40
cond1                0.18       0.29    0.62
cond2                0.00       0.29    0.00
targetTRUE           1.00       0.29    3.42
cond1:targetTRUE     1.13       0.41    2.75
cond2:targetTRUE     2.08       0.41    5.04
> # Notice how cond==1 adds 1, and cond==2 adds 2 in comparison to cond==0 when targetTRUE
> # Notice also that coefficient "cond2:targetTRUE" is incremental to term "targetTRUE", not "cond1:targetTRUE"
> head(getME(fit2,'X')) # Columns correspond to the fixed effect terms
     [,1] [,2] [,3] [,4] [,5] [,6]
[1,]    1    0    0    0    0    0
[2,]    1    0    0    1    0    0
[3,]    1    1    0    0    0    0
[4,]    1    1    0    1    1    0
[5,]    1    0    1    0    0    0
[6,]    1    0    1    1    0    1
Teemu Daniel Laajala
  • 2,316
  • 1
  • 26
  • 37
  • 1
    this all makes sense to me. The only adjustment I would ask is to use the accessor methods: `coef(summary())` rather than `@coefs` and `getME(.,"X")` rather than `@X` – Ben Bolker Feb 28 '13 at 13:33
  • Thanks for the suggestion! I'll keep it in mind. I now corrected the above code and output. – Teemu Daniel Laajala Feb 28 '13 at 14:18