运行 具有泊松族和偏移量的 gam 时出错

Error when running a gam with poisson family and offset

我正在尝试 运行 在 R 中进行游戏,但我收到了一条奇怪的错误消息。

一般来说,我有一定数量的计数,每体积的水样,我想根据这个计数进行校正。我正在尝试生成一个平滑函数,该函数适合作为深度函数的计数,考虑到采样体积的差异。

test <- structure(list(depth = c(2.5, 7.5, 12.5, 17.5, 22.5, 27.5, 32.5, 
37.5, 42.5, 47.5, 52.5, 57.5, 62.5, 67.5, 72.5, 77.5, 82.5, 87.5, 
92.5, 97.5), count = c(53323, 665, 1090, 491, 540, 514, 612, 
775, 601, 497, 295, 348, 357, 294, 292, 968, 455, 148, 155, 101
), vol = c(2119.92, 111.76, 156.64, 71.28, 77.44, 73.92, 62.48, 
78.32, 74.8, 81.84, 53.68, 80.96, 80.08, 79.2, 79.2, 77.44, 77.44, 
84.48, 73.04, 59.84)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -20L), .Names = c("depth", "count", "vol"
))

gam(count ~ s(depth) + offset(vol), data = test, family = "poisson")
Error in if (pdev - old.pdev > div.thresh) { : missing value where TRUE/FALSE needed

知道为什么这不起作用吗?如果我摆脱偏移量,或者如果我设置 family = "gaussian" 函数 运行s 正如人们所期望的那样。

编辑:我发现

gam(count ~ s(depth) + offset(log(vol)), data = test, family = "poisson")

确实 运行,我想我看到有人说有人想为这些变量记录转换偏移量,所以也许这实际上工作正常。

你肯定需要把 vol 放在对数刻度上(对于这个模型)。

更一般地说,偏移量以 link 函数的比例进入模型。因此,如果您的模型使用 family = poisson(link = 'sqrt'),那么您需要包括 偏移量为 offset(sqrt(vol)).

我怀疑错误是由于 likelihood/deviance 中的某些溢出或错误值引起的,原因是假设 vol 值在对数刻度上,而初始模型正在拟合。