Type: Package
Title: Hierarchical Partitioning of Marginal R2 for Generalized Mixed-Effect Models
Version: 0.1-8
Date: 2025-03-23
Depends: R (≥ 3.4.0),MuMIn,ggplot2,vegan
Imports: lme4
Maintainer: Jiangshan Lai <lai@njfu.edu.cn>
Description: Conducts hierarchical partitioning to calculate individual contributions of each predictor (fixed effects) towards marginal R2 for generalized linear mixed-effect model (including lm, glm and glmm) based on output of r.squaredGLMM() in 'MuMIn', applying the algorithm of Lai J.,Zou Y., Zhang S.,Zhang X.,Mao L.(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<doi:10.1093/jpe/rtac096>.
License: GPL-2 | GPL-3 [expanded from: GPL]
Encoding: UTF-8
URL: https://github.com/laijiangshan/glmm.hp
RoxygenNote: 7.3.1
NeedsCompilation: no
Packaged: 2025-03-24 10:08:51 UTC; lai
Author: Jiangshan Lai ORCID iD [aut, cre], Kim Nimon [aut], Yao Liu [aut]
Repository: CRAN
Date/Publication: 2025-03-24 10:30:02 UTC

Internal function for glmm.hp() to create diagonal matrix

Description

Internal function for glmm.hp() to create diagonal matrix

Usage

creatbin(col, binmatrix)

Arguments

col

Imput number.

binmatrix

Imput empty matrix.

Value

a matrix

a matix

A diagonal matrix


Internal function for glmm.hp()

Description

Internal function for glmm.hp()

Usage

genList(ivlist, value)

Arguments

ivlist

The names of explanatory variable.

value

The sequence ID.

Value

a vector

newlist

A vector for variable index.


Hierarchical Partitioning of Marginal R2 for Generalized Mixed-Effect Models

Description

Hierarchical Partitioning of Marginal R2 for Generalized Mixed-Effect Models

Usage

glmm.hp(mod, iv = NULL, type = "adjR2", commonality = FALSE)

Arguments

mod

Fitted lme4,nlme,glmmTMB,glm or lm model objects.

iv

optional The relative importance of predictor groups will be assessed. The input for iv should be a list, where each element contains the names of variables belonging to a specific group. These variable names must correspond to the predictor variables defined in the model (mod).

type

The type of R-square of lm, either "R2" or "adjR2", in which "R2" is unadjusted R-square and "adjR2" is adjusted R-square, the default is "adjR2". The adjusted R-square is calculated using Ezekiel's formula (Ezekiel 1930) for lm.

commonality

Logical; If TRUE, the result of commonality analysis (2^N-1 fractions for N predictors) is shown, the default is FALSE.

Details

This function conducts hierarchical partitioning to calculate the individual contributions of each predictor towards total (marginal) R2 for Generalized Linear Mixed-effect Model (including lm,glm and glmm). The marginal R2 is the output of r.squaredGLMM in MuMIn package for glm and glmm.

Value

r.squaredGLMM

The R2 for the full model.

commonality.analysis

If commonality=TRUE, a matrix containing the value and percentage of all commonality (2^N-1 for N predictors or matrices).

hierarchical.partitioning

A matrix containing individual effects and percentage of individual effects towards total (marginal) R2 for each predictor.

Author(s)

Jiangshan Lai lai@njfu.edu.cn

References

Examples

library(MuMIn)
library(lme4)
mod1 <- lmer(Sepal.Length ~ Petal.Length + Petal.Width+(1|Species),data = iris)
r.squaredGLMM(mod1)
glmm.hp(mod1)
a <- glmm.hp(mod1)
plot(a)
mod2 <- glm(Sepal.Length ~ Petal.Length + Petal.Width, data = iris)
r.squaredGLMM(mod2)
glmm.hp(mod2)
b <- glmm.hp(mod2)
plot(b)
plot(glmm.hp(mod2))
mod3 <- lm(Sepal.Length ~ Petal.Length + Petal.Width + Petal.Length:Petal.Width, data = iris)
glmm.hp(mod3,type="R2")
glmm.hp(mod3,commonality=TRUE)
mod4 <- lm(Sepal.Length ~ Petal.Length + Petal.Width + Sepal.Width, data = iris)
iv=list(pred1="Sepal.Width",pred2=c("Petal.Length","Petal.Width"))
glmm.hp(mod4,iv)

Internal function for glmm.hp() to determine whether the odd number

Description

Internal function for glmm.hp() to determine whether the odd number

Usage

odd(val)

Arguments

val

Imput number.

Value

a logical value

Logical value

TRUE or FALSE


Plot for a glmm.hp object

Description

Plot for a glmm.hp object

Usage

## S3 method for class 'glmmhp'
plot(x, plot.perc = FALSE, color = NULL, n = 1, dig = 4, ...)

Arguments

x

A glmm.hp object.

plot.perc

Logical;if TRUE, the bar plot (based on ggplot2 package) of the percentage to individual effects of variables or groups towards total explained variation, the default is FALSE to show plot with original individual effects.

color

Color of variables.

n

Integer; which marginal R2 in output of r.squaredGLMM to plot.

dig

Integer; number of decimal places in Venn diagram.

...

unused

Value

a ggplot object

Author(s)

Jiangshan Lai lai@njfu.edu.cn

Examples

library(MuMIn)
library(lme4)
mod1 <- lmer(Sepal.Length ~ Petal.Length + Petal.Width +(1 | Species), data = iris)
a <- glmm.hp(mod1)
plot(a)
mod3 <- lm(Sepal.Length ~ Petal.Length+Petal.Width,data = iris)
plot(glmm.hp(mod3,type="R2"))
plot(glmm.hp(mod3,commonality=TRUE),color = c("#8DD3C7", "#FFFFB3"))