Below we demonstrate how to extract evolutionary rate summarystatistics from each node from a Bayesian clock (time-calibrate) summarytree produced by Mr. Bayes, store them in a data frame, produce summarytables, and plots.
1. Import combined log file from all runs.
This is produced by usingcombine_log().The firstargument passed tocombine_log() should be a path to thefolder containing the log files to be imported and combined.
## Import all log (.p) files from all runs and combine them, with burn-in = 25%## and downsampling to 2.5k trees in each log fileposterior3p<-combine_log("LogFiles3p",burnin =0.25,downsample =1000)
Below, we use the posterior datasetposterior3p thataccompaniesEvoPhylo.
data(posterior3p)## Show first 5 lines of combined log filehead(posterior3p,5)
The posterior data must first be transformed from wide to long to beused with the functions described below;FBD_reshape()accomplishes this.
## Reshape imported combined log file from wide to long with FBD_reshapeposterior3p_long<-FBD_reshape(posterior3p,variables =NULL,log.type ="MrBayes")
2. Summarize FBD parameters by time bin
Summary statistics for each FBD parameter by time bin can be quicklysummarized usingFBD_summary():
## Summarize parameters by time bin and analysist3.1<-FBD_summary(posterior3p_long)t3.1
FBD parameters by time bin| parameter | Time_bin | n | mean | sd | min | Q1 | median | Q3 | max |
|---|
| net_speciation | 1 | 10000 | 0.04 | 0.02 | 0.00 | 0.03 | 0.04 | 0.06 | 0.17 |
| net_speciation | 2 | 10000 | 0.03 | 0.02 | 0.00 | 0.02 | 0.03 | 0.04 | 0.12 |
| net_speciation | 3 | 10000 | 0.02 | 0.01 | 0.00 | 0.01 | 0.02 | 0.03 | 0.12 |
| net_speciation | 4 | 10000 | 0.05 | 0.02 | 0.00 | 0.03 | 0.05 | 0.06 | 0.12 |
| relative_extinction | 1 | 10000 | 0.79 | 0.15 | 0.08 | 0.71 | 0.82 | 0.90 | 1.00 |
| relative_extinction | 2 | 10000 | 0.93 | 0.05 | 0.55 | 0.90 | 0.93 | 0.96 | 1.00 |
| relative_extinction | 3 | 10000 | 0.95 | 0.05 | 0.18 | 0.93 | 0.96 | 0.98 | 1.00 |
| relative_extinction | 4 | 10000 | 0.03 | 0.10 | 0.00 | 0.00 | 0.00 | 0.01 | 0.97 |
| relative_fossilization | 1 | 10000 | 0.04 | 0.05 | 0.00 | 0.01 | 0.02 | 0.05 | 0.72 |
| relative_fossilization | 2 | 10000 | 0.07 | 0.04 | 0.00 | 0.04 | 0.06 | 0.09 | 0.36 |
| relative_fossilization | 3 | 10000 | 0.01 | 0.02 | 0.00 | 0.00 | 0.01 | 0.02 | 0.54 |
| relative_fossilization | 4 | 10000 | 0.04 | 0.11 | 0.00 | 0.00 | 0.00 | 0.02 | 0.99 |
## Export the tablewrite.csv(t3.1,file ="FBD_summary.csv")
3. Plot the distribution of each FBD parameter
Each of (or all) the FBD parameter distributions can be plotted bytime bin using various plotting alternatives withFBD_dens_plot():
## Plot distribution of the desired FBD parameter by time bin with## kernel density plotFBD_dens_plot(posterior3p_long,parameter ="net_speciation",type ="density",stack =FALSE)

## Plot distribution of the desired FBD parameter by time bin with## stacked kernel density plotFBD_dens_plot(posterior3p_long,parameter ="net_speciation",type ="density",stack =TRUE)

## Plot distribution of the desired FBD parameter by time bin with## a violin plotFBD_dens_plot(posterior3p_long,parameter ="net_speciation",type ="violin",stack =FALSE,color ="red")

## Plot distribution of all FBD parameter by time bin with a violin plotp1<-FBD_dens_plot(posterior3p_long,parameter ="net_speciation",type ="violin",stack =FALSE,color ="red")p2<-FBD_dens_plot(posterior3p_long,parameter ="relative_extinction",type ="violin",stack =FALSE,color ="cyan3")p3<-FBD_dens_plot(posterior3p_long,parameter ="relative_fossilization",type ="violin",stack =FALSE,color ="green3")library(patchwork)p1+ p2+ p3+plot_layout(nrow =1)

## Save your plot to your working directory as a PDFggplot2::ggsave("Plot_regs.pdf",width =12,height =4)
4. Test for assumptions
In this step, users can perform tests for normality andhomoscedasticity in data distribution for each of the FBD parametersunder consideration. The output will determine whether parametric ornonparametric tests will be performed subsequently.
##### Tests for normality and homoscedasticity for each FBD parameter for all time binst3.2<-FBD_tests1(posterior3p_long)
### Export the output table for all testswrite.csv(t3.2,file ="FBD_Tests1_Assum.csv")
The results of the Shapiro-Wilk normality test for each parameter canbe output as seperate tables or as a single combined table.
# Output as separate tablest3.2$shapiro
Shapiro-Wilk normality test | parameter | statistic | p-value |
|---|
| Time bin 1 | net_speciation | 0.9917 | 0 | | Time bin 2 | net_speciation | 0.9385 | 0 | | Time bin 3 | net_speciation | 0.9227 | 0 | | Time bin 4 | net_speciation | 0.9898 | 0 | | Overall | net_speciation | 0.9568 | 0 | | Residuals | net_speciation | 0.9874 | 0 |
| | parameter | statistic | p-value |
|---|
| Time bin 1 | relative_extinction | 0.8927 | 0 | | Time bin 2 | relative_extinction | 0.9247 | 0 | | Time bin 3 | relative_extinction | 0.8044 | 0 | | Time bin 4 | relative_extinction | 0.3775 | 0 | | Overall | relative_extinction | 0.7036 | 0 | | Residuals | relative_extinction | 0.8238 | 0 |
| | parameter | statistic | p-value |
|---|
| Time bin 1 | relative_fossilization | 0.5764 | 0 | | Time bin 2 | relative_fossilization | 0.8853 | 0 | | Time bin 3 | relative_fossilization | 0.6210 | 0 | | Time bin 4 | relative_fossilization | 0.4637 | 0 | | Overall | relative_fossilization | 0.5473 | 0 | | Residuals | relative_fossilization | 0.5531 | 0 |
|
# OR as single merged tablet3.2$shapiro$net_speciation$bin<-row.names(t3.2$shapiro$net_speciation)t3.2$shapiro$relative_extinction$bin<-row.names(t3.2$shapiro$relative_extinction)t3.2$shapiro$relative_fossilization$bin<-row.names(t3.2$shapiro$relative_fossilization)k1all<-rbind(t3.2$shapiro$net_speciation, t3.2$shapiro$relative_extinction, t3.2$shapiro$relative_fossilization,make.row.names =FALSE)
Shapiro-Wilk normality test| parameter | statistic | p-value | bin |
|---|
| net_speciation | 0.9917 | 0 | Time bin 1 |
| net_speciation | 0.9385 | 0 | Time bin 2 |
| net_speciation | 0.9227 | 0 | Time bin 3 |
| net_speciation | 0.9898 | 0 | Time bin 4 |
| net_speciation | 0.9568 | 0 | Overall |
| net_speciation | 0.9874 | 0 | Residuals |
| relative_extinction | 0.8927 | 0 | Time bin 1 |
| relative_extinction | 0.9247 | 0 | Time bin 2 |
| relative_extinction | 0.8044 | 0 | Time bin 3 |
| relative_extinction | 0.3775 | 0 | Time bin 4 |
| relative_extinction | 0.7036 | 0 | Overall |
| relative_extinction | 0.8238 | 0 | Residuals |
| relative_fossilization | 0.5764 | 0 | Time bin 1 |
| relative_fossilization | 0.8853 | 0 | Time bin 2 |
| relative_fossilization | 0.6210 | 0 | Time bin 3 |
| relative_fossilization | 0.4637 | 0 | Time bin 4 |
| relative_fossilization | 0.5473 | 0 | Overall |
| relative_fossilization | 0.5531 | 0 | Residuals |
## Bartlett's test for homogeneity of variancet3.2$bartlett
Bartlett’s test| parameter | statistic | p-value |
|---|
| net_speciation | 3815.464 | 0 |
| relative_extinction | 18159.213 | 0 |
| relative_fossilization | 25654.975 | 0 |
## Fligner-Killeen test for homogeneity of variancet3.2$fligner
Fligner-Killeen test| parameter | statistic | p-value |
|---|
| net_speciation | 3748.140 | 0 |
| relative_extinction | 12599.843 | 0 |
| relative_fossilization | 4808.545 | 0 |
Deviations from normality can be displayed graphically usingFBD_normality_plot():
## Visualize deviations from normality and similarity of variancesFBD_normality_plot(posterior3p_long)

## Save your plot to your working directory as a PDFggplot2::ggsave("Plot_normTests.pdf",width =8,height =6)
5. Test for significant FBD shifts between time bins
Significant shifts in FBD parameters across time bins can be easilytested using parametric (Student’s t-test) and nonparametric(Mann-Whitney test) pairwise comparisons withFBD_tests2().Both are automatically calculated and the preferred pairwise comparisonwill be chosen by the user depending on the results of the assumptiontestsstep #4 (above).
##### Test for significant differences between each time bin for each FBD parametert3.3<-FBD_tests2(posterior3p_long)
### Export the output table for all testswrite.csv(t3.3,file ="FBD_Tests2_Sign.csv")## Pairwise t-tests# Output as separate tablest3.3$t_tests
Significant tests| parameter | Time_bin1 | Time_bin2 | n1 | n2 | p-value | p-value adj |
|---|
| net_speciation | 1 | 2 | 10000 | 10000 | 0 | 0 | | net_speciation | 1 | 3 | 10000 | 10000 | 0 | 0 | | net_speciation | 1 | 4 | 10000 | 10000 | 0 | 0 | | net_speciation | 2 | 3 | 10000 | 10000 | 0 | 0 | | net_speciation | 2 | 4 | 10000 | 10000 | 0 | 0 | | net_speciation | 3 | 4 | 10000 | 10000 | 0 | 0 |
| | parameter | Time_bin1 | Time_bin2 | n1 | n2 | p-value | p-value adj |
|---|
| relative_extinction | 1 | 2 | 10000 | 10000 | 0 | 0 | | relative_extinction | 1 | 3 | 10000 | 10000 | 0 | 0 | | relative_extinction | 1 | 4 | 10000 | 10000 | 0 | 0 | | relative_extinction | 2 | 3 | 10000 | 10000 | 0 | 0 | | relative_extinction | 2 | 4 | 10000 | 10000 | 0 | 0 | | relative_extinction | 3 | 4 | 10000 | 10000 | 0 | 0 |
| | parameter | Time_bin1 | Time_bin2 | n1 | n2 | p-value | p-value adj |
|---|
| relative_fossilization | 1 | 2 | 10000 | 10000 | 0 | 0 | | relative_fossilization | 1 | 3 | 10000 | 10000 | 0 | 0 | | relative_fossilization | 1 | 4 | 10000 | 10000 | 0 | 0 | | relative_fossilization | 2 | 3 | 10000 | 10000 | 0 | 0 | | relative_fossilization | 2 | 4 | 10000 | 10000 | 0 | 0 | | relative_fossilization | 3 | 4 | 10000 | 10000 | 0 | 0 |
|
# OR as single merged tablek3.3a<-rbind(t3.3$t_tests$net_speciation, t3.3$t_tests$relative_extinction, t3.3$t_tests$relative_fossilization,make.row.names =FALSE)
Pairwise t-tests| parameter | Time_bin1 | Time_bin2 | n1 | n2 | p-value | p-value adj |
|---|
| net_speciation | 1 | 2 | 10000 | 10000 | 0 | 0 |
| net_speciation | 1 | 3 | 10000 | 10000 | 0 | 0 |
| net_speciation | 1 | 4 | 10000 | 10000 | 0 | 0 |
| net_speciation | 2 | 3 | 10000 | 10000 | 0 | 0 |
| net_speciation | 2 | 4 | 10000 | 10000 | 0 | 0 |
| net_speciation | 3 | 4 | 10000 | 10000 | 0 | 0 |
| relative_extinction | 1 | 2 | 10000 | 10000 | 0 | 0 |
| relative_extinction | 1 | 3 | 10000 | 10000 | 0 | 0 |
| relative_extinction | 1 | 4 | 10000 | 10000 | 0 | 0 |
| relative_extinction | 2 | 3 | 10000 | 10000 | 0 | 0 |
| relative_extinction | 2 | 4 | 10000 | 10000 | 0 | 0 |
| relative_extinction | 3 | 4 | 10000 | 10000 | 0 | 0 |
| relative_fossilization | 1 | 2 | 10000 | 10000 | 0 | 0 |
| relative_fossilization | 1 | 3 | 10000 | 10000 | 0 | 0 |
| relative_fossilization | 1 | 4 | 10000 | 10000 | 0 | 0 |
| relative_fossilization | 2 | 3 | 10000 | 10000 | 0 | 0 |
| relative_fossilization | 2 | 4 | 10000 | 10000 | 0 | 0 |
| relative_fossilization | 3 | 4 | 10000 | 10000 | 0 | 0 |
## Mann-Whitney tests (use if Tests in step #4 fail assumptions)# Output as separate tablest3.3$mwu_tests
Mann-Whitney tests| parameter | Time_bin1 | Time_bin2 | n1 | n2 | p-value | p-value adj |
|---|
| net_speciation | 1 | 2 | 10000 | 10000 | 0 | 0 | | net_speciation | 1 | 3 | 10000 | 10000 | 0 | 0 | | net_speciation | 1 | 4 | 10000 | 10000 | 0 | 0 | | net_speciation | 2 | 3 | 10000 | 10000 | 0 | 0 | | net_speciation | 2 | 4 | 10000 | 10000 | 0 | 0 | | net_speciation | 3 | 4 | 10000 | 10000 | 0 | 0 |
| | parameter | Time_bin1 | Time_bin2 | n1 | n2 | p-value | p-value adj |
|---|
| relative_extinction | 1 | 2 | 10000 | 10000 | 0 | 0 | | relative_extinction | 1 | 3 | 10000 | 10000 | 0 | 0 | | relative_extinction | 1 | 4 | 10000 | 10000 | 0 | 0 | | relative_extinction | 2 | 3 | 10000 | 10000 | 0 | 0 | | relative_extinction | 2 | 4 | 10000 | 10000 | 0 | 0 | | relative_extinction | 3 | 4 | 10000 | 10000 | 0 | 0 |
| | parameter | Time_bin1 | Time_bin2 | n1 | n2 | p-value | p-value adj |
|---|
| relative_fossilization | 1 | 2 | 10000 | 10000 | 0 | 0 | | relative_fossilization | 1 | 3 | 10000 | 10000 | 0 | 0 | | relative_fossilization | 1 | 4 | 10000 | 10000 | 0 | 0 | | relative_fossilization | 2 | 3 | 10000 | 10000 | 0 | 0 | | relative_fossilization | 2 | 4 | 10000 | 10000 | 0 | 0 | | relative_fossilization | 3 | 4 | 10000 | 10000 | 0 | 0 |
|
# OR as single merged tablek3.3b<-rbind(t3.3$mwu_tests$net_speciation, t3.3$mwu_tests$relative_extinction, t3.3$mwu_tests$relative_fossilization,make.row.names =FALSE)
Mann-Whitney tests| parameter | Time_bin1 | Time_bin2 | n1 | n2 | p-value | p-value adj |
|---|
| net_speciation | 1 | 2 | 10000 | 10000 | 0 | 0 |
| net_speciation | 1 | 3 | 10000 | 10000 | 0 | 0 |
| net_speciation | 1 | 4 | 10000 | 10000 | 0 | 0 |
| net_speciation | 2 | 3 | 10000 | 10000 | 0 | 0 |
| net_speciation | 2 | 4 | 10000 | 10000 | 0 | 0 |
| net_speciation | 3 | 4 | 10000 | 10000 | 0 | 0 |
| relative_extinction | 1 | 2 | 10000 | 10000 | 0 | 0 |
| relative_extinction | 1 | 3 | 10000 | 10000 | 0 | 0 |
| relative_extinction | 1 | 4 | 10000 | 10000 | 0 | 0 |
| relative_extinction | 2 | 3 | 10000 | 10000 | 0 | 0 |
| relative_extinction | 2 | 4 | 10000 | 10000 | 0 | 0 |
| relative_extinction | 3 | 4 | 10000 | 10000 | 0 | 0 |
| relative_fossilization | 1 | 2 | 10000 | 10000 | 0 | 0 |
| relative_fossilization | 1 | 3 | 10000 | 10000 | 0 | 0 |
| relative_fossilization | 1 | 4 | 10000 | 10000 | 0 | 0 |
| relative_fossilization | 2 | 3 | 10000 | 10000 | 0 | 0 |
| relative_fossilization | 2 | 4 | 10000 | 10000 | 0 | 0 |
| relative_fossilization | 3 | 4 | 10000 | 10000 | 0 | 0 |