ivy.chars.bayesian_models module¶
-
ivy.chars.bayesian_models.
create_mk_model
(tree, chars, Qtype, pi)[source]¶ Create model objects to be passed to pymc.MCMC
Creates Qparams and likelihood function
-
ivy.chars.bayesian_models.
create_multi_mk_model
(tree, chars, Qtype, pi, nregime=2)[source]¶ Create an mk model with multiple regimes to be sampled from with MCMC.
Regime number is fixed and the location of the regime shift is allowed to change
-
ivy.chars.bayesian_models.
fit_mk_bayes
(tree, chars, Qtype, pi, *kwargs)[source]¶ Fit an mk model to a given tree and list of characters. Return posterior distributions of Q parameters and MAP estimate of Q matrix
Parameters: - tree (Node) – Root node of a tree. All branch lengths must be greater than 0 (except root)
- chars (list) – List of character states corresponding to leaf nodes in preoder sequence. Character states must be in the form of 0,1,2,...
- pi (str) – Either “Equal”, “Equilibrium”, or “Fitzjohn”. How to weight values at root node. Defaults to “Equal” Method “Fitzjohn” is not thouroughly tested, use with caution
- Qtype –
Either a string specifying how to esimate values for Q or a numpy array of a pre-specified Q matrix.
Valid strings for Q:
“Equal”: All rates equal “Sym”: Forward and reverse rates equal “ARD”: All rates different
Keyword Arguments: - iters (float) – Number of iterations in MCMC. Defaults to 2000
- burn (float) – Burnin to discard. Defaults to 200
- thin (float) – Thinning parameter. Defaults to 1
Returns: The pymc MCMC object and the pymc MAP object
Return type:
-
ivy.chars.bayesian_models.
get_indices
(list_of_lists)[source]¶ Get indices given list of nodes in regimes
-
ivy.chars.bayesian_models.
hrm_bayesian
(tree, chars, Qtype, nregime, pi=u'Fitzjohn', constraint=u'Rate')[source]¶ Create a hidden rates model for pymc to be sampled from.
Parameters: - tree (Node) – Root node of a tree. All branch lengths must be greater than 0 (except root)
- chars (dict) –
Dict mapping character states to tip labels. Character states should be coded 0,1,2...
Can also be a list with tip states in preorder sequence
- pi (str) – Either “Equal”, “Equilibrium”, or “Fitzjohn”. How to weight values at root node. Defaults to “Equal” Method “Fitzjohn” is not thouroughly tested, use with caution
- Qtype –
Either a string specifying how to esimate values for Q or a numpy array of a pre-specified Q matrix.
- “Simple”: Symmetric rates within observed states and between
- rates.
- “STD”: State Transitions Different. Transitions between states
- within the same rate class are asymetrical
- nregime (int) – Number of hidden states. nstates = 0 is equivalent to a vanilla Mk model
- constraint (str) –
Contraints to apply to the parameters of the Q matrix. Can be one of the following:
- “Rate”: The fastest rate in the fastest regime must be faster than
- the fastest rate in the slowest regime
- “Symmetry”: For two-regime models only. The two regimes must
- have different symmetry (a>b in regime 1, b>a in regime 2)
“None”: No contraints
-
ivy.chars.bayesian_models.
mk_results
(mcmc_obj)[source]¶ Create summary graphs and statistics for an mk model
Parameters: mcmc_obj – A pymc MCMC object that has been sampled Returns: Trace plots, histograms, and summary statistics Return type: dict