从文件夹中读取 biomod2 建模对象和模型投影对象时出错
Error reading in biomod2 modeling object and model projection object from folder
我使用 R 中的 biomod2 包创建了一些简单的模型对象。我将模型和投影保存到我硬盘上的一个文件夹中。几天后我回来获取我的模型评估、变量重要性并重新绘制模型投影,但我无法加载模型。 biomod2 pdf says to simply use the load()
function, but when I tried that, the load()
function either errored because I didn't have permission to load that object, or subsequent commands failed. Below is the built-in example from the tutorial,以及由此产生的错误。
注意:对于我的实际数据,我将只使用随机森林模型,不使用其他 ML 方法。我愿意接受有关其他气候包络建模包的建议。
# test the ability to read in biomod2 model object from folder and get model evaluations, variable importance, and plot
# load the library
library(biomod2)
# load our species data
DataSpecies <- read.csv(system.file("external/species/mammals_table.csv",
package="biomod2"))
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")]
# load the environmental raster layers (could be .img, ArcGIS
# rasters or any supported format by the raster package)
# Environmental variables extracted from Worldclim (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"))
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. Computing the models
myBiomodModelOut <- BIOMOD_Modeling(
myBiomodData,
models = c('SRE','CTA','RF','MARS','FDA'),
models.options = myBiomodOption,
NbRunEval=3,
DataSplit=80,
Prevalence=0.5,
VarImport=3,
models.eval.meth = c('TSS','ROC'),
SaveObj = TRUE,
rescal.all.models = TRUE,
do.full.models = FALSE,
modeling.id = paste(myRespName,"FirstModeling",sep=""))
# get all models evaluation
myBiomodModelEval <- get_evaluations(myBiomodModelOut)
# print the dimnames of this object
dimnames(myBiomodModelEval)
# print variable importances
get_variables_importance(myBiomodModelOut)
# projection over the globe under current conditions
myBiomodProj <- BIOMOD_Projection(
modeling.output = myBiomodModelOut,
new.env = myExpl,
proj.name = 'current',
selected.models = 'all',
binary.meth = 'TSS',
compress = 'xz',
clamping.mask = F,
output.format = '.grd')
# summary of crated oject
myBiomodProj
# files created on hard drive
list.files("GuloGulo/proj_current/")
# This line appears in the global environment as "GuloGulo_AllData_RUN1_RF" a "Formal class RF_biomod2_model"
load('C:/Filepath/GuloGulo/models/GuloGuloFirstModeling/GuloGulo_AllData_RUN1_RF')
get_evaluations(GuloGulo_AllData_RUN1_RF)
最后一行给出
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘get_evaluations’ for signature ‘"RF_biomod2_model"
我对文件夹的索引太多了。在硬盘驱动器(即 'GuloGulo' 父文件夹)上的模型对象中,在您到达任何子文件夹之前,有一个名为 GuloGuloFirstModeling.models.out
的 spice 文件 (.out)。使用 R 中的加载函数阅读此 spice 文件:load("C:/Filepath/GuloGulo/GuloGuloFirstModeling.models.out")
,您将阅读模型对象的所有方面:所有运行、评估指标和变量重要性。
我使用 R 中的 biomod2 包创建了一些简单的模型对象。我将模型和投影保存到我硬盘上的一个文件夹中。几天后我回来获取我的模型评估、变量重要性并重新绘制模型投影,但我无法加载模型。 biomod2 pdf says to simply use the load()
function, but when I tried that, the load()
function either errored because I didn't have permission to load that object, or subsequent commands failed. Below is the built-in example from the tutorial,以及由此产生的错误。
注意:对于我的实际数据,我将只使用随机森林模型,不使用其他 ML 方法。我愿意接受有关其他气候包络建模包的建议。
# test the ability to read in biomod2 model object from folder and get model evaluations, variable importance, and plot
# load the library
library(biomod2)
# load our species data
DataSpecies <- read.csv(system.file("external/species/mammals_table.csv",
package="biomod2"))
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")]
# load the environmental raster layers (could be .img, ArcGIS
# rasters or any supported format by the raster package)
# Environmental variables extracted from Worldclim (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"))
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. Computing the models
myBiomodModelOut <- BIOMOD_Modeling(
myBiomodData,
models = c('SRE','CTA','RF','MARS','FDA'),
models.options = myBiomodOption,
NbRunEval=3,
DataSplit=80,
Prevalence=0.5,
VarImport=3,
models.eval.meth = c('TSS','ROC'),
SaveObj = TRUE,
rescal.all.models = TRUE,
do.full.models = FALSE,
modeling.id = paste(myRespName,"FirstModeling",sep=""))
# get all models evaluation
myBiomodModelEval <- get_evaluations(myBiomodModelOut)
# print the dimnames of this object
dimnames(myBiomodModelEval)
# print variable importances
get_variables_importance(myBiomodModelOut)
# projection over the globe under current conditions
myBiomodProj <- BIOMOD_Projection(
modeling.output = myBiomodModelOut,
new.env = myExpl,
proj.name = 'current',
selected.models = 'all',
binary.meth = 'TSS',
compress = 'xz',
clamping.mask = F,
output.format = '.grd')
# summary of crated oject
myBiomodProj
# files created on hard drive
list.files("GuloGulo/proj_current/")
# This line appears in the global environment as "GuloGulo_AllData_RUN1_RF" a "Formal class RF_biomod2_model"
load('C:/Filepath/GuloGulo/models/GuloGuloFirstModeling/GuloGulo_AllData_RUN1_RF')
get_evaluations(GuloGulo_AllData_RUN1_RF)
最后一行给出
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘get_evaluations’ for signature ‘"RF_biomod2_model"
我对文件夹的索引太多了。在硬盘驱动器(即 'GuloGulo' 父文件夹)上的模型对象中,在您到达任何子文件夹之前,有一个名为 GuloGuloFirstModeling.models.out
的 spice 文件 (.out)。使用 R 中的加载函数阅读此 spice 文件:load("C:/Filepath/GuloGulo/GuloGuloFirstModeling.models.out")
,您将阅读模型对象的所有方面:所有运行、评估指标和变量重要性。