2014-04-17 19 views
0

我正在做物種分佈建模(生態位模型),我將模型投影到當前或未來的氣候柵格(Bioclim變量)。問題與預測函數在R爲一個biostack而不是另一個

當我預測,以目前的柵格(對象= 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! 

我正在投影的未來biostack圖層在圖像中可以正常顯示,具有正常的最小值和最大值(我不能在沒有信譽評分的情況下發布圖像)。

但是,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是不是?

回答

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) 

我再重新跑了預測功能,採用future_bio_stack作爲我的對象,它的工作。

相關問題