First, we load the package phylosignal
and the dataset carnivora
from adephylo
.
library(phylosignal)
library(adephylo)
library(ape)
library(phylobase)
data(carni19)
Here is a phylogenetic tree of 19 carnivora species.
read.tree(text=carni19$tre) tre <-
And we create a dataframe of 3 traits for the 19 carnivora species.
list()
dat <-$mass <- carni19$bm
dat$random <- rnorm(19, sd = 10)
dat$bm <- rTraitCont(tre)
dat as.data.frame(dat) dat <-
We can combine phylogeny and traits into a phylo4d
object.
phylo4d(tre, dat) p4d <-
barplot.phylo4d(p4d, tree.type = "phylo", tree.ladderize = TRUE)
phyloSignal(p4d = p4d, method = "all")
## $stat
## Cmean I K K.star Lambda
## mass 0.549388707 0.39210678 0.7127747 0.7154914 9.640762e-01
## random -0.008591412 -0.01054837 0.1710380 0.1656598 6.846792e-05
## bm 0.631997788 0.54900008 1.2066485 1.2041770 1.027115e+00
##
## $pvalue
## Cmean I K K.star Lambda
## mass 0.002 0.001 0.001 0.001 0.001
## random 0.373 0.311 0.167 0.208 1.000
## bm 0.001 0.001 0.001 0.001 0.001
phyloSim(tree = tre, method = "all", nsim = 100, reps = 99) phylosim <-
plot(phylosim, stacked.methods = FALSE, quantiles = c(0.05, 0.95))
plot.phylosim(phylosim, what = "pval", stacked.methods = TRUE)
phyloCorrelogram(p4d, trait = "mass")
mass.crlg <- phyloCorrelogram(p4d, trait = "random")
random.crlg <- phyloCorrelogram(p4d, trait = "bm")
bm.crlg <-
plot(mass.crlg)
plot(random.crlg)
plot(bm.crlg)
lipaMoran(p4d)
carni.lipa <- lipaMoran(p4d, as.p4d = TRUE)
carni.lipa.p4d <-
barplot.phylo4d(p4d, bar.col=(carni.lipa$p.value < 0.05) + 1, center = FALSE , scale = FALSE)
barplot.phylo4d(carni.lipa.p4d, bar.col = (carni.lipa$p.value < 0.05) + 1, center = FALSE, scale = FALSE)