Sch*_*nsl 5 plot regression r mixed-models glmmtmb
我有以下数据,并使用 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)
Run Code Online (Sandbox Code Playgroud)
我的目的是创建一个图,其中包含不同植物密度的预测直径数据,并包含随机图效果。所以我尝试预测数据:
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)
Run Code Online (Sandbox Code Playgroud)
不幸的是,我得到了每个地块的输出,但想要对直径〜植物密度进行广义预测。
我的目标是创建一个像这里一样的图,但使用 glmmTMB 的回归模型来考虑随机效应。
感谢你的帮助!
小智 6
该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))
Run Code Online (Sandbox Code Playgroud)
你真的可以从那里做任何你想做的事情,改变颜色、主题、比例,该包还有一些漂亮的小插图。
| 归档时间: |
|
| 查看次数: |
4350 次 |
| 最近记录: |