我最近在R中使用了MaxEnt(dismo-package),但只使用交叉验证来验证我的鸟类栖息地模型(只有一个物种)。现在我想使用自己创建的测试样本文件。我必须手动选择这些点进行验证,并且不能使用随机测试点。
所以我的R脚本看起来像这样:
library(raster)
library(dismo)
setwd("H:/MaxEnt")
memory.limit(size = 400000)
punkteVG <- read.csv("Validierung_FL_XY_2016.csv", header=T, sep=";", dec=",")
punkteTG <- read.csv("Training_FL_XY_2016.csv", header=T, sep=";", dec=",")
punkteVG$X <- as.numeric(punkteVG$X)
punkteVG$Y <- as.numeric(punkteVG$Y)
punkteTG$X <- as.numeric(punkteTG$X)
punkteTG$Y <- as.numeric(punkteTG$Y)
##### mask NA ######
mask <- raster("final_merge_8class+le_bb_mask.img")
dataframe_VG <- extract(mask, punkteVG)
dataframe_VG[dataframe_VG == 0] <- NA
dataframe_TG <- extract(mask, punkteTG)
dataframe_TG[dataframe_TG == 0] <- NA
punkteVG <- punkteVG*dataframe_VG
punkteTG <- punkteTG*dataframe_TG
#### add the raster dataset ####
habitat_all <- stack("blockstats_stack_8class+le+area_8bit.img")
#### MODEL FITTING #####
library(rJava)
system.file(package = "dismo")
options(java.parameters = "-Xmx1g" )
setwd("H:/MaxEnt/results_8class_LE_AREA")
### backgroundpoints ###
set.seed(0)
backgrVMmax <- randomPoints(habitat_all, 100000, tryf=30)
backgrVM <- randomPoints(habitat_all, 1000, tryf=30)
### Renner (2015) PPM modelfitting Maxent ###
maxentVMmax_Renner<-maxent(habitat_all,punkteTG,backgrVMmax, path=paste('H:/MaxEnt/Ergebnisse_8class_LE_AREA/maxVMmax_Renner',sep=""),
args=c("-P",
"noautofeature",
"nothreshold",
"noproduct",
"maximumbackground=400000",
"noaddsamplestobackground",
"noremoveduplicates",
"replicates=10",
"replicatetype=subsample",
"randomtestpoints=20",
"randomseed=true",
"testsamplesfile=H:/MaxEnt/Validierung_FL_XY_2016_swd_NA"))
&#34; maxent()&#34; -command后我遇到了多个错误。首先我得到一个错误,说明他需要超过0(这是默认值)&#34; randomtestpoints&#34;。所以我添加了&#34; randomtestpoints = 20&#34; (希望不会阻止程序使用该文件)。然后我得到了:
Error: Test samples need to be in SWD format when background data is in SWD format
Error in file(file, "rt") : cannot open the connection
问题是,当我使用默认的交叉验证运行脚本时,如下所示:
maxentVMmax_Renner<-maxent(habitat_all,punkteTG,backgrVMmax, path=paste('H:/MaxEnt/Ergebnisse_8class_LE_AREA/maxVMmax_Renner',sep=""),
args=c("-P",
"noautofeature",
"nothreshold",
"noproduct",
"maximumbackground=400000",
"noaddsamplestobackground",
"noremoveduplicates",
"replicates=10"))
......一切正常。
我还尝试了多种方法来获取正确格式的csv-validation-data。两行(标记为X和Y),三行(标记物种,X和Y)和其他东西。我宁愿使用我用read.csv创建的&#34; punkteVG&#34; -vector(这是验证数据)......但似乎MaxEnt想要他的文件。
我无法想象我的问题是如此罕见。有人必须使用参数&#34; testsamplesfile&#34;之前。
答案 0 :(得分:0)
我发现了,问题是什么。所以在这里,让其他人享受:
子样本文件的正确maxent-command如下所示:
maxentVMmax_Renner<-maxent(habitat_all, punkteTG, backgrVMmax, path=paste('H:/MaxEnt',sep=""),
args=c("-P",
"noautofeature",
"nothreshold",
"noproduct",
"maximumbackground=400000",
"noaddsamplestobackground",
"noremoveduplicates",
"replicates=1",
"replicatetype=Subsample",
"testsamplesfile=H:/MaxEnt/swd.csv"))
当然,不能有多个重复项,因为您只有一个子样本。 最重要的是,“swd.csv”子样本文件必须包括:
所以最后一点是这里的问题。基本上,如果您没有在Subsample-file中定义species-colum,MaxEnt将不知道如何分配数据。