admin管理员组文章数量:1123412
I'm facing the following issue in R and I don't know how to solve it:
I want to run linear mixed model to model reaction time as function of group and task. When trying to run the model
lmm.reaction.time.LT.RT.PD.CG <- lmer(
reaction_time ~ group * task +
PANDA.total + FSS + education.years +
PANDA.mood +
(1 + group * task | subject_nr) +
(1 + group * task | sentence),
data = df.master.correct.responses.no.rt.outliers.LT.RT.PD.CG.copy)
I get this error warning:
Error in contrasts<-(tmp, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels
All my predictors have at least two levels:
contrasts(df.master.correct.responses.no.rt.outliers.LT.RT.PD.CG.copy$group)
contrasts(df.master.correct.responses.no.rt.outliers.LT.RT.PD.CG.copy$task)
[,1]
CG 1
PD -1
[,1]
LT 1
RT -1
Simplifying the random structures did not work as following model led to same error warning:
lmm.reaction.time.LT.RT.PD.CG <- lmer(
reaction_time ~ group * task +
PANDA.total + FSS + education.years +
PANDA.mood +
(1 | subject_nr) +
(1 | sentence),
data = df.master.correct.responses.no.rt.outliers.LT.RT.PD.CG.copy)
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
I tried to run the model with an other predictor instead of task.sum and it worked, so I think the issue comes from this variable, which has two levels (RT: reaction time task, and LT: language task)
As the RT had fewer trials than the LT there is a strong imbalance between these two levels, which might cause this issues?
table(df.master.correct.responses.no.rt.outliers.LT.RT.PD.CG.copy$group, +
df.master.correct.responses.no.rt.outliers.LT.RT.PD.CG.copy$task)
LT RT
CG 4341 724
PD 3955 791
My data frame looks something like this (I'm only showing the relevant columns and some example rows):
subject_nr group sentence condition reaction_time education.years PANDA.total PANDA.mood FSS.a task
CG01 CG 43lf lf 3.433987 12 25 2 23 LT
CG01 CG 43sf sf 7.078342 12 25 2 23 LT
CG01 CG 45sc sc 6.137727 12 25 2 23 LT
CG01 CG NA left 7.198184 12 25 2 23 RT
PD12 PD 47sf sf 6.658011 11 28 3 57 LT
PD12 PD 13lc lc 5.986452 11 28 3 57 LT
PD12 PD NA right 6.920672 11 28 3 57 RT
Is there another reason that could cause this error?
Maybe the NAs in column "sentence" as "sentence" is used for random structure?
If the error occurs due to the imbalance of data points between these two tasks is there a way to structure my data frame in another way to be able to run the model?
本文标签:
版权声明:本文标题:r - Error in `contrasts<-`(`*tmp*`,value=contr.funs[1+isOF[nn]]): contrasts can be applied only to factors with 2 or more 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736567424a1944724.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论