R: Compute species-specific rate through time trajectories
speciesByRatesMatrix
R Documentation
Compute species-specific rate through time trajectories
Description
Computes the mean of the marginal posterior density of
speciation/extinction or phenotypic rates for equally spaced points
along the root to tip path for each species.
Usage
speciesByRatesMatrix(ephy, nslices, index = NULL, spex = "s")
Arguments
ephy
An object of class bammdata.
nslices
An integer number of time slices. This determines the
number of equally spaced points in time at which rates are computed
for each species.
index
An integer or vector of mode integer indicating which
posterior samples to use in the calculation. If NULL (default)
all samples are used.
spex
A character string. "s" (default) calculates speciation rates;
"e" calculates extinction rates; "netdiv" calculates diversification
rates. Ignored if ephy$type = "trait".
Value
A list with two components:
times A vector of time points where rates were
calculated.
rates A species X times matrix of rate through time
trajectories.
data(whales, events.whales)
ed <- getEventData(whales,events.whales,burnin=0.25, nsamples=500)
ratemat <- speciesByRatesMatrix(ed, nslices = 100)
dolphins <- extract.clade(whales,140)$tip.label
plot.new()
plot.window(xlim=c(0,35),ylim=c(0,0.8))
for (i in 1:nrow(ratemat$rates)) {
if (whales$tip.label[i] %in% dolphins) {
lines(ratemat$times, ratemat$rates[i,], lwd=2, col=4)
} else {
lines(ratemat$times, ratemat$rates[i,], lwd=2, col=8)
}
}
axis(1,seq(-5,35,5))
axis(2,seq(-0.2,0.8,0.2),las=1)
mtext("Time since root",1,line=2.5)
mtext("Speciation rate",2,line=2.5)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(BAMMtools)
Loading required package: ape
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/BAMMtools/speciesByRatesMatrix.Rd_%03d_medium.png", width=480, height=480)
> ### Name: speciesByRatesMatrix
> ### Title: Compute species-specific rate through time trajectories
> ### Aliases: speciesByRatesMatrix
> ### Keywords: models
>
> ### ** Examples
>
> data(whales, events.whales)
> ed <- getEventData(whales,events.whales,burnin=0.25, nsamples=500)
Processing event data from data.frame
Discarded as burnin: GENERATIONS < 2495000
Analyzing 500 samples from posterior
Setting recursive sequence on tree...
Done with recursive sequence
> ratemat <- speciesByRatesMatrix(ed, nslices = 100)
>
> dolphins <- extract.clade(whales,140)$tip.label
> plot.new()
> plot.window(xlim=c(0,35),ylim=c(0,0.8))
> for (i in 1:nrow(ratemat$rates)) {
+ if (whales$tip.label[i] %in% dolphins) {
+ lines(ratemat$times, ratemat$rates[i,], lwd=2, col=4)
+ } else {
+ lines(ratemat$times, ratemat$rates[i,], lwd=2, col=8)
+ }
+ }
> axis(1,seq(-5,35,5))
> axis(2,seq(-0.2,0.8,0.2),las=1)
> mtext("Time since root",1,line=2.5)
> mtext("Speciation rate",2,line=2.5)
>
>
>
>
>
> dev.off()
null device
1
>