if (deepSTRAPP::is_dev_version())
{
# ----- Example 1: Continuous trait ----- #
# Load fake trait df
data(Ponerinae_trait_tip_data, package = "deepSTRAPP")
# Load phylogeny with old calibration
data(Ponerinae_tree_old_calib, package = "deepSTRAPP")
# Load the BAMM_object summarizing 1000 posterior samples of BAMM
data(Ponerinae_BAMM_object_old_calib, package = "deepSTRAPP")
## This dataset is only available in development versions installed from GitHub.
# It is not available in CRAN versions.
# Use remotes::install_github(repo = "MaelDore/deepSTRAPP") to get the latest development version.
## Prepare trait data
# Extract continuous trait data as a named vector
Ponerinae_cont_tip_data <- setNames(object = Ponerinae_trait_tip_data$fake_cont_tip_data,
nm = Ponerinae_trait_tip_data$Taxa)
# Select a color scheme from lowest to highest values
color_scale = c("darkgreen", "limegreen", "orange", "red")
# Get Ancestral Character Estimates based on a Brownian Motion model
# To obtain values at internal nodes
Ponerinae_ACE <- phytools::fastAnc(tree = Ponerinae_tree_old_calib, x = Ponerinae_cont_tip_data)
# (May take several minutes to run)
# Run a Stochastic Mapping based on a Brownian Motion model
# to interpolate values along branches and obtain a "contMap" object
Ponerinae_contMap <- phytools::contMap(Ponerinae_tree, x = Ponerinae_cont_tip_data,
res = 100, # Number of time steps
plot = FALSE)
# Plot contMap = stochastic mapping of continuous trait
plot_contMap(contMap = Ponerinae_contMap,
color_scale = color_scale)
## Set focal time to 10 Mya
focal_time <- 10
## Run deepSTRAPP on net diversification rates for focal time = 10 Mya.
Ponerinae_deepSTRAPP_cont_old_calib_10My <- run_deepSTRAPP_for_focal_time(
contMap = Ponerinae_contMap,
ace = Ponerinae_ACE,
tip_data = Ponerinae_cont_tip_data,
trait_data_type = "continuous",
BAMM_object = Ponerinae_BAMM_object_old_calib,
focal_time = focal_time,
rate_type = "net_diversification",
return_perm_data = TRUE,
extract_diversification_data_melted_df = TRUE,
return_updated_trait_data_with_Map = TRUE,
return_updated_BAMM_object = TRUE)
## Explore output
str(Ponerinae_deepSTRAPP_cont_old_calib_10My, max.level = 1)
# ----- Plot histogram of STRAPP overall test results from run_deepSTRAPP_for_focal_time() ----- #
histogram_ggplot <- plot_histogram_STRAPP_test_for_focal_time(
deepSTRAPP_outputs = Ponerinae_deepSTRAPP_cont_old_calib_10My,
display_plot = TRUE,
# PDF_file_path = "./plot_STRAPP_histogram_10My.pdf",
plot_posthoc_tests = FALSE)
# Adjust aesthetics a posteriori
histogram_ggplot_adj <- histogram_ggplot +
ggplot2::theme(plot.title = ggplot2::element_text(color = "red", size = 15))
print(histogram_ggplot_adj)
# ----- Plot histogram of STRAPP overall test results from run_deepSTRAPP_over_time() ----- #
## Load directly outputs from run_deepSTRAPP_over_time()
data(Ponerinae_deepSTRAPP_cont_old_calib_0_40, package = "deepSTRAPP")
## This dataset is only available in development versions installed from GitHub.
# It is not available in CRAN versions.
# Use remotes::install_github(repo = "MaelDore/deepSTRAPP") to get the latest development version.
# Select focal_time = 10My
focal_time <- 10
## Plot histogram for overall test
histogram_ggplot <- plot_histogram_STRAPP_test_for_focal_time(
deepSTRAPP_outputs = Ponerinae_deepSTRAPP_cont_old_calib_0_40,
focal_time = focal_time,
display_plot = TRUE,
# PDF_file_path = "./plot_STRAPP_histogram_10My.pdf",
plot_posthoc_tests = FALSE)
# Adjust aesthetics a posteriori
histogram_ggplot_adj <- histogram_ggplot +
ggplot2::theme(plot.title = ggplot2::element_text(color = "red", size = 15))
print(histogram_ggplot_adj)
# ----- Example 2: Categorical trait ----- #
## Load data
# Load phylogeny
data(Ponerinae_tree, package = "deepSTRAPP")
# Load trait df
data(Ponerinae_trait_tip_data, package = "deepSTRAPP")
# Load the BAMM_object summarizing 1000 posterior samples of BAMM
data(Ponerinae_BAMM_object_old_calib, package = "deepSTRAPP")
## This dataset is only available in development versions installed from GitHub.
# It is not available in CRAN versions.
# Use remotes::install_github(repo = "MaelDore/deepSTRAPP") to get the latest development version.
## Prepare trait data
# Extract categorical data with 3-levels
Ponerinae_cat_3lvl_tip_data <- setNames(object = Ponerinae_trait_tip_data$fake_cat_3lvl_tip_data,
nm = Ponerinae_trait_tip_data$Taxa)
table(Ponerinae_cat_3lvl_tip_data)
# Select color scheme for states
colors_per_states <- c("forestgreen", "sienna", "goldenrod")
names(colors_per_states) <- c("arboreal", "subterranean", "terricolous")
# (May take several minutes to run)
## Produce densityMaps using stochastic character mapping based on an ARD Mk model
Ponerinae_cat_3lvl_data_old_calib <- prepare_trait_data(
tip_data = Ponerinae_cat_3lvl_tip_data,
phylo = Ponerinae_tree_old_calib,
trait_data_type = "categorical",
colors_per_states = colors_per_states,
evolutionary_models = "ARD", # Use default ARD model
nb_simulations = 100, # Reduce number of simulations to save time
seed = 1234, # Seet seed for reproducibility
return_best_model_fit = TRUE,
return_model_selection_df = TRUE,
plot_map = FALSE)
# Load directly output
data(Ponerinae_cat_3lvl_data_old_calib, package = "deepSTRAPP")
## Set focal time to 10 Mya
focal_time <- 10
# (May take several minutes to run)
## Run deepSTRAPP on net diversification rates for focal time = 10 Mya.
Ponerinae_deepSTRAPP_cat_3lvl_old_calib_10My <- run_deepSTRAPP_for_focal_time(
densityMaps = Ponerinae_cat_3lvl_data_old_calib$densityMaps,
ace = Ponerinae_cat_3lvl_data_old_calib$ace,
tip_data = Ponerinae_cat_3lvl_tip_data,
trait_data_type = "categorical",
BAMM_object = Ponerinae_BAMM_object_old_calib,
focal_time = focal_time,
rate_type = "net_diversification",
posthoc_pairwise_tests = TRUE,
return_perm_data = TRUE,
extract_diversification_data_melted_df = TRUE,
return_updated_trait_data_with_Map = TRUE,
return_updated_BAMM_object = TRUE)
## Explore output
str(Ponerinae_deepSTRAPP_cat_3lvl_old_calib_10My, max.level = 1)
# ------ Plot histogram of STRAPP overall test results ------ #
histogram_ggplot <- plot_histogram_STRAPP_test_for_focal_time(
deepSTRAPP_outputs = Ponerinae_deepSTRAPP_cat_3lvl_old_calib_10My,
display_plot = TRUE,
# PDF_file_path = "./plot_STRAPP_histogram_overall_test.pdf",
plot_posthoc_tests = FALSE)
# Adjust aesthetics a posteriori
histogram_ggplot_adj <- histogram_ggplot +
ggplot2::theme(plot.title = ggplot2::element_text(color = "red", size = 15))
print(histogram_ggplot_adj)
# ------ Plot histograms of STRAPP post hoc test results ------ #
histograms_ggplot_list <- plot_histogram_STRAPP_test_for_focal_time(
deepSTRAPP_outputs = Ponerinae_deepSTRAPP_cat_3lvl_old_calib_10My,
display_plot = TRUE,
# PDF_file_path = "./plot_STRAPP_histograms_posthoc_tests.pdf",
plot_posthoc_tests = TRUE)
# Plot all histograms one by one
print(histograms_ggplot_list)
# Plot all histograms on one faceted plot
cowplot::plot_grid(plotlist = histograms_ggplot_list)
}
Run the code above in your browser using DataLab