Data
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.
tre <- read.tree(text=carni19$tre)
And we create a dataframe of 3 traits for the 19 carnivora
species.
- Body mass
- Random values
- Simulated values under a Brownian Motion model along the tree
dat <- list()
dat$mass <- carni19$bm
dat$random <- rnorm(19, sd = 10)
dat$bm <- rTraitCont(tre)
dat <- as.data.frame(dat)
We can combine phylogeny and traits into a phylo4d
object.
Measuring and testing the signal for each trait and different
methods
phyloSignal(p4d = p4d, method = "all")
## $stat
## Cmean I K K.star Lambda
## mass 0.5493887 0.3921068 0.7127747 0.7154914 9.640762e-01
## random -0.1935545 -0.1787461 0.1054534 0.1065616 6.846792e-05
## bm 0.5980953 0.4008083 1.1829240 1.1864567 1.026244e+00
##
## $pvalue
## Cmean I K K.star Lambda
## mass 0.001 0.003 0.001 0.001 0.001
## random 0.815 0.898 0.756 0.749 1.000
## bm 0.001 0.001 0.001 0.001 0.001
Assessing the behavior of these methods with this phylogeny along a
Brownian-Motion influence gradient
phylosim <- phyloSim(tree = tre, method = "all", nsim = 100, reps = 99)
plot(phylosim, stacked.methods = FALSE, quantiles = c(0.05, 0.95))
plot.phylosim(phylosim, what = "pval", stacked.methods = TRUE)
Locating the signal with LIPA
carni.lipa <- lipaMoran(p4d)
carni.lipa.p4d <- lipaMoran(p4d, as.p4d = TRUE)
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)