首页 > 解决方案 > 错误使用 gam 模型分析浮游植物丰度和环境参数(mgcv 包)

问题描述

我对 R 和这个论坛的新手很陌生。我一直在尝试使用 gam 模型来根据环境预测因子对浮游植物物种计数数据进行建模,但我遇到了错误。
我的代码如下:

file <- read.csv("sg1.csv", header = TRUE, sep = ";", dec = ".", check.names = FALSE,na.strings=c("","NA")) #my dataset contains empty cells that I substitute with NA
data.selected <- file[,c(5,6,14:19)] #I select only the columns on which I am interested
data.no_na <- na.omit(data.selected)
colnames(data.no_na) <- c("T", "S", "P", "Si", "DIN", "DIN_P", "Si_DIN", "Diato")
set.seed(123)
training.samples <- data.no_na$Diato %>% createDataPartition(p =0.8, list = FALSE) #to use Diatom as outcome variable
train.data <- data.no_na[training.samples, ]
test.data <- data.no.na[-training.samples, ]
model <- gam(Diato ~ s(T) + s(S) + s(P) + s(Si), data = train.data)

当我运行代码时,出现此错误:Smooth.construct.tp.smooth.spec(object, dk$data, dk$knots) 中的错误:chiamata a funzioneesterna (arg 1) Inoltre 中的 NA/NaN/Inf:警告消息:1:在 mean.default(xx) 中:参数不是数字或逻辑:返回 NA 2:在 Ops.factor(xx, shift[i]) 中:'-' 对因子没有意义

我看到只有当我将 T 参数放在命令行中时才会发生这种情况,并且如果我使用 data.no_na$TI 分析值获取值列表和 '3011 Levels: 1.25321 10 10.001 10.0043 10.0094 10.025 10.0304 ... S'在最后。

有人可以帮助我了解发生了什么以及我做错了什么吗?先感谢您!如果您需要任何进一步的信息,请告诉我。

标签: rgammgcv

解决方案


推荐阅读