# NOT RUN {
# For a perfect binary tree of depth 2 below
#
# 3
# /\
# 1 2
# /\ /\
# -1 -2 -3 -4
#
# A can expressed as the following:
A_true <- cbind(diag(4),
as.matrix(c(1, 1, 0, 0)),
as.matrix(c(0, 0, 1, 1)),
as.matrix(c(1, 1, 1, 1)))
# Now use tree.matrix to generate A
tree0 <- list()
tree0$merge <- matrix(c(-1, -2, -3, -4, 1, 2),
ncol = 2, byrow = TRUE)
tree0$labels <- c("leaf1", "leaf2", "leaf3", "leaf4")
A <- tree.matrix(tree0)
all(A_true == as.matrix(A))
# Another example
hc <- hclust(dist(USArrests), "ave")
A <- tree.matrix(hc)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab