tpr: Calculate true positive rate (TPR) on a tree structure

Description Usage Arguments Value Author(s) Examples

Description

tpr calculates the true positive rate (TPR) on a tree structure at leaf or node level.

Usage

1
tpr(tree, truth, found, only.Tip = TRUE, direction = FALSE)

Arguments

tree

A phylo object

truth

Nodes that have signals (eg. differentally abundant at different experimental conditions.). If the signals are in different directions (up and down), then provide the nodes as a list of two members (one up and one down). One could provide either node number or node label. Note: When TPR at node level is required and only leaf nodes with signal are provided, then the internal nodes which are shared and only shared by the provied leaf nodes (signal in the same direction) will be found out and used with the leaf nodes in the TPR calculation; when TPR at leaf level is required and the given nodes have internal nodes, then the descendant leaf nodes will be found out and used in the TPR calculation.

found

Nodes that have been found to have signal (eg. differentally abundant at different experimental conditions). If the signals are in different directions (up and down), then provide the nodes as a list of two members (one up and one down). One could provide either node number or node label. Note: When TPR at node level is required, then the descendant nodes of the provied nodes (include themselves) will be found out and used in the TPR calculation; when TPR at leaf level is required, then the descendant leaf nodes will be found out and used in the TPR calculation.

only.Tip

A logical value, TRUE or FALSE. If TRUE, true positive rate is calculated at the leaf (tip) level; otherwise it is calculated at node level. The default is TRUE

direction

TRUE or FALSE. Default is FALSE. If TRUE, the signal direction is taken into account; the argument truth and found should both be a list of two members and the order of directions should match.

Value

A true positive rate

Author(s)

Ruizhu Huang

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
library(ggtree)
data("tinyTree")
ggtree(tinyTree) + geom_text2(aes(label = node))

# Truth: two branches have differential
# abundance under different conditions.
# branch with node 16 (direction: increase)
# branch with node 13 (direction: decrease)

# ------------ ignore direction -------------------
# Found: branches with node 17 and node 14
 # TPR at the tip level
tpr1 <- tpr(tree = tinyTree, truth = c(16, 13),
            found = c(17, 14), only.Tip = TRUE)
 # TPR at the node level
tpr2 <- tpr(tree = tinyTree, truth = c(16, 13),
            found = c(17, 14), only.Tip = FALSE)


# ------------ direction matters-------------------
# Found: branches with node 17 (up) and node 14 (down)

 # the order of direction for truth and found should be the same
(tpr3 <- tpr(tree = tinyTree, truth = list(16, 13),
            found = list(16, 13), only.Tip = TRUE,
            direction = TRUE))  # correct order

(tpr4 <- tpr(tree = tinyTree, truth = list(16, 13),
            found = list(13, 16), only.Tip = FALSE,
            direction = TRUE)) # wrong order

markrobinsonuzh/treeAGG documentation built on May 26, 2019, 9:32 a.m.