物种分布建模中x@presence空对象错误求解(R语言sdm包)
构建物种分布模型时sdm包报错:
Error in x@presence : no applicable method for @ applied to an object of class "NULL" 环境信息
- R版本:4.4.1
- 使用工具:Naimi于2016年开发的sdm包
报错场景
运行以下建模代码时触发错误:
model <- sdm(Species ~ ., data = sdm_data, methods = c('glm', 'gam', 'gbm', 'rf', 'svm', 'mars'))
错误信息:
Error in x@presence : no applicable method for
@applied to an object of class "NULL"
完整相关代码
bioclim_files <- list.files(pattern = "*.tif$", full.names = TRUE) Study_Area <- st_read("shp/3Province.shp") DEM <- rast ("shp/DEM.tif") DEM_crop <- crop (DEM, Study_Area) DEM_mask <- mask (DEM_crop, Study_Area) Bio <- rast(bioclim_files) Bio <- crop (Bio, Study_Area) Bio <- mask (Bio, Study_Area) ext(Bio) ext(DEM) Bio_crop <- crop(Bio, ext(DEM)) Bio_resample <- resample(Bio_crop, DEM) #Bio1_2_4_8_15_18 occurance_data <- import("p_i.xlsx") sdm_data <- sdmData(Species ~ . + coords(Lon + Lat), train = occurance_data, predictors = Bio_resample) print(sdm_data) summary(sdm_data) model <- sdm(Species ~ ., data = sdm_data, methods = c('glm', 'gam', 'gbm', 'rf', 'svm', 'mars')) str(sdm_data)
物种出现数据(occurance_data)详情
> names(occurance_data) [1] "OBJECTID" "Species" "Lon" "Lat" > str(occurance_data) 'data.frame': 78 obs. of 4 variables: $ OBJECTID: num 1 2 3 4 5 6 7 8 9 10 ... $ Species : chr "p_i" "p_i" "p_i" "p_i" ... $ Lon : num 50.8 50.8 50.9 51.3 51.3 ... $ Lat : num 36.7 36.7 36.7 36.4 36.7 ... > summary(occurance_data) OBJECTID Species Lon Lat Min. : 1.00 Length:78 Min. :49.01 Min. :36.12 1st Qu.:20.25 Class :character 1st Qu.:50.86 1st Qu.:36.29 Median :39.50 Mode :character Median :52.36 Median :36.42 Mean :39.50 Mean :51.97 Mean :36.56 3rd Qu.:58.75 3rd Qu.:53.09 3rd Qu.:36.76 Max. :78.00 Max. :55.59 Max. :37.39
已尝试的无效方案
- 调整变量名大小写(如
Species/species) - 增加物种出现数据量
求可行的解决方法。
内容的提问来源于stack exchange,提问作者Simon
相关产品推荐
相关产品推荐

