#' Transform factor vector into design matrix
#'
#' Transform factor vector into design matrix, based on code from \code{\link[limma]{removeBatchEffect}}.
#' See examples in vignette.
#'
#' @param batch Vector that is a factor or can be coerced to one.
#' @return Numeric matrix.
batch2design <- function(batch){
stopifnot(length(unique(batch)) > 1)
batch <- as.factor(batch)
stats::contrasts(batch) <- stats::contr.sum(levels(batch))
batch <- stats::model.matrix(~batch)[, -1, drop = FALSE]
return(batch)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.