I want to analysis using lmer, glmer in R.

There is variables. In fact, I have more variables like that. I think, the data cases are sufficient.

random effect : item, test, id

using lmer; random intercept : (1+item|id);

random slope : (1+test|id);

categorical independent variables(range) : sex(1,2), item(1:20), test(1:3);I used factor()

sex=factor(sex, levels=(1:2))
item=factor(item, levels=(1:20))
test=factor(test, levels=(1:3))

independent variable : age, A_score(fixed effect)

dependent variable : test score


using glmer;

random intercept, random slope, independent variables are same.

dependent variable : score group(0,1)

result=glmer(score_group~sex+age+item+test+A_score+(1+item|id)+(1+test|id),data, family="binomial")

Is it correct? Also, if categorical dependent variable have 3 levels, what code can I use?


closed as unclear what you're asking by Nick Stauner, kjetil b halvorsen, mdewey, Michael Chernick, Juho Kokkala Dec 13 '18 at 6:37

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ I think the random intercept could be fitted for id (1|id) and any variables could be considered as variability of slopes(random slope). In addition, (item|id) and (test|id) were considered as random slopes. I recommend this code: result=glmer(score_group~factor(sex)+age+item+test+(1+item+test|id),data, family="binomial") (variable sex is a cateogorical variable, andthen you should use r function 'factor'.). Your model depends on the strategy of analysis. Which variables are considered as random or fixed effect and random intercept or random slope? $\endgroup$ – J-H Yoon Jan 16 '18 at 5:25
  • $\begingroup$ yes, I use factor() for [sex, item, test] and [item, test, id] are random effect. a_score is fixed effect. $\endgroup$ – DH.LEE Jan 16 '18 at 5:43
  • $\begingroup$ First of all, I recommend to convert each categorical variables into a factor. You can use this example code:data$item_factor = as.factor(data$item). If id was considered as a random intercept and item was considered as a random slope according to the id, you might try this code:result=glmer(score_group~sex_factor+age+item_factor+(1+item_factor|id),data, family="binomial"). This code is a simple form. You can expand the code for your purpose. $\endgroup$ – J-H Yoon Jan 16 '18 at 7:11
  • $\begingroup$ I really appreciate your reply, but my professor suggested to use like that,, random intercept(1+item|id) / random slope(1+test|id). If I have to use these two things, what should I do? $\endgroup$ – DH.LEE Jan 16 '18 at 12:35