title: "A Quick introudction for chaolab utility" output: github_document
knitr::opts_chunk$set(collapse = TRUE, comment = "", fig.retina=2, fig.align='center', fig.width = 7, fig.height = 5, warning = FALSE, message = FALSE)
library(chaoUtility)
chaoUtility
focuses on some useful tools for chao lab, include:
general functions:Boot_p()
and checktype()
phylogeny fucntions:
-phylo2phytree()
: input phylo object(ultrmetric or non-ultrametric), return chaophytree object
-phyExpandData()
: input abundance data, label,chaophytree object, return tibble with abundance or incidence data.
-phyExpandData()
: input abundance data, label,chaophytree object, return tibble with abundance or incidence data.
-phylengthbyT()
: input vector of ageT, chaophytree object, return matrix with label and new branch.length (default rootExtend =T
,if rootExtend=T and ageT>treeH
, root.length=ageT-treeH), non ultrametric tree example
-phyBranchAL()
: input abundance data,phylo object,vector of ageTs, return Chaophyabu object (default rootExtend =T
,remove0=T
)
-phyBranchALinc()
: input incidence_raw data,phylo object,vector of ageTs, return Chaophyabu object (default rootExtend =T
,remove0=T
)
-phy_BranchAL_IncBootP()
: input incidence bootstrp p,phylo object,vector of ageTs, return ChaophyincBP object (default rootExtend =T
,remove0=T
) : the inode formular is 1-(1-p1)(1-p2)
-phylo2chaolabphy()
The chaoUtility
package can be downloaded with a standard R installation procedure using the following commands.
## install the latest version from github install.packages('devtools') library(devtools) install_github('chaolab2019/chaoUtility')
We first describe the main function Boot_p()
with default arguments:
Boot_p(x,zero=TRUE,Bootype="One",datatype="abundance")
Argument | Description |
---|---|
x |
a matrix , data.frame , lists of species abundances or incidence data. |
zero |
reserves zero frequency or not. Default is TRUE. |
Bootype |
character : "One" or "JADE" or "SAR". `Bootype = "One"` or `Bootype = "JADE"` or `Bootype = "SAR"`"One": from #99 2013 Entropy and the species accumulation curve Appendix S2: Estimating species relative abundance. "JADE": from #107 Unveiling the species-rank abundance distribution by generalizing the Good-Turing sample coverage theory. "SAR": :sampleing which was drawn without replacement (based on one parameter estimated method) |
datatype |
data type of input data: individual-based abundance data (`datatype = "abundance"`), or species by sampling-units incidence frequency (`datatype = "incidence_freq"` or `datatype = "incidence"`),or species by sampling-units incidence matrix (`datatype = "incidence_raw"`). |
without replacement:
library(chaoUtility) data(bird) bird.abun<- bird$abun Boot_p(bird$abun,zero=FALSE,Bootype="SAR",datatype="abundance",rho=0.8) data(incdata) Boot_p(incdata,zero=FALSE,Bootype="SAR",datatype="incidence",rho=0.8)
with replacement:One
library(chaoUtility) data(bird) bird.inc <- bird$inci bird.abun<- bird$abun Boot_p(bird$abun, datatype="abundance")
library(chaoUtility) data(treesample) newphy<-phylo2phytree(treesample) class(newphy)
newphy$tips newphy$nodes newphy$phytree newphy$treeH
library(ape) plot(treesample) tiplabels() nodelabels() library(dplyr) nodetext<-newphy$phytree %>% filter(tgroup!="Tip") %>% pull(label) nodelabels(text=nodetext,adj=c(0,2.2)) edgelabels(treesample$edge.length, bg="black", col="white", font=2)
text<-"(((((((A:4,B:4):6,C:5):8,D:6):3,E:21):10,((F:4,G:12):14,H:8):13):13,((I:5,J:2):30,(K:11,L:11):2):17):4,M:56);" library(ape) tree2<-read.tree(text=text) library(chaoUtility) tree2.phytree<-phylo2phytree(tree2) library(dplyr) nodetext<-tree2.phytree$phytree %>% filter(tgroup!="Tip") %>% pull(label) plot(tree2) nodelabels(text=nodetext) edgelabels(tree2$edge.length, bg="black", col="white", font=2) tree2.phytree$treeH as.data.frame(tree2.phytree$phytree) tree2.phytree$leaves tree2.phytree$nodes
text<-"(((((((A:4,B:4):6,C:5):8,D:6):3,E:21):10,((F:4,G:12):14,H:8):13):13,((I:5,J:2):30,(K:11,L:11):2):17):4,M:56);" library(ape) tree2<-read.tree(text=text) library(chaoUtility) tree2.phytree<-phylo2phytree(tree2) library(dplyr) nodetext<-tree2.phytree$phytree %>% filter(tgroup!="Tip") %>% pull(label) plot(tree2) nodelabels(text=nodetext) edgelabels(tree2$edge.length, bg="black", col="white", font=2) tree2.phytree$treeH as.data.frame(tree2.phytree$phytree) tree2.phytree$leaves tree2.phytree$nodes
library(chaoUtility) data(phybird.new) bird.abu <- phybird.new$abun bird.lab <- rownames(phybird.new$abun) bird.phy <- phybird.new$chaophytree bird.abu bird.lab phyExpandData(x=bird.abu, labels=bird.lab, phy=bird.phy, datatype="abundance")
library(chaoUtility) data(phyincisimple) data.inc <- phyincisimple$inci.simple.data data.lab<-rownames(data.inc) phy.inc<-phyincisimple$tree.simple.phytree
library(chaoUtility) data(phyincisimple.new) data.inc <- phyincisimple.new$inci.simple.data data.lab<-rownames(data.inc) phy.inc<-phyincisimple.new$tree.simple.phytree phylotree<-phyincisimple.new$tree.simple plot(phylotree) nodetext<-phy.inc$phytree %>% filter(tgroup!="Tip") %>% pull(label) nodelabels(text=nodetext) edgelabels(phylotree$edge.length, bg="black", col="white", font=2)
data.inc dataNtree<-phyExpandData(data.inc, labels=data.lab, phy=phy.inc, datatype="incidence_raw") as.data.frame(dataNtree)
library(chaoUtility) data(phybird) bird.phy <- phybird$chaophytree bird.phy$treeH phyLengthbyT(Ts=c(90,75,55), phy=bird.phy, datatype="abundance")
text<-"(((((((A:4,B:4):6,C:5):8,D:6):3,E:21):10,((F:4,G:12):14,H:8):13):13,((I:5,J:2):30,(K:11,L:11):2):17):4,M:56);" library(ape) tree2<-read.tree(text=text)
text<-"(((((((A:4,B:4):6,C:5):8,D:6):3,E:21):10,((F:4,G:12):14,H:8):13):13,((I:5,J:2):30,(K:11,L:11):2):17):4,M:56);" library(ape) tree2<-read.tree(text=text) library(chaoUtility) phytree<-phylo2phytree(tree2) phytree$treeH phyLengthbyT(Ts=c(75,55,50), phy=phytree, datatype="abundance",rootExtend=T) library(dplyr) nodetext<-phytree$phytree %>% filter(tgroup!="Tip") %>% pull(label) plot(tree2) nodelabels(text=nodetext) edgelabels(tree2$edge.length, bg="black", col="white", font=2) as.data.frame(phytree$phytree)
data(AbuALdata) adata<-AbuALdata$abudata atree<-AbuALdata$tree vdata<-adata$EM names(vdata)<-rownames(adata) vdata refTs<-c(400,250,100) result<-phyBranchAL_Abu(atree,vdata,datatype="abundance",refTs) ##final branch.abu:removed abu=0 treeNabu<-result$treeNabu treeNabu %>% print(n = Inf) ##final treeH:removed abu=0 result$treeH ##final branch.length:removed abu=0 result$BLbyT ####result$treeNabu is an object of tbl_tree could change to phylo tlb2phylo<-as.phylo(treeNabu) plot(tlb2phylo) ###this is the original tree plot(atree)
data(phybird.new) bird.abu <- phybird.new$abun bird.inc <- phybird.new$inci bird.lab <- rownames(phybird.new$abun) bird.phy <- phybird.new$chaophytree tree<-as.phylo(bird.phy$phytree) Idata<-bird.inc$North.site Idata refTs<-c(80,90,100) result<-phyBranchAL_Inc(tree,Idata,datatype="incidence_raw",refTs) ##final branch.abu:removed abu=0 treeNabu<-result$treeNabu treeNabu %>% print(n = Inf) ##final treeH:removed abu=0 result$treeH ##final branch.length:removed abu=0 result$BLbyT ####result$treeNabu is an object of tbl_tree could change to phylo tlb2phylo<-as.phylo(treeNabu) plot(tlb2phylo) ###this is the original tree plot(tree)
data(phybird.new) bird.abu <- phybird.new$abun bird.inc <- phybird.new$inci bird.lab <- rownames(phybird.new$abun) bird.phy <- phybird.new$chaophytree tree<-as.phylo(bird.phy$phytree) Idata<-bird.inc$North.site refTs<-c(80,90,100) result<-phy_BranchAL_Inc(tree,Idata,datatype="incidence_raw",refTs) ##final branch.abu:removed abu=0 treeNabu<-result$treeNabu treeNabu %>% print(n = Inf) ##final treeH:removed abu=0 result$treeH ##final branch.length:removed abu=0 result$BLbyT ####result$treeNabu is an object of tbl_tree could change to phylo tlb2phylo<-as.phylo(treeNabu) plot(tlb2phylo) ###this is the original tree plot(atree)
data(phyincPdata) pdata <- phyincPdata$pdata phylotree <- phyincPdata$tree pdata refTs<-c(80,90,100) result<-phy_BranchAL_IncBootP(phylotree,pdata,refTs,remove0=FALSE) ##final treeNincBP: treeNincBP<-result$treeNincBP treeNincBP %>% print(n = Inf) ##final treeH: result$treeH ##final branch.length: result$BLbyT ####result$treeNabu is an object of tbl_tree could change to phylo tlb2phylo<-as.phylo(treeNincBP) plot(tlb2phylo) ###this is the original tree plot(phylotree)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.