I am trying to make a raster file to predict where species will occur. The model that I want to run is:
glmer(colorSymbol ~ snow.cover_sc + bio2_sc + bio3_sc + alt_sc + y + x + (1|spsCode), family = binomial, data = data)
It is a mixed effects model with lat (x) and long (y) as independent predictors as well as various environmental covariates. x and y are geographical coordinates. Since x and y are independent predictors I am trying to use the interpolate function in the raster
package. However, the help file for interpolate gives gstat
(gstat
package) or Krige
(fields
package) as example model objects.
So my first question is can a glmer serve as a model for the interpolate function? I realize that a glmer assumes independence between the predictors and tested for that to see if there was correlation between any of them and found none (<0.5).
My second question is if glmer can be the model object, what does the following error mean:
Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : object is not a matrix In addition: Warning message: closing unused connection 4
For context I get this error when I run the reduced model:
m4<- glm(colorSymbol ~ bio_2 + alt + x + y, family = binomial, data = data)
and create a raster stack of bio_2 and alt. Links to files below: (Note they can also be accessed via worldclim(dot)org/current (sorry can't post more than 2 links) and downloading ESRI 30 second grids.)
Here is the full code:
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
Any help would be greatly appreciated!