我一直尝试使用四向交互执行有序逻辑回归并获取错误消息:
设计错误(eval.parent(m)):交互术语不是秒或 第三顺序
设计是: 因变量: 发展阶段 - 5个级别编号为1-5
自变量: 年龄 - 收集数据的4个不同年龄点; 祖先 - 2个类别编号为1& 2; 饲养环境 - 编号为1和2的2个类别2; 当前环境 - 编号为1和2的2个类别2
由于存在伪复制的可能性,因此模型由" Colony"进行集群运行。
因此,我一直试图使用的代码是:
library(rms)
Data$Ancestry <- factor(Data$Ancestry)
Data$Rearing <- factor(Data$Rearing)
Data$Queenless <- factor(Data$Queenless)
m <- lrm(Level ~ Age * Ancestry * Rearing * Queenless, x=T, y=T, dat = Data)
robcov(m, cluster = Data$Colony)
我假设错误消息意味着lrm不支持4向交互。还有另一种方法吗?我没有在线搜索备用解决方案的运气,我知道我在尝试使用polr函数进行聚类时遇到了问题。
非常感谢你的帮助。
这是我的数据:
structure(list(Bee.Age = c(8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L), Colony = structure(c(1L, 1L, 1L, 1L, 5L, 5L,
5L, 5L, 2L, 2L, 2L, 2L, 6L, 6L, 6L, 6L, 1L, 1L, 1L, 1L, 9L, 9L,
9L, 9L, 2L, 2L, 2L, 2L, 10L, 10L, 10L, 10L, 3L, 3L, 3L, 3L, 7L,
7L, 7L, 7L, 4L, 4L, 4L, 4L, 8L, 8L, 8L, 8L, 3L, 3L, 3L, 3L, 7L,
7L, 7L, 7L, 4L, 4L, 4L, 4L, 8L, 8L, 8L, 8L, 1L, 1L, 1L, 1L, 5L,
5L, 5L, 5L, 2L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L, 5L, 5L, 4L, 5L, 5L,
5L, 5L, 2L, 5L, 4L, 4L, 5L, 3L, 5L, 4L, 4L, 5L, 4L, 5L, 2L,
4L, 5L, 4L, 5L, 4L, 5L, 4L, 5L), X = c(NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA
)), .Names = c("Bee.Age", "Colony", "Ancestry", "Queenless",
"Rearing", "LevelOA", "X"), row.names = c(NA, -320L), class = "data.frame")
&#13;
答案 0 :(得分:1)
这只是部分答案。
如果您需要使用群集数据拟合序数模型,则可以使用ordinal
包:
流程数据:
library(ordinal)
Data <- transform(Data,
Ancestry=factor(Ancestry),
Rearing=factor(Rearing),
Queenless=factor(Queenless),
LevelOA=ordered(LevelOA))
这里唯一的特殊要点是响应变量需要是有序因子(ordered()
)。
ordinal
中有两个版本的群集累积链接模型(您可以在包的帮助文件中了解他们的选项):
c1 <- clmm(LevelOA ~ Bee.Age*Ancestry*Rearing*Queenless + (1|Colony),
dat = Data)
c2 <- clmm2(ordered(LevelOA) ~ Bee.Age*Ancestry*Rearing*Queenless,
random = Colony, data= Data, Hess=TRUE)
这两个都给出了估计值,但没有给出标准偏差 - 我认为模型过于复杂,SD计算出现了问题,但需要做更多工作(可能还有更多)才能弄明白。对于两个模型(标准差大约2.7e-5),估计的种群间方差也几乎/实际为零,这意味着作为初步,您可以使用MASS::polr
来拟合模型而不进行聚类:< / p>
c0 <- polr(LevelOA ~ Bee.Age * Ancestry * Rearing * Queenless,
dat = Data)
因为估计的种群间方差为零,所以这给出了与ordinal
函数相同的系数估计值。