hierarchical_test: Test on a given tree to achieve aggregation of leaves

View source: R/hierarchical_test.R

hierarchical_testR Documentation

Test on a given tree to achieve aggregation of leaves

Description

This function sequentially tests on a tree in a top-down manner. The testing result determines aggregation of the leaves and makes sure the False Split Rate is controlled under a target level.

Usage

hierarchical_test(tree = NULL, p_vals, alpha, independent = TRUE)

Arguments

tree

An object encoding the tree structure. Can be one of three formats: (1) an hclust object (if tree is binary), (2) a dendrogram, or (3) a generalization of an hclust object to the case of non-binary trees, which we call an hc_list object. An hc_list object is a list of length-num_interior_nodes where the ith item in the list contains the child nodes of the ith node in the tree. The negative values in the list indicate leaf nodes.

p_vals

A length-num_interior_nodes vector of p-values for the interior nodes. The ordering of p-values should correspond to the ordering of nodes in the hclust/hc_list object, i.e., the ith item of the vector is the p-value of the ith node. If a dendrogram is provided that stores the tree structure, the p-values should be ordered reversely as how each node of a dendrogram is reached by a recursive algorithm (See Examples for an example using dendrogram).

alpha

A use-specified target FSR level

independent

Whether the p-values are independent (default = TRUE).

Value

Returns the testing result and calculated threshold values.

alpha

The target FSR level.

rejections

A length-num_interior_nodes vector indicating whether each node is rejected.

threshold_functions

A length-(nnodes-nleaves) vector of computed threshold value at each node. NA if not tested.

groups

A length-n-feature vector of integers indicating the cluster to which each leaf is allocated.

Examples

set.seed(123)
## Example 1: Test with an hclust object
hc = hclust(dist((1:10) + runif(10)/10), method = "complete")
p_vals = c(runif(5), rbeta(4, 1, 60))
hierarchical_test(tree = hc, p_vals = p_vals, alpha = 0.3, independent = TRUE)
## Example 2: Test with a dendrogram object
dend = as.dendrogram(hc)
p_vals = c(runif(4), rbeta(1, 1, 60), runif(1), rbeta(3, 1, 60))
hierarchical_test(tree = dend, p_vals = p_vals, alpha = 0.3, independent = TRUE)
## Example 3: Test with a hc_list object
hc_list = dend_as_hclist(dend)
p_vals = c(runif(4), rbeta(1, 1, 60), runif(1), rbeta(3, 1, 60))
hierarchical_test(tree = hc_list, p_vals = p_vals, alpha = 0.3, independent = TRUE)

simone0628/hat documentation built on June 1, 2024, 9 a.m.