apply.reconstruction: Apply reconstruction

View source: R/apply.reconstruction.R

apply.reconstructionR Documentation

Apply reconstruction

Description

Apply a series of passes for an ancestral states reconstruction

Usage

apply.reconstruction(
  tree,
  character,
  passes = 4,
  method = "NA",
  inapplicable = 1,
  match.tip.char = FALSE
)

Arguments

tree

phylo, a tree

character

character, a vector of character states

passes

numeric, the number of passes in the tree; from 1 to 4 (default)

method

either "Fitch" or "NA"

inapplicable

When method is "Fitch", how do deal with inapplicable data: 1, 2 for respectively treating them as ? or an extra state.

match.tip.char

logical, TRUE to match the character to the tip labels (e.g character 1 matches with tip "a" or "1") or FALSE (default) to match the character to the tips entry (e.g. character 1 matches with the first tip)

Value

A states.matrix object that is a list of:

$Char

a list of character (numeric) where "NA" is equal to -1

$Dp1

a list of character from the first downpass

$Up1

a list of character from the first uppass

$Dp2

a list of character from the second downpass

$Up2

a list of character from the second uppass

$tracker

a list of the same Dp1, Up1, Dp2 and Up2 elements but tracking the applicable regions

$region

a vector of numeric value indicating the number of additional applicable regions

$changes

a vector of numeric values indicating the nodes where a state change was recorded

$score

a single numeric value that is the score of the tree (X$score = length(X$region) + length(X$changes))

$tree

the tree (phylo)

Author(s)

Thomas Guillerme

See Also

plot.states.matrix, runInapp

Examples

set.seed(1)
## Random tree with 12 taxa
tree <- ape::rtree(12, br = NULL)
## A character with inapplicable data
character <- "23--1??--032"

## Normal Fitch algorithm (NA states are missing data)
apply.reconstruction(tree, character, passes = 2, method = "Fitch",
                     inapplicable = 1)
## Same but NA states are an extra state and character now match the tips
apply.reconstruction(tree, character, passes = 2, method = "Fitch",
                     inapplicable = 2, match.tip.char = TRUE)

## NA algorithm
apply.reconstruction(tree, character, passes = 4, method = "NA")

## 1st pass of the NA algorithm
apply.reconstruction(tree, character, passes = 1, method = "NA")


TGuillerme/Inapp documentation built on Feb. 4, 2024, 7:26 a.m.