Type: Package
Title: Hierarchical Partitioning of Adjusted R2 and Explained Deviance for Generalized Additive Models
Version: 0.0-3
Date: 2024-12-15
Depends: R (≥ 3.4.0),mgcv,ggplot2
Maintainer: Jiangshan Lai <lai@njfu.edu.cn>
Description: Conducts hierarchical partitioning to calculate individual contributions of each predictor towards adjusted R2 and explained deviance for generalized additive models based on output of gam()in 'mgcv' package, applying the algorithm in this paper: Lai(2024) <doi:10.1016/j.pld.2024.06.002>.
License: GPL-2 | GPL-3 [expanded from: GPL]
Encoding: UTF-8
URL: https://github.com/laijiangshan/gam.hp
RoxygenNote: 7.3.1
NeedsCompilation: no
Packaged: 2024-12-16 03:29:04 UTC; lai
Author: Jiangshan Lai ORCID iD [aut, cre], Jing Tang [aut]
Repository: CRAN
Date/Publication: 2024-12-16 03:40: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


Hierarchical Partitioning of Adjusted R2 and Explained Deviance for Generalized Additive Models

Description

Hierarchical Partitioning of Adjusted R2 and Explained Deviance for Generalized Additive Models

Usage

gam.hp(mod, iv = NULL, type = "dev", commonality = FALSE)

Arguments

mod

Fitted "gam" 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 gam, either "dev" or "adjR2", in which "dev" is explained deviance and "adjR2" is adjusted R-square, the default is "dev".

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 adjusted R2 and explained deviance for Generalized Additive Models. The adjusted R2 and explained deviance are is the output of summary.gam()in mgcv package.

Value

dev

The R2 for the full model.

hierarchical.partitioning

A matrix containing individual effects and percentage of individual effects towards total adjusted R2 and explained deviance for each predictor.

Author(s)

Jiangshan Lai lai@njfu.edu.cn

References

Examples

library(mgcv)
mod1 <- gam(Sepal.Length ~ s(Petal.Length) + s(Petal.Width) + Sepal.Width,data = iris)
summary(mod1)
gam.hp(mod1)
gam.hp(mod1,type="adjR2")
gam.hp(mod1,commonality=TRUE)
iv <- list(env1=c("s(Petal.Length)","s(Petal.Width)"),env2="Sepal.Width")
gam.hp(mod1,iv,type="adjR2")
gam.hp(mod1,iv,commonality=TRUE)

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.


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


Permutation Test of Hierarchical Partitioning for GAM Analysis

Description

Permutation Test of Hierarchical Partitioning for GAM Analysis

Usage

permu.gamhp(mod = NULL, iv = NULL, type = "dev", permutations = 10)

Arguments

mod

gam model generated by mgcv::gam()

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 total explained variation, either "dev" or "adjR2", in which "dev" is deviance explained and "adjR2" is adjusted R-square, the default is "adjR2".

permutations

An integer; Number of permutations for computing p value of individual contribution for the randomized dataset.

Details

This function is a permutation test of hierarchical partitioning for gam analysis. It returns a matrix of I values (the individual contribution towards total explained variation) for all values from permutations randomizations. For each permutation, the values in each variable (i.e each column of iv) are randomized independently, and gam.hp is run on the randomized iv. As well as the randomized I matrix, the function returns a summary table listing the observed I values, the p value of I for the randomized dataset.

Value

a data.frame containing a summary table listing the observed individual contribution, the p value of individual contribution for the randomized dataset

Author(s)

Jiangshan Lai lai@njfu.edu.cn

Examples

library(mgcv)
mod1 <- gam(Sepal.Length ~ s(Petal.Length) + s(Petal.Width) + Sepal.Width,data = iris)
permu.gamhp(mod=mod1,type="dev",permutations=10)
iv <- list(env1=c("s(Petal.Length)","s(Petal.Width)"),env2="Sepal.Width")
permu.gamhp(mod=mod1,iv,type="dev",permutations=10)

Plot for a gam.hp object

Description

Plot for a gam.hp object

Usage

## S3 method for class 'gamhp'
plot(x, plot.perc = FALSE, ...)

Arguments

x

A gam.hp object.

plot.perc

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

...

unused

Value

a ggplot object

Author(s)

Jiangshan Lai lai@njfu.edu.cn

Examples

library(mgcv)
mod1 <- gam(Sepal.Length ~ s(Petal.Length) + s(Petal.Width) + Sepal.Width,data = iris)
plot(gam.hp(mod1))