我正在尝试使用 lmer
函数从 lme4
软件包中首次在R中运行线性混合效应模型,而且我一直在遇到我不喜欢的错误t知道如何解释。
现在,我有错误:
if中的错误(任何(bgrad< 0))){:缺少true/false需要的值
,而当我尝试在线查找它的含义时,我读到它与if-sause有关,但是由于我没有'写代码,我不知道如何解决(甚至理解)。
我的模型看起来像这样:
lmer(accuracy ~ emotion1 + Age + (1|item) +
(1|id) + (1+emotion1|item) + (1+Age|id), data = lib4)
如果我忽略了随机斜率,它可以正常工作,但是我想我需要它们吗?
简而言之,我想看看年龄和不同的情绪影响着对项目的判断的准确性,而我认为物品和个人都有自己的拦截和斜率(有些项目更容易评估,有些人,有些人评估更好;每个项目都会受到情绪的影响,每个项目都会受到年龄的影响?)。如果我的模型没有反映这些想法或没有意义,请告诉我!正如我所说,我是混合效果模型的新手。
我不知道这是否是您需要查看我的数据的问题,如果您这样做,我会将其发送给您。
I'm trying to run a linear mixed-effects model for the first time in R, using the lmer
function from lme4
package, and I keep getting errors that I don't know how to interpret.
Now, I got the error:
Error in if (any(bgrad < 0)) { : missing value where TRUE/FALSE needed
and when I tried to look up online what it means, I read that it has to do with an if-clause, but since I didn't write the code, I don't know how to solve (or even understand) this.
My model looks like this :
lmer(accuracy ~ emotion1 + Age + (1|item) +
(1|id) + (1+emotion1|item) + (1+Age|id), data = lib4)
and it works if I leave out the random slopes, but I think I need them ?
For a short explanation, I want to see how much age and different emotions influence the accuracy of judgment about the items, while I assume that both items and individuals also have their own intercepts and slopes (some items are easier to evaluate, and some individuals are better at evaluations ; each item might be impacted differently by emotions, and each individual by age?). If my model does not reflect these ideas or doesn't make sense as it is, please let me know too! As I say, I'm new to mixed effects models.
I don't know if this is a question for which you need to see my data, I'll send it to you if you do.
发布评论
评论(1)
您不必知道这一点,但是发生错误(转到 https://github.com/lme4/lme4/lme4/lme4 和搜索“和搜索” Bgrad”)。
我以前从未见过这个特殊错误(这是令人印象深刻的,因为我已经有一段时间已经听到了
lme4
错误了)。显然是错误的(抱歉)但易于修复的事情是您的随机效果规范
(1 | item) +(1 | id) +(1 + emotion1 | item) +(1 + age | id)是多余的;随机斜线规格
(1+emotion1 | item)
and(1+age | id)
已经包括拦截术语(并且与base-r不同, ] lm
公式,该软件包还不够聪明,无法自动删除这些冗余术语)。尝试在没有(1 | item)
和(1 | id)
的情况下重写模型,然后查看是否清除一切。这个开放性问题建议
lmer
应该尝试检查/在这些情况下警告。也就是说,我有兴趣查看可再现示例的数据,以便(希望)可以发出更有用的错误消息。
You shouldn't have to know this, but the error occurs here (go to https://github.com/lme4/lme4 and search for "bgrad").
I have not seen this particular error before (which is impressive since I've been hearing about
lme4
errors for quite a while now).The thing that's obviously wrong (sorry) but easy to fix is that your random effect specification
(1|item) + (1|id) + (1+emotion1|item) + (1+Age|id)
is redundant; the random-slopes specifications(1+emotion1|item)
and(1+Age|id)
already include the intercept terms (and unlike base-R[g]lm
formulas, the package isn't quite smart enough to drop these redundant terms automatically). Try rewriting your model without(1|item)
and(1|id)
and see if that clears things up.This open issue suggests that
lmer
should try to check for/warn in these cases.That said, I would be interested in seeing the data for a reproducible example so that (hopefully) a more useful error message can be given.