R: Empirical ancestral state probabilities.

asr_empirical_probabilities {castor} | R Documentation

## Empirical ancestral state probabilities.

### Description

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.

### Usage

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

### Arguments

`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 `NULL`, or an integer specifying the number of possible states of the trait. If `NULL`, then it will be computed based on the maximum value encountered in `tip_states`
`probabilities` | Logical, specifying whether empirical frequencies should be normalized to represent probabilities. If `FALSE`, then the raw occurrence counts are returned.
`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 `FALSE` to reduce computation.

### Details

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`).

### Value

A list with the following elements:

`ancestral_likelihoods` | A 2D integer (if `probabilities==FALSE`) or numeric (if `probabilities==TRUE`) matrix, listing the frequency or probability of each state for each node. This matrix will have size Nnodes x Nstates, where Nstates was either explicitly provided as an argument or inferred from `tip_states`. The rows in this matrix will be in the order in which nodes are indexed in the tree, i.e. the [n,s]-th entry will be the frequency or probability of the s-th state for the n-th node. Note that the name was chosen for compatibility with other ASR functions.

### Author(s)

Stilianos Louca

### See Also

`asr_max_parsimony`, `asr_squared_change_parsimony` `asr_mk_model`, `map_to_state_space`

### Examples

    ## Not run:
    asr_empirical_probabilities(tree, tip_states=c(1,3,2,3), Nstates=3)

    ## End(Not run)

[Package castor version 1.3.4 Index]