R中的MaxEnt将类别变量视为连续

时间:2020-09-29 06:55:02

标签: r categorical-data continuous maxent dismo

我正在尝试使用Maxent使用10个预测变量(9个连续变量和1个分类变量)进行某些物种分布映射。当我将分类栅格导入R时,尽管它在ArcGIS中看起来不错,但仍将其视为连续栅格。我已经在模型中包括了factor参数,以指示应将变量视为分类变量,但是当我查看响应曲线时,该变量的输出是线形图,而不是条形图。

mod = maxent(x=pred.vars, p=pb, factors = "Soiltext",
             args=c("hinge",
                    "threshold=FALSE",
                    "noautofeature",
                    "noremoveduplicates", 
                    "-P","-J", 
                    "writeplotdata",
                    "outputformat=logistic", 
                    "threads=4",
                    "randomseed=FALSE"), 
             path=paste("S:/Thesis_Chapter_1/data/Output/Maxent/species")) ; 

在导入栅格后,我尝试将栅格设置为一个因子,这似乎一开始就可以使用。但是,当我尝试绘制它时会出现错误,并且它似乎仍被视为模型中的连续变量(即,响应曲线仍然是线图,而不是条形图)。

> # Set soil raster layer as a factor (categorical variable)
> Soiltext.f <- asFactor(Soiltext)
> # Check soil is set to factor 
> is.factor(Soiltext.f)
[1] TRUE
> plot(Soiltext.f)
Error in .checkLevels(levels(x)[[1]], value) : 
  the first column name of the raster attributes (factors) data.frame should be "ID"
> structure(Soiltext.f)
class      : RasterLayer 
dimensions : 2270, 3252, 7382040  (nrow, ncol, ncell)
resolution : 250, 250  (x, y)
extent     : 2126684, 2939684, 2259553, 2827053  (xmin, xmax, ymin, ymax)
crs        : +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +units=m +no_defs 
source     : D:/FireFrag_Cdrive/Thesis_Chapter_1/data/predictor_variables/Soil Texture/soil_text_v4_clip3.tif 
names      : soil_text_v4_clip3 
values     : 1, 7  (min, max)
attributes :
       VALUE
 from:     1
  to :     7

关于如何解决此问题的任何建议?谢谢!

0 个答案:

没有答案