我正在做物种分布建模(生态位建模),我将一个模型投影到当前或未来的气候光栅(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不使用吗?
发布于 2014-04-19 01:57:37
我在这里回答我自己的问题,因为我刚刚弄明白了这一点。
为了将训练好的模型(使用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作为我的对象,重新运行了预测函数,它起作用了。
https://stackoverflow.com/questions/23136380
复制相似问题