Learn R Programming

dendextend (version 1.18.1)

sample.dendrogram: Sample a tree

Description

Samples a tree, either by permuting the labels (which is usefull for a permutation test), or by repeated sampling of the same labels (essential for bootstraping when we don't have access to the original data which produced the tree).

Duplicates a leaf in a tree. Useful for non-parametric bootstraping trees since it emulates what would have happened if the tree was constructed based on a row-sample with replacments from the original data matrix.

Usage

sample.dendrogram(
  dend,
  replace = FALSE,
  dend_labels,
  sampled_labels,
  fix_members = TRUE,
  fix_order = TRUE,
  fix_midpoint = TRUE,
  ...
)

Value

A dendrogram, after "sampling" its leaves.

Arguments

dend

a dendrogram object

replace

logical (FALSE). Should we shuffle the labels (if FALSE), or should we replicate the same leaf over and over, while omitting other leaves? (this is when set to TRUE).

dend_labels

a character vector of the tree's labels. This can save the time it takes for getting the tree labels (in case we run a simulating, computing this once might save some running time). If missing, it uses labels in order to get the labels.

sampled_labels

a character vector of the tree's sampled labels. This can help us if we wish to compare two trees. In such a case we'd like to be able to have the same sample of labels used on both trees. If missing, it uses sample in order to get the sampled labels.

Only works when replace=TRUE!

fix_members

logical (TRUE). Fix the number of members in attr using fix_members_attr.dendrogram

fix_order

logical (TRUE). Fix the leaves order

fix_midpoint

logical (TRUE). Fix the midpoint value. If TRUE, it overrides "fix_members" and turns it into TRUE (since it must have a correct number of members in order to work). values using rank_order.dendrogram

...

not used

See Also

sample, duplicate_leaf

Examples

Run this code

if (FALSE) {
# define dendrogram object to play with:
dend <- USArrests[1:5, ] %>%
  dist() %>%
  hclust(method = "ave") %>%
  as.dendrogram()
plot(dend)

# # same tree, with different order of labels
plot(sample.dendrogram(dend, replace = FALSE))

# # A different tree (!), with some labels duplicated,
# while others are pruned
plot(sample.dendrogram(dend, replace = TRUE))
}

Run the code above in your browser using DataLab