簡體   English   中英

使用帶有family = betar的bam()的GAM錯誤

[英]GAM error using bam() with family = betar

我無法解決從mgcv運行bam()時遇到的錯誤。

我注意到 14 個月前在這里報告了一個類似的錯誤,似乎沒有就解決方案達成一致 - 建議向 Simon Wood 發送電子郵件。

我的數據在這里 數據集太大,無法粘貼dput()的輸出。

如果我使用整個數據集運行以下模型,則會出現以下錯誤

library(mgcv)

m3 <- bam(pt10 ~ 
            org.type +
            region +
            s(year) + 
            s(year, by = org.type) +
            s(year, by = region), 
          data = error, 
          method = "fREML", 
          family = betar(link="logit", eps = 0.1),
          select = T)

Warning messages:
1: In estimate.theta(theta, family, G$y, linkinv(eta), scale = scale1,  :
  step failure in theta estimation
2: In wt * LS :
  longer object length is not a multiple of shorter object length
3: In muth * (log(y) - log1p(-y)) :
  longer object length is not a multiple of shorter object length
4: In -lgamma(theta) + lgamma(muth) + lgamma(theta - muth) - muth *  :
  longer object length is not a multiple of shorter object length
5: In -lgamma(theta) + lgamma(muth) + lgamma(theta - muth) - muth *  :
  longer object length is not a multiple of shorter object length
6: In -lgamma(theta) + lgamma(muth) + lgamma(theta - muth) - muth *  :
  longer object length is not a multiple of shorter object length
7: In prior. weights * y :
  longer object length is not a multiple of shorter object length
8: In 2 * wt * (-lgamma(theta) + lgamma(muth) + lgamma(theta - muth) -  :
  longer object length is not a multiple of shorter object length

但是,如果我使用整個數據集運行相同的模型,我排除了最后一行,則模型似乎運行正常

m3 <- bam(pt10 ~ 
            org.type +
            region +
            s(year) + 
            s(year, by = org.type) +
            s(year, by = region), 
          data = error[1:20500,], 
          method = "fREML", 
          family = betar(link="logit", eps = 0.1),
          select = T)

這向我表明數據集的最后一行有問題。 但是,我在數據集的最后一行中看不到任何我希望產生上述警告消息的錯誤。

如果我再次在一小部分數據上運行相同的模型,但這次包括最后一行數據,則模型再次運行正常。

m3 <- bam(pt10 ~ 
            org.type +
            region +
            s(year) + 
            s(year, by = org.type) +
            s(year, by = region), 
          data = error[20400:20501,], 
          method = "fREML", 
          family = betar(link="logit", eps = 0.1),
          select = T)

但是更大的數據子集(同樣包括最后一行)會產生與上述類似的警告消息。

m3 <- bam(pt10 ~ 
            org.type +
            region +
            s(year) + 
            s(year, by = org.type) +
            s(year, by = region), 
          data = error[10000:20501,], 
          method = "fREML", 
          family = betar(link="logit", eps = 0.1),
          select = T)

Warning messages:
1: In wt * LS :
  longer object length is not a multiple of shorter object length
2: In muth * (log(y) - log1p(-y)) :
  longer object length is not a multiple of shorter object length
3: In -lgamma(theta) + lgamma(muth) + lgamma(theta - muth) - muth *  :
  longer object length is not a multiple of shorter object length
4: In -lgamma(theta) + lgamma(muth) + lgamma(theta - muth) - muth *  :
  longer object length is not a multiple of shorter object length
5: In -lgamma(theta) + lgamma(muth) + lgamma(theta - muth) - muth *  :
  longer object length is not a multiple of shorter object length
6: In prior.weights * y :
  longer object length is not a multiple of shorter object length
7: In 2 * wt * (-lgamma(theta) + lgamma(muth) + lgamma(theta - muth) -  :
  longer object length is not a multiple of shorter object length
8: In bgam.fit(G, mf, chunk.size, gp, scale, gamma, method = method,  :
  algorithm did not converge

任何建議表示贊賞。

我懷疑問題出在您的eps上(這可能確實表明您的數據有問題)。

默認值為:

r$> .Machine$double.eps*100                                                     
[1] 2.220446e-14

因此,您將所有響應值截斷為區間[eps, 1-eps] (即任何y < epsy > 1-eps分別被重置為eps1 - eps 。)。 我想這會導致擬合算法出現問題,並且遇到了未預料到的情況。 如果在[eps, 1-eps]范圍之外的值的數量不少,那么您會將所有這些值堆積在范圍的范圍內,我懷疑這會導致數據發生細微變化的情況導致擬合算法中的數值問題。

盡可能多地截斷數據表明這不是您的數據的正確分布。 如果沒有任何其他信息,我會在別處尋找更合適的方法。

暫無
暫無

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

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