0

我正在做物种分布建模(生态位模型),我将模型投影到当前或未来的气候栅格(Bioclim 变量)。

当我预测当前栅格(object=bio_stack)时,一切正常,使用以下代码:

#predict species current distribution using bio_stack
current_dist<-predict(object=bio_stack, model=mod_gam,filename="whitebark_current_dist_17April2014", 
           na.rm=TRUE, type="response", format="GTiff", overwrite=TRUE,
           progress="text")

但是,当我预测未来的栅格 ( object=future_bio_stack) 时,此代码不会产生结果:

#predict species future distribution using future_bio_stack
future_dist<-predict(object = future_bio_stack, model=mod_gam,filename="whitebark_future_dist_17April2014", 
           fun=predict, na.rm=TRUE, type="response", format="GTiff", overwrite=TRUE,
           progress="text") 

相反,我收到以下警告消息:

In addition: Warning message:
In predict.gam(model, blockvals, ...) :
  not all required variables have been supplied in  newdata!

我投影到的未来生物堆栈层在图像中看起来不错,具有正常的最小值和最大值(如果没有信誉分数,我无法发布图像)。

然而,future_bio_stack 的最小值和最大值在摘要中看起来很奇怪,尤其是与 bio_stack 相比。以下是每个堆栈的摘要,并提供了最小值和最大值:

> future_bio_stack

class       : RasterStack 
dimensions  : 4800, 5880, 28224000, 5  (nrow, ncol, ncell, nlayers)
resolution  : 0.008333333, 0.008333333  (x, y)
extent      : -152, -103, 30, 70  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +no_defs 
names       : WC05future_clipped, WC06future_clipped, WC08future_clipped,     WC13future_clipped, WC15future_clipped 
min values  :             -32768,             -32768,                 -32768,             -32768,             -32768 
max values  :              32767,              32767,                  32767,              32767,              32767 

> bio_stack
class       : RasterStack 
dimensions  : 4800, 5880, 28224000, 5  (nrow, ncol, ncell, nlayers)
resolution  : 0.008333333, 0.008333333  (x, y)
extent      : -152, -103, 30, 70  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
names       : WC05_clipped, WC06_clipped, WC08_clipped, WC13_clipped, WC15_clipped 
min values  :          -56,         -429,         -145,            7,            5 
max values  :          457,          100,          332,          767,          129 

任何想法为什么bio_stack正在使用该predict功能但future_bio_stack不是?

4

1 回答 1

0

我在这里回答我自己的问题,因为我刚刚发现了这一点。

为了将训练后的模型(使用 bio_stack)投影到另一组栅格(例如 future_bio_stack),每个堆栈的列名必须相同。

我重命名了文件并重新堆叠了 future_bio_stack 的栅格,使名称与 bio_stack 中的名称相同:

> bio5future<-raster("WC05_clipped.tif") 
> bio6future<-raster("WC06_clipped.tif")
> bio8future<-raster("WC08_clipped.tif")
> bio13future<-raster("WC13_clipped.tif")
> bio15future<-raster("WC15_clipped.tif")
> 
> future_bio_stack<-stack(bio5future, bio6future, bio8future,
> bio13future, bio15future)

然后我重新运行了 predict 函数,使用 future_bio_stack 作为我的对象,它工作了。

于 2014-04-18T17:57:36.997 回答