R/bMat.R

Defines functions bMat

Documented in bMat

#' Full interaction matrix
#'
#' \code{bMat} returns the matrix of all the interactions between k basic factors
#'
#' @param k An integer. Number of basic factors.
#' @return A k by \eqn{2^{k}-1} binary matrix of all interactions between basic factors.
#' @export
bMat <- function(k) {
  # Check the value of k
  if (k < 2) {
    stop("Minimum 2 basic factors (k) are needed")
  }
  # Build the matrix
  int_vec <- c(1:(2^k - 1))
  full_int_mat <- sapply(int_vec, function(x) {
    as.integer(intToBits(x))[1:k]
  })
  colnames(full_int_mat) <- int_vec
  rownames(full_int_mat) <- letters[1:k]
  return(full_int_mat)
}
ABohynDOE/mldoeR documentation built on Dec. 17, 2021, 6:40 a.m.