我必须得到AUC(ROC曲线下面积)来评估我的模型。 我正在使用带有Biomod2包的SRE模型。
Biomod2通过 evaluate()函数给出了AUC值,这很好。然后我尝试用ROCR包检查AUC,我遇到了一个大问题:来自evaluate()(Biomod2)和ROCR的AUC值不一样。 (对于其他一些未在Biomod2上实现的模型,我必须使用ROCR包,这就是我担心的原因。)
现在我正在尝试使用可重现的示例(来自Biomod2包的代码)找到问题,但是我收到了错误。
首先,来自Biomod2包的代码(可重现的例子):
end
然后,从ROCR获得AUC的部分:
library(biomod2)
library(ROCR)
# species occurrences
DataSpecies <- read.csv(system.file("external/species/mammals_table.csv",
package="biomod2"), row.names = 1)
head(DataSpecies)
# the name of studied species
myRespName <- 'GuloGulo'
# the presence/absences data for our species
myResp <- as.numeric(DataSpecies[,myRespName])
# the XY coordinates of species data
myRespXY <- DataSpecies[,c("X_WGS84","Y_WGS84")]
# Environmental variables extracted from BIOCLIM (bio_3, bio_4, bio_7, bio_11 & bio_12)
myExpl = stack( system.file( "external/bioclim/current/bio3.grd",
package="biomod2"),
system.file( "external/bioclim/current/bio4.grd",
package="biomod2"),
system.file( "external/bioclim/current/bio7.grd",
package="biomod2"),
system.file( "external/bioclim/current/bio11.grd",
package="biomod2"),
system.file( "external/bioclim/current/bio12.grd",
package="biomod2"))
# 1. Formatting Data
myBiomodData <- BIOMOD_FormatingData(resp.var = myResp,
expl.var = myExpl,
resp.xy = myRespXY,
resp.name = myRespName)
# 2. Defining Models Options using default options.
myBiomodOption <- BIOMOD_ModelingOptions()
# 3. Doing Modelisation
myBiomodModelOut <- BIOMOD_Modeling( myBiomodData,
models = c('SRE'),
models.options = myBiomodOption,
NbRunEval=1,
DataSplit=80,
Yweights=NULL,
VarImport=3,
models.eval.meth = c('TSS'),
SaveObj = TRUE,
rescal.all.models = FALSE,
do.full.models = FALSE,
modeling.id='test')
# 4. Evaluate model over another dataset (here the full one)
## creation of suitable dataset
data <- cbind(GuloGulo=get_formal_data(myBiomodModelOut,'resp.var'),
get_formal_data(myBiomodModelOut,'expl.var'))
## evaluation
evaluate(myBiomodModelOut, data=data, stat=c('ROC','TSS'))
我遇到的问题是我无法从myResp和myBiomod_raster创建data.frame,因为 # 4.1 Projection on current environemental conditions
myBiomodProjection <- BIOMOD_Projection(modeling.output = myBiomodModelOut,
new.env = myExpl,
proj.name = 'current',
selected.models = 'all',
binary.meth = 'TSS',
compress = FALSE,
build.clamping.mask = FALSE)
myBiomod_raster <- get_predictions(myBiomodProjection) #, as.data.frame=TRUE
spp_occ <- myResp
sauv_p <- as.vector(as.matrix(myBiomod_raster))
ROC_curve <- data.frame(result=sauv_p, spp=spp_occ) #préparation
ROC_curve <- prediction(ROC_curve$result, ROC_curve$spp) #run
AUC <- performance( ROC_curve, "auc" )@y.values
print(AUC[[1]])
= 2488且myBiomod_raster的长度为5640。
错误是:参数意味着行数不同
您是否知道如何使用此Biomod2软件包示例中的数据来获得相同数量的行?
非常感谢!