我正在try "bam.更新"我匹配的mgcv::bam模型,该模型使用"weights"参数,并得到以下错误:
Error in model.frame.default(gp$fake.formula, data, weights = weights, :
invalid type (closure) for variable '(weights)'
我自己无法解决这个问题,所以我放弃这个问题.以下是一个示例代码,它会生成与我在更大的模型中遇到的完全相同的错误:
library(data.table)
library(mgcv)
mtcars <- data.table(mtcars)
# adding arbitrary "model_weigts"
set.seed(55)
mtcars[, model_weigts := abs(rnorm(nrow(mtcars)))]
# split the dataset
mtcars_1 <- mtcars[1:20,]
mtcars_2 <- mtcars[21:32,]
# an arbitrary model formula
formula_c <- formula(mpg ~ s(wt) + s(hp))
# fit the initial model to mtcars_1 and attempt to update it with mtcars_2
model_initial <- mgcv::bam(formula_c, data = mtcars_1, weights = model_weigts)
model_updated <- mgcv::bam.update(model_initial, data = mtcars_2)
sessionInfo()
R version 4.3.3 (2024-02-29)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.5
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: Australia/Adelaide
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] mgcv_1.9-1 nlme_3.1-164 data.table_1.15.2
loaded via a namespace (and not attached):
[1] compiler_4.3.3 Matrix_1.6-5 splines_4.3.3 grid_4.3.3 lattice_0.22-5