Type: Package
Title: Hierarchical Partitioning of R2 for Phylogenetic Linear Regression
Version: 0.0-3
Date: 2024-11-30
Depends: R (≥ 3.4.0),rr2,phylolm,ggplot2,vegan
Maintainer: Jiangshan Lai <lai@njfu.edu.cn>
Description: Conducts hierarchical partitioning to calculate individual contributions of phylogenetic tree and predictors (groups) towards total R2 for phylogenetic linear regression models.
License: GPL-2 | GPL-3 [expanded from: GPL]
Encoding: UTF-8
URL: https://github.com/laijiangshan/phylolm.hp
RoxygenNote: 7.3.1
NeedsCompilation: no
Packaged: 2024-12-01 00:02:16 UTC; lai
Author: Jiangshan Lai ORCID iD [aut, cre], Gang Wang [aut]
Repository: CRAN
Date/Publication: 2024-12-05 15: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


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


Hierarchical Partitioning of R2 for Phylogenetic Generalized Linear Regression

Description

Hierarchical Partitioning of R2 for Phylogenetic Generalized Linear Regression

Usage

phyloglm.hp(mod, iv = NULL, commonality = FALSE)

Arguments

mod

Fitted phylolm or phyloglm model objects.

iv

optional the relative importance of predicotr groups will be evaluated. The input for iv should be a list containing the names of each group of variables. The variable names must be the names of the predictor variables in mod.

commonality

Logical; If TRUE, the result of commonality analysis is shown, the default is FALSE.

Details

This function conducts hierarchical partitioning to calculate the individual contributions of phylogenetic signal and each predictor towards total R2 from rr2 package for phylogenetic linear regression.

Value

Total.R2

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).

Individual.R2

A matrix containing individual effects and percentage of individual effects for phylogenetic tree and each predictor

Author(s)

Jiangshan Lai lai@njfu.edu.cn

References

Examples

library(phylolm)
library(rr2)
set.seed(231)
tre <- rcoal(60)
taxa <- sort(tre$tip.label) 
b0 <- 0      
b1 <- 0.3    
b2 <- 0.5 
b3 <- 0.4
x <- rTrait(n=1, phy=tre, model="lambda", parameters=list(ancestral.state=0, sigma2=15, lambda=0.9))          
x2 <- rTrait(n=1, phy=tre, model="lambda",  
parameters=list(ancestral.state=0, sigma2=10, lambda=0.9))  
x3 <- rTrait(n=1, phy=tre, model="lambda",  
parameters=list(ancestral.state=0, sigma2=13, lambda=0.9)) 
y <- b0 + b1 * x + b2 * x2 + b3*x3+ rTrait(n=1, phy=tre, model="lambda",
parameters=list(ancestral.state=0, sigma2=5, lambda=0.9))            
dat <- data.frame(trait=y[taxa], pred=x[taxa], pred2=x2[taxa],pred3=x3[taxa])
fit <- phylolm(trait ~ pred + pred2 + pred3, data=dat, phy=tre, model="lambda")
phyloglm.hp(fit,commonality=TRUE)
iv=list(env1="pred",env2=c("pred2","pred3"))
phyloglm.hp(fit,iv)
set.seed(123456)
tre <- rtree(50)
x1 <- rTrait(n=1, phy=tre)  
x2 <- rTrait(n=1, phy=tre)
x3 <- rTrait(n=1, phy=tre)
X <- cbind(rep(1, 50), x1, x2, x3)
y <- rbinTrait(n=1, phy=tre, beta=c(-1, 0.9, 0.9, 0.5), alpha=1, X=X)
dat <- data.frame(trait01=y, predictor1=x1, predictor2=x2, predictor3=x3)
fit <- phyloglm(trait01 ~ predictor1 + predictor2 + predictor3, phy=tre, data=dat)
phyloglm.hp(fit)
iv=list(env1="predictor1",env2=c("predictor2","predictor3"))
phyloglm.hp(fit,iv)

Hierarchical Partitioning of R2 for Phylogenetic Linear Regression

Description

Hierarchical Partitioning of R2 for Phylogenetic Linear Regression

Usage

phylolm.hp(mod, iv = NULL, commonality = FALSE)

Arguments

mod

Fitted phylolm or phyloglm model objects.

iv

optional the relative importance of predicotr groups will be evaluated. The input for iv should be a list containing the names of each group of variables. The variable names must be the names of the predictor variables in mod.

commonality

Logical; If TRUE, the result of commonality analysis is shown, the default is FALSE.

Details

This function conducts hierarchical partitioning to calculate the individual contributions of phylogenetic signal and each predictor towards total R2 from rr2 package for phylogenetic linear regression.

Value

Total.R2

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).

Individual.R2

A matrix containing individual effects and percentage of individual effects for phylogenetic tree and each predictor

Author(s)

Jiangshan Lai lai@njfu.edu.cn

References

Examples

library(phylolm)
library(rr2)
set.seed(231)
tre <- rcoal(60)
taxa <- sort(tre$tip.label) 
b0 <- 0      
b1 <- 0.3    
b2 <- 0.5 
b3 <- 0.4
x <- rTrait(n=1, phy=tre, model="lambda", parameters=list(ancestral.state=0, sigma2=15, lambda=0.9))          
x2 <- rTrait(n=1, phy=tre, model="lambda",  
parameters=list(ancestral.state=0, sigma2=10, lambda=0.9))  
x3 <- rTrait(n=1, phy=tre, model="lambda",  
parameters=list(ancestral.state=0, sigma2=13, lambda=0.9)) 
y <- b0 + b1 * x + b2 * x2 + b3*x3+ rTrait(n=1, phy=tre, model="lambda",
parameters=list(ancestral.state=0, sigma2=5, lambda=0.9))            
dat <- data.frame(trait=y[taxa], pred=x[taxa], pred2=x2[taxa],pred3=x3[taxa])
fit <- phylolm(trait ~ pred + pred2 + pred3, data=dat, phy=tre, model="lambda")
phylolm.hp(fit,commonality=TRUE)
iv=list(env1="pred",env2=c("pred2","pred3"))
phylolm.hp(fit,iv)
set.seed(123456)
tre <- rtree(50)
x1 <- rTrait(n=1, phy=tre)  
x2 <- rTrait(n=1, phy=tre)
x3 <- rTrait(n=1, phy=tre)
X <- cbind(rep(1, 50), x1, x2, x3)
y <- rbinTrait(n=1, phy=tre, beta=c(-1, 0.9, 0.9, 0.5), alpha=1, X=X)
dat <- data.frame(trait01=y, predictor1=x1, predictor2=x2, predictor3=x3)
fit <- phyloglm(trait01 ~ predictor1 + predictor2 + predictor3, phy=tre, data=dat)
phylolm.hp(fit)
iv=list(env1="predictor1",env2=c("predictor2","predictor3"))
phylolm.hp(fit,iv)

Plot for a phyloglm.hp object

Description

Plot for a phyloglm.hp object

Usage

## S3 method for class 'phyloglmhp'
plot(x, plot.perc = FALSE, commonality = FALSE, color = NULL, dig = 4, ...)

Arguments

x

A phyloglm.hp object.

plot.perc

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

commonality

Logical; If TRUE, the result of commonality analysis is shown, the default is FALSE.

color

Color of variables.

dig

Integer; number of decimal places in Venn diagram.

...

unused

Value

a ggplot object

Author(s)

Jiangshan Lai lai@njfu.edu.cn

Examples

library(phylolm)
library(rr2)
set.seed(123456)
tre <- rtree(50)
x1 <- rTrait(n=1, phy=tre)  
x2 <- rTrait(n=1, phy=tre)
X <- cbind(rep(1, 50), x1, x2)
y <- rbinTrait(n=1, phy=tre, beta=c(-1, 0.8, 0.9), alpha=1, X=X)
dat <- data.frame(trait01=y, predictor1=x1, predictor2=x2)
fit <- phyloglm(trait01 ~ predictor1 + predictor2, phy=tre, data=dat)
plot(phyloglm.hp(fit,commonality=TRUE))
plot(phyloglm.hp(fit,commonality=TRUE),commonality=TRUE)