错误:无法评估模型框架内的分组因子 X:如果可能,尝试将分组因子显式添加到数据框中

问题描述

我试图在 lme4 的占用率中拟合一个二元线性混合模型,作为 acd 和 N_days 的乘积。由于我的抽样设计,有很多嵌套因素我想作为嵌套随机效应进行拟合。

这是数据框的几行:

important_data

和结构:

    X         sample FirstOrder SecondOrder Site        family occupancy      acd N_days       date
1  57 A_1_02/03/2013        A_1       A_580    A Staphylinidae         0 28.50894      3 02/03/2013
2 118 A_1_02/11/2011        A_1       A_580    A Staphylinidae         1 28.50894      5 02/11/2011
3 119 A_1_02/11/2011        A_1       A_580    A Staphylinidae         1 28.50894      3 02/11/2011
4 120 A_1_02/11/2011        A_1       A_580    A Staphylinidae         1 28.50894      3 02/11/2011
5 121 A_1_02/11/2011        A_1       A_580    A Staphylinidae         1 28.50894      3 02/11/2011
6 122 A_1_02/11/2011        A_1       A_580    A Staphylinidae         1 28.50894      3 02/11/2011
  field_name unique_ID
1         34        NA
2         41     14587
3         53     14587
4         54     14588
5         55     14589
6         56     14590

我使用显式嵌套来拟合我的模型:

'data.frame':   18608 obs. of  12 variables:
 $ X          : int  57 118 119 120 121 122 123 124 125 126 ...
 $ sample     : Factor w/ 1763 levels "A_1_02/03/2013",..: 1 2 2 2 2 2 2 2 2 2 ...
 $ FirstOrder : Factor w/ 576 levels "A_1","A_10","A_11",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ SecondOrder: Factor w/ 193 levels "A_580","A_581",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ Site       : Factor w/ 17 levels "A","B","C","D",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ family     : Factor w/ 59 levels "Aderidae","Anobiidae",..: 56 56 56 56 56 56 56 56 56 56 ...
 $ occupancy  : int  0 1 1 1 1 1 1 1 1 1 ...
 $ acd        : num  28.5 28.5 28.5 28.5 28.5 ...
 $ N_days     : int  3 5 3 3 3 3 3 3 3 3 ...
 $ date       : Factor w/ 64 levels "01/03/2013","01/08/2013",..: 4 5 5 5 5 5 5 5 5 5 ...
 $ field_name : int  34 41 53 54 55 56 57 58 59 60 ...
 $ unique_ID  : int  NA 14587 14587 14588 14589 14590 14591 14592 14593 14594 ...

但是当我运行模型时出现错误

staph_model <- glmer(formula = occupancy~acd+N_days+(1|Site)+(1|Site:SecondOrder)+(1|Site:SecondOrder:FirstOrder)+(1|Site:SecondOrder:FirstOrder:sample),data = staphylinidae,family = binomial(link = "logit"))

关于为什么会发生这种情况,我找不到任何明确的答案?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)