簡體   English   中英

使用family = gaulss()時,mgcv GAM中出現錯誤消息

[英]Error message in mgcv GAM when using family = gaulss()

我正在嘗試使用高斯位置比例模型系列在mgcv中使用分層通用加性模型。 但是,該函數家族在嘗試擬合時會引發一個神秘錯誤。

遵循了最近一篇論文( https://peerj.com/articles/6876/ )中關於HGAM的指南以及lmvar軟件包撰寫中的注釋指南( https://cran.r-project.org/ web / packages / lmvar / vignettes / Intro.html )。


library(mgcv); library(datasets)

# Using the CO2 dataset for illustration

data <- datasets::CO2

# Changing the 'Plant' factor from ordered to unordered

data$Plant <- factor(data$Plant, ordered = FALSE)

# This model fits with no errors

CO2_modG_1 <- gam(log(uptake) ~ s(log(conc), k = 5, bs = 'tp') + s(Plant, k = 12, bs = 're'), data = data, method = 'REML', family = 'gaussian')

# This model fails with error

CO2_modG_2 <- gam(log(uptake) ~ s(log(conc), k = 5, bs = 'tp') + s(Plant, k = 12, bs = 're'), data = data, method = 'REML', family = gaulss())

這將返回錯誤消息:


Error in while (sqrt(mean(dlb/(dlb + lami * dS * rm)) * mean(dlb)/mean(dlb +  : 
  missing value where TRUE/FALSE needed

使用gaulss()系列擬合高斯位置比例模型時,必須將兩個公式對象的列表傳遞給gam()

您無需說要如何對模型的比例分量建模,因此這里有一個示例,該示例應等效於gaussian()系列,其中我們有一個比例常數項和一個為平均值提供的線性預測變量。

CO2_modG_2 <- gam(list(log(uptake) ~ s(log(conc), k = 5, bs = 'tp') + 
                         s(Plant, k = 12, bs = 're'), 
                       ~ 1), 
                  data = data, method = 'REML', family = gaulss())

例如,如果要允許每個植物具有其自己的方差,則可以將項添加到第二個公式中:

CO2_modG_3 <- gam(list(log(uptake) ~ s(log(conc), k = 5, bs = 'tp') + 
                         s(Plant, k = 12, bs = 're'), 
                       ~ s(Plant, k = 12, bs = 're')), 
                  data = data, method = 'REML', family = gaulss())

重要的是,您必須為此家族提供兩個公式對象的列表,並且第二個公式應僅帶有波浪號和公式的右側,以指定比例參數的線性預測變量。

list(response ~ x1 + s(x2), # location linear predictor, left & right hand sided
              ~ x1 + s(x3)  # scale linear predictor, right-hand side only
    )

因此,按照我上面顯示的第一個示例,如果希望線性預測變量中的常數用於比例,則需要對截距或常數項使用R的表示法。 ~ 1

list(response ~ x1 + s(x2), # location linear predictor, left & right hand sided
              ~ 1           # scale linear predictor, constant
    )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM