【问题标题】:mgcv ziplss predict contrasts can be applied only to factors with 2 or more levelsmgcv ziplss predict contrasts 只能应用于具有 2 个或更多级别的因子
【发布时间】:2020-06-26 17:46:24
【问题描述】:

我使用 mgcv 包中的 gam() 拟合了一个零膨胀泊松模型

 ziplss.fit.mixed <- gam(
    list(
      n.ind ~ as.factor(data.type) + s(year) +s(enz,bs="re") + s(clc.3,bs="re") + te(lon, lat), 
      ~ as.factor(data.type) + s(year) + s(enz,bs="re") + s(clc.3,bs="re") + te(lon, lat)),
    family=ziplss(),
    data = dat,
    control = gam.control(keepData = TRUE)
  )

每次我尝试进行预测时,都会收到以下消息

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels

我什至尝试使用我用于拟合的数据进行预测。它给出了同样的错误

predict.gam(ziplss.fit.mixed, newdata = ziplss.fit.mixed$data, newdata.guaranteed = TRUE)

如果我改回具有相同公式的常规泊松游戏,那么它可以工作。

知道为什么 ziplss 选项会触发错误吗?

感谢您的帮助

【问题讨论】:

    标签: r predict gam mgcv


    【解决方案1】:

    由于某些未知原因,您在从 ziplss 家庭拟合进行预测时似乎必须格式化变量。

    例如,如果您在模型中编写了“as.factor(my.var)”,那么您的新数据必须属于类因子。

    【讨论】:

      猜你喜欢
      • 2023-03-23
      • 2016-09-03
      • 2020-03-27
      • 2021-01-24
      • 1970-01-01
      • 2015-12-09
      • 2017-01-29
      • 2020-05-03
      • 2020-04-22
      相关资源
      最近更新 更多