1
$\begingroup$

I have a dependent variable: rtln (log transformed reaction time) and 3 predictors: choicenum (ranging from 1 to 6), ifrelevant (0 and 1), and condition (0 and 1), and I have a variable with subject IDs.

I would like to estimate a model where choicenum is nested within subjects. I use the following notation:

lmer(rtln~choicenum + ifrelevant + condition 
 + (1|subject/choicenum),    data=myData)

for some reason this estimates 5 fixed effects for choicenum.

$\endgroup$
5
  • 2
    $\begingroup$ you seem to be posting the same question using different variable names, see here and here. $\endgroup$
    – wolf.rauch
    Commented Jul 18, 2011 at 23:20
  • 1
    $\begingroup$ so are you really sure you want to have choicenum nested within subject? $\endgroup$
    – wolf.rauch
    Commented Jul 18, 2011 at 23:22
  • $\begingroup$ @wolf.rauch yes I want to have the exact same output as in stata. I want two grouping factors nested within each other. $\endgroup$
    – DBR
    Commented Jul 18, 2011 at 23:32
  • 1
    $\begingroup$ Your stata output has ifIncongruent as a numeric variable. It does not correspond to your question here. You should make more of an effort to describe what you want. $\endgroup$
    – wolf.rauch
    Commented Jul 18, 2011 at 23:52
  • $\begingroup$ @wolf.rauch I'm terribly sorry, I provided the wrong output. I've edited the question with the new (correct output) $\endgroup$
    – DBR
    Commented Jul 18, 2011 at 23:58

1 Answer 1

2
$\begingroup$

I guess that you have specified choicenum as a factor, but you assume that it is numeric.

If you specify choicenum as a factor in the fixed effects part, lmer will --- as you should know from the help pages of lmer, lm and the R Introduction, estimate effects comparing all factor levels to a 'baseline' level (see ?contr.treatment and ?contrasts), so that is why you get 5 entries for choicenum in the fixed effects part.

But you need a factor in the random effects part of the equation for lmer. So you might try the following:

First, specify choicenum as numeric in your data.frame. Then, run

m1 <- lmer(rtln~choicenum + ifrelevant + condition + (1|subject/as.factor(choicenum)), 
  data= YourData)

Of course you could also specify ... as.numeric(choicenum) ...

$\endgroup$
7
  • $\begingroup$ I have specified choicenum<-as.numeric(choicenum) and then entered the code you pasted. R just freezes and processes for ever. Did you manage to run this code? $\endgroup$
    – DBR
    Commented Jul 19, 2011 at 0:51
  • $\begingroup$ problem solved: first specify subject as factor choicenum as numeric and then your code works. thank you for resolving this problem, this finally solves every question for all of my posts $\endgroup$
    – DBR
    Commented Jul 19, 2011 at 0:59
  • $\begingroup$ @wolf.rauch Do you know any literature that shows that a grouping variable (choicenum) can also be included as a fixed effect? As far as I know, it makes no sense but I may be wrong... $\endgroup$ Commented Jul 19, 2011 at 10:35
  • $\begingroup$ @Bernd-Weiss: As far as I understood DBR’s design, choicenum is a within-subjects ordered factor, so there should be no problem about its fixed effect. I had my problems with choicenum as a grouping factor, but now I think it might make a little sense. Beside its fixed effects, there might be different between-subjects variances at each level of choicenum. $\endgroup$
    – wolf.rauch
    Commented Jul 19, 2011 at 16:58
  • 1
    $\begingroup$ @Bernd-Weiss: yes, I know about the schools/classes :-) I have that problem too. Try to think of every student (student in N) being taught by every teacher (in M) with N>>M, and there are repeated measures for students:teachers. Each teacher has a "fixed effect" (i.e. some are "better" than others), and there is also variability of the teacher effect within students. And yes, I think that it makes more sense to include a random coefficient for choicenum instead of a grouping factor. $\endgroup$
    – wolf.rauch
    Commented Jul 19, 2011 at 22:48

Your Answer

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