用glmer预测新数据在哪里是固定效果的栅格堆栈 [英] predict with glmer where new data is a Raster Stack of fixed efefcts
问题描述
我已经在 glmer
中构建了模型,并希望在表示我模型中固定效果的 rasterStack
上进行预测.我的 glmer
模型的格式为:
I have constructed models in glmer
and would like to predict these on a rasterStack
representing the fixed effects in my model. my glmer
model is in the form of:
m1<-glmer(Severity ~ x1 + x2 + x3 + (1 | Year) + (1 | Ecoregion), family=binomial( logit ))
如您所见,我具有随机效果,而我没有作为空间图层的效果-例如'year'.因此,当您没有随机效果数据随机效果层时,问题实际上是在 rasterStacks
上预测 glmer
.如果我在不添加随机效果的情况下开箱即用,则会收到错误消息.
As you can see, I have random effects which I don't have as spatial layer - for example 'year'. Therefore the problem is really predicting glmer
on rasterStacks
when you don't have the random effects data random effects layers. If I use it out of the box without adding my random effects I get an error.
m1.predict=predict(object=all.var, model=m1, type='response', progress="text", format="GTiff")
Error in predict.averaging(model, blockvals, ...) :
推荐答案
您的问题很简短,没有指出遇到的问题(如果有).这似乎开箱即用",但在您的情况下可能行不通.有关选项,请参见?raster :: predict
.
Your question is very brief, and does not indicated what, if any, trouble you have encountered. This seems to work 'out of the box', but perhaps not in your case. See ?raster::predict
for options.
library(raster)
# example data. See ?raster::predict
logo <- brick(system.file("external/rlogo.grd", package="raster"))
p <- matrix(c(48, 48, 48, 53, 50, 46, 54, 70, 84, 85, 74, 84, 95, 85,
66, 42, 26, 4, 19, 17, 7, 14, 26, 29, 39, 45, 51, 56, 46, 38, 31,
22, 34, 60, 70, 73, 63, 46, 43, 28), ncol=2)
a <- matrix(c(22, 33, 64, 85, 92, 94, 59, 27, 30, 64, 60, 33, 31, 9,
99, 67, 15, 5, 4, 30, 8, 37, 42, 27, 19, 69, 60, 73, 3, 5, 21,
37, 52, 70, 74, 9, 13, 4, 17, 47), ncol=2)
xy <- rbind(cbind(1, p), cbind(0, a))
v <- data.frame(cbind(pa=xy[,1], extract(logo, xy[,2:3])))
v$Year <- sample(2000:2001, nrow(v), replace=TRUE)
library(lme4)
m <- lmer(pa ~ red + blue + (1 | Year), data=v)
# here adding Year as a constant, as it is not a variable (RasterLayer) in the RasterStack object
x <- predict(logo, m, const=(data.frame(Year=2000)))
这篇关于用glmer预测新数据在哪里是固定效果的栅格堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!