R运行GLMER时如何忽略指定因子水平?鹿RSF土地覆盖分析场景
你需要剔除的水体对应Landcover_Type的取值4,只需要在设置参考组、拟合模型前,先过滤该类别观测并清理冗余因子水平即可,修改后的代码如下:
# 过滤掉所有水体类(Landcover_Type=4)的观测 pre_RSFpoints <- subset(pre_RSFpoints, Landcover_Type != 4) # 删除已经不存在的因子水平,避免模型运行时报空水平错误 pre_RSFpoints$Landcover_Type <- droplevels(pre_RSFpoints$Landcover_Type) # 按原有需求设置林地(取值2)为因子参考组 pre_RSFpoints<-within(pre_RSFpoints, Landcover_Type <-relevel(Landcover_Type, ref = 2)) # 后续模型拟合代码无需调整 pre_model <- glmer(Used ~ Landcover_Type + (1|Id),family="binomial",data=pre_RSFpoints) summary(pre_model)
小提示:运行完成后可以执行table(pre_RSFpoints$Landcover_Type),确认4对应的水体水平已经完全被移除,不会参与模型计算。
你原问题中附的样本数据参考:
内容的提问来源于stack exchange,提问作者JLD475
相关产品推荐
相关产品推荐

