使用 family=betar 的 bam 模型 (mgcv) 中的未知错误消息

问题描述

我在 mgcv 中运行以下 bam 模型:

model <- bam(x~s(y,by=aa,k=-1) + aa + s(bb,bs='re') + s(lat,long),family=betar,data=dataframe)

其中 y 是连续的,aa 和 bb 是分类预测变量。为了说明空间自相关,lat 和 long 被包括为平滑的交互项。数据框非常大(> 200 万行,因此采用 bam 方法)。模型似乎在几个小时后以正确的 df 运行,并且图看起来正确,但模型给出了以下警告消息:

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

我尝试在 Google 上搜索这些内容,但找不到任何有助于理解的上下文。我试过生成虚拟数据,但考虑到数据的大小和模型的复杂性,我正在努力提供一个可重现的示例。我应该如何关注这些警告消息,谁能帮助解释它们?

编辑:我已经更新了下面的虚拟代码显示 bam 模型的结构,但我不能让它给出与上面相同的可重现错误

library(mgcv)

beta <- 0.0002
n <- 1000

set.seed(1)
lat <- runif(n,min = 0,max = 100)
set.seed(2)
long <- runif(n,max = 100)

temp1a <- data.frame(y = exp(beta * seq(n)) + rnorm(n),long=long,lat=lat,time = seq(n),model="a",category="a")
temp1b <- data.frame(y = exp(beta * seq(n)) + rnorm(n),model="b",category="a")
temp1c <- data.frame(y = exp(beta * seq(n)) + rnorm(n),model="c",category="a")
temp1d <- data.frame(y = exp(beta * seq(n)) + rnorm(n),model="d",category="a")
temp1e <- data.frame(y = exp(beta * seq(n)) + rnorm(n),model="e",category="a")

temp2a <- data.frame(y = exp(beta * seq(n)) + rnorm(n),category="b")
temp2b <- data.frame(y = exp(beta * seq(n)) + rnorm(n),category="b")
temp2c <- data.frame(y = exp(beta * seq(n)) + rnorm(n),category="b")
temp2d <- data.frame(y = exp(beta * seq(n)) + rnorm(n),category="b")
temp2e <- data.frame(y = exp(beta * seq(n)) + rnorm(n),category="b")

temp3a <- data.frame(y = exp(beta * seq(n)) + rnorm(n),category="c")
temp3b <- data.frame(y = exp(beta * seq(n)) + rnorm(n),category="c")
temp3c <- data.frame(y = exp(beta * seq(n)) + rnorm(n),category="c")
temp3d <- data.frame(y = exp(beta * seq(n)) + rnorm(n),category="c")
temp3e <- data.frame(y = exp(beta * seq(n)) + rnorm(n),category="c")

temp4a <- data.frame(y = exp(beta * seq(n)) + rnorm(n),category="d")
temp4b <- data.frame(y = exp(beta * seq(n)) + rnorm(n),category="d")
temp4c <- data.frame(y = exp(beta * seq(n)) + rnorm(n),category="d")
temp4d <- data.frame(y = exp(beta * seq(n)) + rnorm(n),category="d")
temp4e <- data.frame(y = exp(beta * seq(n)) + rnorm(n),category="d")

df <- rbind(temp1a,temp1b,temp1c,temp1d,temp1e,temp2a,temp2b,temp2c,temp2d,temp2e,temp3a,temp3b,temp3c,temp3d,temp3e,temp4a,temp4b,temp4c,temp4d,temp4e)
df$model <- as.factor(df$model)
df$category <- as.factor(df$category)
df$time <- as.numeric(df$time)
df$y <- as.numeric(df$y)
str(df)

df$y [df$y == 1] <- 0.999999
df$y [df$y == 0] <- 0.000001

m1 <- bam(y~s(time,by=category,k=-1) + category + s(model,bs='re') + s(long,lat),data=df)

(提前为上面糟糕的代码道歉)

编辑 #2:包含以下实际数据的 str(df):

'data.frame':   3453552 obs. of  7 variables:
 $ long    : num  11.7 11.6 11.5 11.4 11.3 11.2 11.1 11 10.9 10.8 ...
 $ lat     : num  75 75 75 75 75 75 75 75 75 75 ...
 $ bb   : Factor w/ 6 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ aa: Factor w/ 4 levels "a","b","c",..: 4 4 4 4 4 4 4 4 4 4 ...
 $ y      : num  2014 2014 2014 2014 2014 ...
 $ x    : num  0.0342 0.0128 0.0118 0.0101 0.0079 ...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...