| extract_most_likely_ranges_from_densityMaps_for_focal_time | R Documentation |
Extracts the most likely ranges found along branches
at a specific time in the past (i.e. the focal_time).
Optionally, the function can update the mapped phylogeny (densityMaps)
such as branches overlapping the focal_time are shorten to the focal_time,
and the range mapping for the cut off branches are removed
by updating the $tree$maps and $tree$mapped.edge elements.
extract_most_likely_ranges_from_densityMaps_for_focal_time(
densityMaps,
ace = NULL,
tip_data = NULL,
focal_time,
update_densityMaps = FALSE,
keep_tip_labels = TRUE
)
densityMaps |
List of objects of class |
ace |
(Optional) Numerical matrix that record the posterior probabilities of ancestral ranges at internal nodes,
obtained with |
tip_data |
(Optional) Named character string vector of tip ranges. Names are nodes_ID of the internal nodes. Needed to provide accurate tip values. |
focal_time |
Integer. The time, in terms of time distance from the present, at which the tree and mapping must be cut. It must be smaller than the root age of the phylogeny. |
update_densityMaps |
Logical. Specify whether the mapped phylogeny ( |
keep_tip_labels |
Logical. Specify whether terminal branches with a single descendant tip
must retained their initial |
The mapped phylogeny (densityMaps) is cut at a specific time in the past
(i.e. the focal_time) and the current trait values of the overlapping edges/branches are extracted.
—– Extract trait_data —–
Most likely ranges are extracted from the posterior probabilities displayed in the densityMaps.
The range with the highest probability is assigned to each tip and cut branches at focal_time.
True ML estimates will be used if tip_data and/or ace are provided as optional inputs.
In practice the discrepancy is negligible.
—– Update the densityMaps —–
To obtain updated densityMaps alongside the trait data, set update_densityMaps = TRUE.
The update consists in cutting off branches and mapping that are younger than the focal_time.
When a branch with a single descendant tip is cut and keep_tip_labels = TRUE,
the leaf left is labeled with the tip.label of the unique descendant tip.
When a branch with a single descendant tip is cut and keep_tip_labels = FALSE,
the leaf left is labeled with the node ID of the unique descendant tip.
In all cases, when a branch with multiple descendant tips (i.e., a clade) is cut, the leaf left is labeled with the node ID of the MRCA of the cut-off clade.
The ancestral range mapping in densityMap ($tree$maps and $tree$mapped.edge) is updated accordingly by removing mapping associated with the cut off branches.
By default, the function returns a list with three elements.
$trait_data A named character string vector with ML ranges found along branches overlapping the focal_time. Names are the tip.label/tipward node ID.
$focal_time Integer. The time, in terms of time distance from the present, at which the trait data were extracted.
$trait_data_type Character string. Define the type of trait data as "biogeographic". Used in downstream analyses to select appropriate statistical processing.
If update_densityMaps = TRUE, the output is a list with four elements: $trait_data, $focal_time, $trait_data_type, and $densityMaps.
$densityMaps A list of objects of class "densityMap" that contains the updated densityMap of each range/range,
with branches and mapping that are younger than the focal_time cut off.
The function also adds multiple useful sub-elements to the $densityMaps$tree elements.
$root_age Integer. Stores the age of the root of the tree.
$nodes_ID_df Data.frame with two columns. Provides the conversion from the new_node_ID to the initial_node_ID. Each row is a node.
$initial_nodes_ID Vector of character strings. Provides the initial ID of internal nodes. Used to plot internal node IDs as labels with ape::nodelabels().
$edges_ID_df Data.frame with two columns. Provides the conversion from the new_edge_ID to the initial_edge_ID. Each row is an edge/branch.
$initial_edges_ID Vector of character strings. Provides the initial ID of edges/branches. Used to plot edge/branch IDs as labels with ape::edgelabels().
Maël Doré
cut_phylo_for_focal_time() cut_densityMaps_for_focal_time()
Associated main function: extract_most_likely_trait_values_for_focal_time()
Sub-functions for other types of trait data:
extract_most_likely_trait_values_from_contMap_for_focal_time()
extract_most_likely_states_from_densityMaps_for_focal_time()
## Load biogeographic range data mapped on a phylogeny
data(eel_biogeo_data, package = "deepSTRAPP")
# Explore data
str(eel_biogeo_data, 1)
eel_biogeo_data$densityMaps # Two density maps: one per unique area: A, B.
eel_biogeo_data$densityMaps_all_ranges # Three density maps: one per range: A, B, and AB.
# Set focal time to 10 Mya
focal_time <- 10
# ----- Example 1: Using only unique areas ----- #
# (May take several minutes to run)
## Extract trait data and update densityMaps for the given focal_time
# Extract from the densityMaps
eel_biogeo_data_10My <- extract_most_likely_ranges_from_densityMaps_for_focal_time(
densityMaps = eel_biogeo_data$densityMaps,
# ace = eel_biogeo_data$ace,
focal_time = focal_time,
update_densityMaps = TRUE)
## Print trait data
str(eel_biogeo_data_10My, 1)
eel_biogeo_data_10My$trait_data
## Plot density maps as overlay of all range posterior probabilities
# Plot initial density maps with ACE pies
plot_densityMaps_overlay(densityMaps = eel_biogeo_data$densityMaps, fsize = 0.7)
abline(v = max(phytools::nodeHeights(eel_biogeo_data$densityMaps[[1]]$tree)[,2]) - focal_time,
col = "red", lty = 2, lwd = 2)
# Plot updated densityMaps with ACE pies
plot_densityMaps_overlay(eel_biogeo_data_10My$densityMaps, fsize = 0.7)
# ----- Example 2: Using all ranges ----- #
# (May take several minutes to run)
## Extract trait data and update densityMaps_all_ranges for the given focal_time
# Extract from the densityMaps
eel_biogeo_data_10My <- extract_most_likely_ranges_from_densityMaps_for_focal_time(
densityMaps = eel_biogeo_data$densityMaps_all_ranges,
# ace = eel_biogeo_data$ace_all_ranges,
focal_time = focal_time,
update_densityMaps = TRUE)
## Print trait data
str(eel_biogeo_data_10My, 1)
eel_biogeo_data_10My$trait_data
## Plot density maps as overlay of all range posterior probabilities
# Plot initial density maps with ACE pies
root_age <- max(phytools::nodeHeights(eel_biogeo_data$densityMaps_all_ranges[[1]]$tree)[,2])
plot_densityMaps_overlay(densityMaps = eel_biogeo_data$densityMaps_all_ranges, fsize = 0.7)
abline(v = root_age - focal_time,
col = "red", lty = 2, lwd = 2)
# Plot updated densityMaps with ACE pies
plot_densityMaps_overlay(eel_biogeo_data_10My$densityMaps, fsize = 0.7)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.