我有以下数据,并以R中的glmmTMB包建立了一个具有随机绘图效应的植物直径~植物密度(植物数量)的模型:
d <- data.frame (diameter = c(17,16,15,13,11, 19,17,15,11,11, 19,15,14,11,8),
plant_density = c(1000,2000,3000,4000,5000, 1000,2000,3000,4000,5000, 1000,2000,3000,4000,5000),
plot = c(1,1,1,1,1, 2,2,2,2,2, 3,3,3,3,3))
glmm.model <- glmmTMB(diameter ~ plant_density + (1|plot),
data = d,
na.action = na.omit,
family="gaussian",
ziformula = ~ 0)我的目的是为不同植物密度建立一个具有预测直径数据的地块,其中包含随机小区效应。所以我试着预测数据:
new.dat <- data.frame(diameter= d$diameter,
plant_density = d$plant_density,
plot= d$plot)
new.dat$prediction <- predict(glmm.model, new.data = new.dat,
type = "response", re.form = NA)不幸的是,我得到了每个地块的输出,但是我想要一个关于直径~植物密度的广义预测。
我的目标是创建一个类似于这里的图,但是使用一个glmmTMB的回归模型,该模型考虑了随机效应。
谢谢你的帮助!
发布于 2022-01-06 15:42:06
ggeffects包使这种类型的东西很容易实现和定制。
例如
library('ggplot2')
library('glmmTMB')
library('ggeffects')
d <- data.frame (diameter = c(17,16,15,13,11, 19,17,15,11,11, 19,15,14,11,8),
plant_density = c(1000,2000,3000,4000,5000, 1000,2000,3000,4000,5000, 1000,2000,3000,4000,5000),
plotx = as.factor( c(1,1,1,1,1, 2,2,2,2,2, 3,3,3,3,3)))
glmm.model <- glmmTMB(diameter ~ plant_density + (1|plotx),
data = d,
family="gaussian")
# basically what your looking for
plot(ggpredict(glmm.model, terms = "plant_density"))
# with additional a change of limits on the y-axis
plot(ggpredict(glmm.model, terms = "plant_density")) +
scale_y_continuous(limits = c(0, 20))你真的可以用它做任何你想做的事,改变颜色,主题,音阶,这个包也有一些漂亮的小插曲。。
https://stackoverflow.com/questions/70607543
复制相似问题