赖江山的博客分享 http://blog.sciencenet.cn/u/laijiangshan 生态、统计与R语言

博文

请安装更新版glmm.hp(0.0-7),解决一个无关变量带NA导致总R2跟变量R2之和不相等的问题

已有 1619 次阅读 2023-3-3 14:27 |个人分类:glmm|系统分类:科研笔记

最近有个glmm.hp的用户反馈他获得每个固定效应因子的(fixed effect)的Individual值的和并不等于总的marginal R2


通过我排查后,发现问题是他的原始数据中,有一些没有应用到模型中的有些列里面具有NA值(红色的地方)引起的。


  

glmm.hp函数输入对象很非常简单,即lme4包、nlme包和glmmTMB包运行(G)LMM得到模型对象均可。glmm.hp运行过程需要从“模型对象”中获取原始的data, 我之前在运行过程加上na.omit函数对所提取的原始数据先删除含有NA的行,目的是为了保证如果预测变量带有NA(黄色标识),需要将这些行去掉,否则会导致在模型子集过程每次所运行的数据不一样,比如运行单独含有“focal”作为predictor的时候,第一行会被去掉,而运行单独有“difference”作为predictor的时,第二行会被去掉,第一行则会被保留的,这样导致两次运行的数据不一样,这样就会导致结果不准。如果非使用的列变量中含有NA,提前用na.omit进行处理,就会把例如图中第21行也去掉,而这一行所用到的数据列是完整的,这就会导致用于分解的数据会比原始数据少,导致了分解前全模型跟后面用于分解的子模型的数据不一样,所以导致基于原始数据算出来的总marginal R2解后的总和不匹配。现在已经新的包已经考虑的这个问题,先去判predictor中是否有NA,如果有,找到NA的行并去掉,而不是将全部含有NA的行去掉。所以目前解决这个问题请大家更新包,CRAN和github均已经更新,如果您之前的数据出现过这种情况,请您更新包后重新计算。R包总是在用户不断尝试反馈过程中完善,这是R开源的优势和魅力所在!

glmm.hp的文章已经在Journal of Plant Ecology今年最后一期上正式发表,请各位及时重新安装,(install.packages("glmm.hp"))即可。另外,请各位使用glmm.hp的用户在文章中务必使用如下的引用:Jiangshan Lai, Yi Zou, Shuang Zhang, Xiaoguang Zhang,Lingfeng Mao(2022). glmm.hp: an R package for computing individual effect of predictors in generalized linear mixed models. Journal of Plant Ecology,15(6):1302-1307


目前已经有6篇SCI文章引用JPE的文章,列表如下:

1.       Wan, J.-Z., Wang, Q., and Wang, C.-J. (2023). Biomass and nitrogen content of petiole and rachis predict leaflet trait variation in compound pinnate leaves of plants. Flora 298, 152207. doi: https://doi.org/10.1016/j.flora.2022.152207.

2.       Wang, C., Wang, S., Fu, B., Li, Z., and Lü, Y. (2022). Plantation understorey legume functional groups enhance soil organic carbon sequestration by promoting species richness. Land Degrad. Dev.. doi: https://doi.org/10.1002/ldr.4598.

3.       Yunwei, H., Qing, W., Fucheng, L., Yalin, G., Weipo, Y., Yida, A., et al. (2023). The difference in soil organic carbon distribution between natural and planted forests: A case study on stony soils mountainous area in the Upper Min River Arid Valley, China. Soil Use and Management 39(1), 147-160. doi: https://doi.org/10.1111/sum.12860.

4.       Zhang, M., Gao, H., Chen, S., Wang, X., Mo, W., Yang, X., et al. (2022). Linkages between stomatal density and minor leaf vein density across different altitudes and growth forms. Front. Plant Sci. 13. doi: 10.3389/fpls.2022.1064344.

5.       Yong Cao, Lizhu Wang 2023How to Statistically Disentangle the Effects of Environmental Factors and Human Disturbances: A Review . Water15(4) https://doi.org/10.3390/w15040734


6.       Jiqi Gu, Xiaotong Song, Yujia Liao, Yanhui Ye, Ruihong Wang, Heping Ma, Xiaoming Shao.2022Tree Species Drive the Diversity of Epiphytic Bryophytes in the Alpine Forest Ecosystem: A Case Study in TibetForests13(12), https://doi.org/10.3390/f13122154





https://wap.sciencenet.cn/blog-267448-1378745.html

上一篇:Wiley发来Top cited paper的通知
下一篇:“水杉”生态统计讲坛第六讲:多元统计的应用
收藏 IP: 222.129.5.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-27 13:06

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部