asr_empirical_probabilities {castor} | R Documentation |

Given a rooted phylogenetic tree and the states of a discrete trait for each tip, calculate the empirical state frequencies/probabilities for each node in the tree, i.e. the frequencies/probabilities of states across all tips descending from that node. This may be used as a very crude estimate of ancestral state probabilities.

asr_empirical_probabilities(tree, tip_states, Nstates=NULL, probabilities=TRUE, check_input=TRUE)

`tree` |
A rooted tree of class "phylo". The root is assumed to be the unique node with no incoming edge. |

`tip_states` |
An integer vector of size Ntips, specifying the state of each tip in the tree as an integer from 1 to Nstates, where Nstates is the possible number of states (see below). |

`Nstates` |
Either |

`probabilities` |
Logical, specifying whether empirical frequencies should be normalized to represent probabilities. If |

`check_input` |
Logical, specifying whether to perform some basic checks on the validity of the input data. If you are certain that your input data are valid, you can set this to |

For this function, the trait's states must be represented by integers within 1,..,Nstates, where Nstates is the total number of possible states. If the states are originally in some other format (e.g., characters or factors), you should map them to a set of integers 1,..,Nstates. You can easily map any set of discrete states to integers using the function `map_to_state_space`

.

The tree may include multi-furcations (i.e. nodes with more than 2 children) as well as mono-furcations (i.e. nodes with only one child). The function has asymptotic time complexity O(Nedges x Nstates).

Tips must be represented in `tip_states`

in the same order as in `tree$tip.label`

. The vector `tip_states`

need not include names; if it does, however, they are checked for consistency (if `check_input==TRUE`

).

A list with the following elements:

`ancestral_likelihoods` |
A 2D integer (if |

Stilianos Louca

`asr_max_parsimony`

,
`asr_squared_change_parsimony`

`asr_mk_model`

,
`map_to_state_space`

## Not run: # generate a random tree Ntips = 100 tree = generate_random_tree(list(birth_rate_intercept=1),max_tips=Ntips)$tree # create a random transition matrix Nstates = 3 Q = get_random_mk_transition_matrix(Nstates, rate_model="ER", max_rate=0.01) cat(sprintf("Simulated ER transition rate=%g\n",Q[1,2])) # simulate the trait's evolution simulation = simulate_mk_model(tree, Q) tip_states = simulation$tip_states # calculate empirical probabilities of tip states asr_empirical_probabilities(tree, tip_states=tip_states, Nstates=Nstates) ## End(Not run)

[Package *castor* version 1.7.0 Index]