model_adequacy_hbds {castor} | R Documentation |
Check if a birth-death-sampling model adequately explains a timetree.
Description
Given a rooted timetree and a homogenous birth-death-sampling model (e.g., as used in molecular epidemiology), check if the model adequately explains various aspects of the tree, such as the branch length and node age distributions and other test statistics. The function uses bootstrapping to simulate multiple hypothetical trees according to the model and then compares the distribution of those trees to the original tree. This function may be used to quantify the "goodness of fit" of a birth-death-sampling model to a timetree. For background on the HBDS model see the documentation for generate_tree_hbds
.
Usage
model_adequacy_hbds(tree,
models,
splines_degree = 1,
extrapolate = FALSE,
Nbootstraps = 1000,
max_sim_attempts = 1000,
Nthreads = 1,
max_extant_tips = NULL,
max_model_runtime = NULL)
Arguments
tree |
A rooted timetree of class "phylo". |
models |
Either a single HBDS model or a list of HBDS models, specifying the pool of models from which to randomly draw bootstraps. Every model should itself be a named list with some or all of the following elements:
If you are assessing the adequacy of a single model with specific parameters, then |
splines_degree |
Integer, one of 0, 1, 2 or 3, specifying the polynomial degree of the model parameters |
extrapolate |
Logical, specifying whether to extrapolate the model variables |
Nbootstraps |
Integer, the number of bootstraps (simulations) to perform for calculating statistical significances. A larger number will increase the accuracy of estimated statistical significances. |
max_sim_attempts |
Integer, maximum number of simulation attempts per bootstrap, before giving up. Multiple attempts may be needed if the HBDS model has a high probability of leading to extinction early on. |
Nthreads |
Integer, number of parallel threads to use for bootstrapping. Note that on Windows machines this option is ignored. |
max_extant_tips |
Integer, optional maximum number of extant tips per simulation. A simulation is aborted (and that bootstrap iteration skipped) if the number of extant tips exceeds this threshold. Use this to avoid occasional explosions of runtimes, for example due to very large generated trees. |
max_model_runtime |
Numeric, optional maximum computation time (in seconds) to allow for each HBDS model simulation (per bootstrap). Use this to avoid occasional explosions of runtimes, for example due to very large generated trees. Aborted simulations will be omitted from the bootstrap statistics. If |
Details
In addition to model selection, the adequacy of any chosen model should also be assessed in absolute terms, i.e. not just relative to other competing models (after all, all considered models might be bad). This function essentially determines how probable it is for hypothetical trees generated by a candidate model (or a distribution of candidate models) to resemble the tree at hand, in terms of various test statistics. In particular, the function uses a Kolmogorov-Smirnov test to check whether the probability distributions of edge lengths and node ages in the tree resemble those expected under the provided models. All statistical significances are calculated using bootstrapping, i.e. by simulating trees from the provided models. For every bootstrap, a model is randomly chosen from the provided models
list.
Note that even if an HBDS model appears to adequately explain a given timetree, this does not mean that the model even approximately resembles the true diversification history (i.e., the true speciation, extinction and sampling rates) that generated the tree (Louca and Pennell 2020). Hence, it is generally more appropriate to say that a given model "congruence class" rather than a specific model explains the tree.
Note that here "age" refers to time before present, i.e. age increases from tips to roots and the youngest tip in the input tree has age 0. In some situations the process that generated the tree (or which is being compared to the tree) might have halted after the last tip was sampled, in which case end_age
should be negative. Similarly, the process may have started prior to the tree's root (e.g., sampled tips coalesce at a later time than when the monitoring started), in which case stem_age
should be greater than the root's age.
For convenience, it is possible to specify a model without providing an explicit age grid (i.e., omitting ages
); in such a model \lambda
, \mu
, \psi
and \kappa
are assumed to be time-independent, and hence lambda
, mu
, psi
and kappa
must be provided as single numerics (or not provided at all).
Value
A named list with the following elements:
success |
Logical, indicating whether the model evaluation was successful. If |
Nbootstraps |
Integer, the number of bootstraps used. |
tree_Ntips |
Integer, the number of tips in the original tree. |
bootstrap_mean_Ntips |
Numeric, mean number of tips in the bootstrap trees. |
PNtips |
Numeric, two-sided statistical significance of the tree's number of tips under the provided null model, i.e. the probability that |
tree_Colless |
Numeric, Colless imbalance statistic (Shao and Sokal, 1990) of the original tree. |
bootstrap_mean_Colless |
Numeric, mean Colless statistic across all bootstrap trees. |
PColless |
Numeric, two-sided statistical significance of the tree's Colless statistic under the provided null model, i.e. the probability that |
tree_Sackin |
Numeric, Sackin statistic (Sackin, 1972) of the original tree. |
bootstrap_mean_Sackin |
Numeric, median Sackin statistic across all bootstrap trees. |
PSackin |
Numeric, two-sided statistical significance of the tree's Sackin statistic under the provided null model, i.e. the probability that |
tree_edgeKS |
Numeric, Kolmogorov-Smirnov (KS) statistic of the original tree's edge lengths, i.e. the estimated maximum difference between the tree's and the model's (estimated) cumulative distribution function of edge lengths. |
bootstrap_mean_edgeKS |
Numeric, mean KS statistic of the bootstrap trees' edge lengths. |
PedgeKS |
Numeric, the one-sided statistical significance of the tree's edge-length KS statistic, i.e. the probability that the KS statistic of any tree generated by the model would be larger than the original tree's KS statistic. A low value means that the probability distribution of edge lengths in the original tree differs strongly from that expected based on the model. |
tree_tipKS |
Numeric, Kolmogorov-Smirnov (KS) statistic of the original tree's tip ages (sampling times before present), i.e. the estimated maximum difference between the tree's and the model's (estimated) cumulative distribution function of tip ages. |
bootstrap_mean_tipKS |
Numeric, mean KS statistic of the bootstrap trees' tip ages. |
PtipKS |
Numeric, the one-sided statistical significance of the tree's tip-age KS statistic, i.e. the probability that the KS statistic of any tree generated by the model would be larger than the original tree's KS statistic. A low value means that the probability distribution of tip ages in the original tree differs strongly from that expected based on the model. |
tree_nodeKS |
Numeric, Kolmogorov-Smirnov (KS) statistic of the original tree's node ages (divergence times before present), i.e. the estimated maximum difference between the tree's and the model's (estimated) cumulative distribution function of node ages. |
bootstrap_mean_nodeKS |
Numeric, mean KS statistic of the bootstrap trees' node ages. |
PnodeKS |
Numeric, the one-sided statistical significance of the tree's node-age KS statistic, i.e. the probability that the KS statistic of any tree generated by the model would be larger than the original tree's KS statistic. A low value means that the probability distribution of node ages in the original tree differs strongly from that expected based on the model. |
statistical_tests |
Data frame, listing the above statistical test results in a more compact format (one test statistic per row). |
LTT_ages |
Numeric vector, listing ages (time before present) on which the tree's LTT will be defined. |
tree_LTT |
Numeric vector of the same length as |
bootstrap_LTT_CI |
Named list containing the elements |
fraction_LTT_in_CI95 |
Numeric, fraction of the tree's LTT contained within the equal-tailed 95%-confidence interval of the distribution of LTT values predicted by the model. For example, a value of 0.5 means that at half of the time points between the present-day and the root, the tree's LTT is contained with the 95%-CI of predicted LTTs. |
Author(s)
Stilianos Louca
References
S. Louca and M. W. Pennell (2020). Extant timetrees are consistent with a myriad of diversification histories. Nature. 580:502-505.
O. G. Pybus and P. H. Harvey (2000). Testing macro-evolutionary models using incomplete molecular phylogenies. Proceedings of the Royal Society of London. Series B: Biological Sciences. 267:2267-2272.
M. J. Sackin (1972). "Good" and "Bad" Phenograms. Systematic Biology. 21:225-226.
K.T. Shao, R. R. Sokal (1990). Tree Balance. Systematic Biology. 39:266-276.
See Also
simulate_deterministic_hbds
,
generate_tree_hbds
,
model_adequacy_hbd
Examples
## Not run:
# generate a tree based on a simple HBDS process
max_time = 10
gen = castor::generate_tree_hbds(max_time = max_time,
lambda = 1,
mu = 0.1,
psi = 0.1,
no_full_extinction = TRUE)
if(!gen$success) stop(sprintf("Could not generate tree: %s",gen$error))
tree = gen$tree
root_age = castor::get_tree_span(tree)$max_distance
# determine age of the stem, i.e. when the HBDS process started
stem_age = gen$root_time + root_age
# determine age at which the HBDS simulation was halted.
# This might be slightly negative, e.g. if the process
# halted after the last sampled tip
end_age = root_age - (gen$final_time-gen$root_time)
# compare the tree to a slightly different model
model = list(stem_age = stem_age,
end_age = end_age,
lambda = 1.2,
mu = 0.1,
psi = 0.2)
adequacy = model_adequacy_hbds( tree,
models = model,
Nbootstraps = 100)
if(!adequacy$success){
cat(sprintf("Adequacy test failed: %s\n",adequacy$error))
}else{
print(adequacy$statistical_tests)
}
## End(Not run)