hsp_subtree_averaging {castor} | R Documentation |

Reconstruct ancestral states of a continuous (numeric) trait for nodes and predict unknown (hidden) states for tips on a tree using subtree averaging.

hsp_subtree_averaging(tree, tip_states, 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` |
A numeric vector of size Ntips, specifying the state of each tip in the tree. |

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

Any `NA`

entries in `tip_states`

are interpreted as unknown (hidden) states to be estimated. For each node the reconstructed state is set to the arithmetic average state of all tips with known state and descending from that node. For each tip with hidden state and each node whose descending tips all have hidden states, the state is set to the state of the closest ancestral node with known or reconstructed state, while traversing from root to tips (Zaneveld and Thurber 2014). Note that reconstructed node states are only local estimates, i.e. for each node the estimate is only based on the tip states in the subtree descending from that node.

Tips must be represented in `tip_states`

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

. The vector `tip_states`

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

). This function has asymptotic time complexity O(Nedges).

This function is meant for reconstructing ancestral states in all nodes of a tree as well as predicting the states of tips with an a priory unknown state. If the state of all tips is known and only ancestral state reconstruction is needed, consider using the function `asr_subtree_averaging`

for improved efficiency.

A list with the following elements:

`success` |
Logical, indicating whether HSP was successful. |

`states` |
A numeric vector of size Ntips+Nnodes, listing the reconstructed state of each tip and node. The entries in this vector will be in the order in which tips and nodes are indexed in |

Stilianos Louca

J. R. Zaneveld and R. L. V. Thurber (2014). Hidden state prediction: A modification of classic ancestral state reconstruction algorithms helps unravel complex symbioses. Frontiers in Microbiology. 5:431.

`asr_subtree_averaging`

,
`hsp_squared_change_parsimony`

# generate random tree Ntips = 100 tree = generate_random_tree(list(birth_rate_intercept=1),max_tips=Ntips)$tree # simulate a continuous trait tip_states = simulate_ou_model(tree, stationary_mean=0, spread=1, decay_rate=0.001)$tip_states # print tip states print(as.vector(tip_states)) # set half of the tips to unknown state tip_states[sample.int(Ntips,size=as.integer(Ntips/2),replace=FALSE)] = NA # reconstruct all tip states via subtree averaging estimated_states = hsp_subtree_averaging(tree, tip_states)$states # print estimated tip states print(estimated_states[1:Ntips])

[Package *castor* version 1.6.8 Index]