#' Transition matrix to binary tree
#'
#' This is adapted from \code{mstate::trans.illness}.
#' Create a complete binary tree transition matrix.
#'
#' @param names Node names
#' @param depth Depth of tree; integer
#'
#' @return Matrix of TRUE and FALSE
#' @export
#'
#' @examples
#'
#' trans_binarytree(c("A", "B"), depth = 2)
#'
trans_binarytree <- function(names,
depth = 2)
{
tmat <- matrix(NA, depth, 2*depth + 1)
for (i in seq_len(depth)) {
tmat[i, (2*i):(2*i + 1)] <- (2*i - 1):(2*i)
}
if (!missing(names))
if (length(names) != depth)
stop("incorrect length of \"names\" argument")
dimnames(tmat) <- list(from = seq_len(depth),
to = seq_len(2*depth + 1))
return(tmat)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.