R语言Maxent物种分布建模报错:行数量不匹配求助
Maxent模型运行报错排查求助
我有两个均为15695行且无缺失值(NA)的数据框:
dat_Winter:存储环境变量dolphin_coords_xy:存储十进制度数格式的经纬度
尝试使用dismo包中的maxent()函数运行物种分布模型时,始终出现以下报错:
Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 1, 2, 0
该报错提示行数不匹配,但我已验证两个数据框行数一致,也检查了缺失值、数据类型,均符合函数参数要求,仍无法定位问题。因数据所有权限制无法共享完整数据,现提供前5行数据及模拟数据,恳请协助排查。
相关代码
# 从dolphin_coords1中提取存在点坐标 dolphin_coords_xy <- dolphin_coords1 %>% dplyr::select(1, 2) dolphin_coords_xy <- as.data.frame(dolphin_coords_xy) p = dolphin_coords_xy # 构建Maxent模型 max1_Winter <- maxent(x = dat_Winter, p = dolphin_coords_xy) # 已执行的排查步骤 # 检查行数是否一致 nrow(dat_Winter) # 结果为15695行 nrow(dolphin_coords_xy) # 结果为15695行 # 检查坐标列的NA值 sum(is.na(dolphin_coords_xy$x)) # NA数量为0 sum(is.na(dolphin_coords_xy$y)) # NA数量为0 # 检查数据框类型 class(dat_Winter) # 结果为data.frame class(dolphin_coords_xy) # 结果为data.frame # 函数参数要求确认 # x = 预测变量可以是Raster*对象、SpatialGridDataFrame或数据框,每列对应一个预测变量,每行对应存在点或背景记录 # p = 如果是数据框/矩阵,则表示物种存在点位置,必须包含两列,第一列为x坐标(经度),第二列为y坐标(纬度)
数据示例
数据框1 dat_Winter(前5行)
SST Chlor.a Slope Distance Depth 1 26.03596 0.2764387 3.12927913 0.0000 5 2 25.84813 0.3505107 0.54305966 412.0501 9 3 25.79146 0.3326796 0.96003758 4175.7593 62 4 26.03121 0.2818667 2.14737457 412.5744 5 5 26.03596 0.2764387 3.12927913 0.0000 5
数据框2 dolphin_coords_xy(前5行)
x y 1 33.89083 27.26778 2 33.86782 27.40854 3 33.86230 27.44623 4 33.88653 27.26957 5 33.88766 27.26848
模拟数据
structure(list(x = c(33.7250201948918, 33.0372212855145, 33.1162582356483, 33.1780943416525, 33.325465941336, 33.1426498885266, 33.372344966745, 33.7141977476422, 33.5114065359812, 33.4723861014936), y = c(28.0621412244625, 27.6205332666635, 28.0223171819933, 27.5313555219211, 27.1894561205059, 27.5307895665988, 28.1612804006785, 27.5815055153333, 27.3029501273297, 27.3116279762238), Calf_Presence = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), SSS = c(1027.47942044867, 1026.32734772185, 1027.6889518555, 1026.61821882308, 1026.73625519967, 1026.99284255489, 1026.50956621722, 1026.42982337421, 1026.87068500051, 1026.71667900492), SST = c(25.0228688765572, 27.6068648373514, 23.5967889237256, 26.6370548686025, 26.2696984540073, 24.8069121214026, 27.1928669289746, 27.3427573793279, 26.2358166318412, 26.8545404103531), Chlor.a = c(0.234918360422555, 0.552972766326481, 0.372645556572673, 0.158839964433605, 0.155691480776937, 0.322592780862786, 0.16285265978558, 0.155731527084381, 0.207670826649629, 0.174525638280348 ), Slope = c(4.50732010781271, 0.262136190366096, 0.164475474050542, 0.725271958307515, 0.793811857372093, 0.0233933381961778, 2.86868026925737, 2.04465639865241, 1.15032474698361, 0.930412189550645), Distance = c(102293.714232872, 332276.294160756, 126047.003446403, 146918.398130579, 158796.57696904, 27015.5468157929, 190039.211871486, 265043.121310163, 105894.776220919, 98221.3073956403), Depth = c(27, 2, 52, 810, 1081, 76, 819, 879, 705, 738)), row.names = c(NA, 10L), class = "data.frame")
内容的提问来源于stack exchange,提问作者Alice Hobbs
相关产品推荐
相关产品推荐

