【问题标题】:Error message when running mixed effect models using R-INLA使用 R-INLA 运行混合效应模型时出现错误消息
【发布时间】:2020-09-07 13:47:39
【问题描述】:

我正在使用 R-INLA 运行以下模型(Treatment、Animal.1 和 Animal.2 是因子,Encounter.Length 是连续的):

formula <- Encounter.Length ~ Treatment +f(Animal.1, model = "iid", n = n.animal) + 
           f(Animal.2, copy = "Animal.1")

m.1 <- inla(formula, data = inla.dat)

但是,运行此代码后,我收到以下错误消息:

inla 中的错误(公式,数据 = inla.dat): 在 f(Animal.1) 中:“协变量”必须匹配“值”,并且两者都必须是“数字”或“因子”/“字符”。

我是使用 INLA 的新手,想知道此错误消息的含义以及如何修复它。

【问题讨论】:

    标签: r mixed-models r-inla


    【解决方案1】:

    答案(来自 r-inla.help):B 的级别不是 A 的子集(用于定义模型,B 为其复制)。所以你必须在层次上定义联合模型。

    例如:

    n <- 3 
    A <- as.factor(letters[1:n]) 
    B <- as.factor(letters[1+1:n]) 
    y <- 1:n 
    

    这不起作用

    inla(y ~ -1 + f(A) + f(B, copy = "A"), data = data.frame(A, B)) 
    

    但这确实

    values <- as.factor(unique(c(levels(A), levels(B)))) 
    inla(y ~ -1 + f(A, values = values) + f(B, copy = "A"), 
    data = list(A = A, B = B, values = values))
    

    【讨论】:

      猜你喜欢
      • 2021-10-04
      • 2019-09-19
      • 2019-10-09
      • 1970-01-01
      • 2021-06-12
      • 2017-12-10
      • 2013-04-23
      • 1970-01-01
      • 2015-12-07
      相关资源
      最近更新 更多