r - 错误使用 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'在最后。
有人可以帮助我了解发生了什么以及我做错了什么吗?先感谢您!如果您需要任何进一步的信息,请告诉我。
解决方案
推荐阅读
- angular - 是否可以按需构建模块?
- c# - 在选择语句中传递参数时,npgsql 不返回行
- prometheus - 如何让 Prometheus 根据 Alert 标签向两个不同的 Alertmanagers 发送 Alerts?
- c++ - 我可以在堆分配的原始数组上使用 std::sort 吗?
- xaml - Ribbon.xaml 上的定向控件
- reactjs - 在使用 PDF.JS 渲染所有 pdf 页面时,列表中的每个孩子都应该有一个唯一的“key”道具
- arrays - VBA 数组中的 IF 语句比循环更快地运行代码
- python - 如何将一组参数作为一个长变量传递给 find()/find_all()
- javascript - 如何使电子邮件请求与动态 HTML 响应一起使用?
- jar - 运行 Spring 批处理时出现 CommandLineJobRunner 错误,无法找到或加载主类 CommandLineJobRunner