用glmer插值,其中新数据是光栅堆栈,模型是固定效果,lat和long作为独立预测器

时间:2016-07-01 01:45:07

标签: r interpolation raster

我正在尝试制作一个光栅文件来预测物种的发生位置。我想要运行的模型是:

glmer(colorSymbol ~ snow.cover_sc + bio2_sc + bio3_sc + alt_sc + y + x + (1|spsCode), family = binomial, data = data)

它是一个混合效应模型,lat(x)和long(y)作为独立预测因子以及各种环境协变量。 x和y是地理坐标。由于x和y是独立的预测变量,我试图在raster包中使用插值函数。但是,插值的帮助文件会将gstatgstat包)或Krigefields包)作为示例模型对象。

所以我的第一个问题是glmer可以作为插值函数的模型吗?我意识到一个glmer假设预测器之间的独立性并进行了测试,以确定它们之间是否存在相关性并且没有找到(<0.5)。

我的第二个问题是如果glmer可以作为模型对象,则以下错误意味着什么:

  

model.frame.default中的错误(条款,newdata,na.action = na.action,   xlev = object $ xlevels):object不是矩阵另外:   警告消息:关闭未使用的连接4

对于上下文,我在运行简化模型时遇到此错误:

m4<- glm(colorSymbol ~ bio_2 + alt + x + y, family = binomial, data = data)

并创建一个bio_2和alt的栅格堆栈。链接到下面的文件:(注意它们也可以通过worldclim(点)org / current访问(抱歉不能发布2个以上的链接)并下载ESRI 30秒网格。)

alt raster file

bio_2 raster file

以下是完整代码:

data4<-structure(list(colorSymbol = c(1L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 
1L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L), bio_2 =           
structure(c(-1.65319533124791, 
5.12773277360962, -2.96563302896227, 2.13829135103802, 1.62789891303799, 
0.169634804466482, -0.049104811819245, -0.049104811819245,      
-0.049104811819245, 
-0.049104811819245, -0.267844428104972, 0.315461215323633,   
0.315461215323633, 
-0.63241045524785, -0.63241045524785, 0.315461215323633, -0.122018017247821, 
-0.049104811819245, -0.413670838962123, 0.169634804466482), .Dim = c(20L, 
1L)), alt = structure(c(0.751340496188818, 4.17865221830445, 
-0.118372064874358, -0.554302064617135, 1.86371359898073,  
0.0126216788907128, 
-0.595103394642321, -0.595103394642321, -0.558596941461892,   
-0.573629010418539, 
-0.0840130501163067, -0.0625386658925246, 0.0620127626054117, 
2.11925877124374, 2.11925877124374, -0.124814380141493, -0.543564872505244, 
-0.719654823140258, 0.495795323925811, 0.20803857532713), .Dim = c(20L, 
1L)), y = structure(c(0.0353970033327643, 1.83610974064461,  
-4.82625744580285, 
-4.36879939725431, 1.11073398331965, 0.101128667461893, 0.171636464096401, 
0.171636497654332, 0.168280671013401, 0.168839981046544, 0.173873670671044, 
0.10507991246954, 0.0997146033725779, 0.0106082967555351,   
0.0106082967555351, 
0.105639188944753, 0.182263153378545, 0.186305172589088, 0.133466968853809, 
0.10507991246954), .Dim = c(20L, 1L)), x = structure(c(3.73193203850492, 
-3.74207501883321, 1.93312018034606, -3.43881737052527, -1.87240343109311, 
-0.289046352405738, 0.13805360014565, 0.13805360014565, 0.0955082550467424, 
0.0997628661381006, 0.00616320902913118, 0.0869992881355855, 
-0.236861953199331, -0.103499155724443, -0.103499410996004, 
0.0912538992269437, 
0.0997628661381006, 0.0498381307812604, 0.220158634177113,     
0.0784903212244285
), .Dim = c(20L, 1L))), .Names = c("colorSymbol", "bio_2", "alt", 
"y", "x"), row.names = c(NA, 20L), class = "data.frame")

library("lme4")
library("raster")
library("rgdal")
library("RArcInfo")

m7 = glm(colorSymbol ~ bio_2 + alt + x + y, family = binomial, data = data4)
#write model

alt<-raster("alt.ovr")
bio_2<-raster("bio_2.ovr")
#import rasters

rasstack<-stack(alt, bio_2)
#make raster stack

test<-raster::interpolate(rasstack, m7)
#try and interpolate model

非常感谢任何帮助!

0 个答案:

没有答案