stack_contrasts: Stack a vector of contrasts into a full string

stack_contrastsR Documentation

Stack a vector of contrasts into a full string

Description

Stack a vector of contrasts into a full string

Usage

stack_contrasts(imgroups, contrast_delim = "-", ...)

Arguments

imgroups

character vector of group names.

contrast_delim

character string used as a delimiter between group names to indicate a statistical contrast.

...

additional arguments are ignored.

Details

This is an internal function called by contrast2comp() and comp2contrast(). It takes a single vector of groups, with 2^(integer) number of entries, and combines them into a series of pairwise contrasts.

For example:

  • ⁠A, B⁠ becomes A-B

  • ⁠A, B, C, D⁠ becomes (A-B)-(C-D)

  • ⁠A, B, C, D, E, F, G, H⁠ becomes ((A-B)-(C-D))-((E-F)-(G-H))

Value

character vector with fully written contrasts.

Examples

stack_contrasts(head(LETTERS, 2))
stack_contrasts(head(LETTERS, 4))
stack_contrasts(head(LETTERS, 8))
contrast2comp(stack_contrasts(head(LETTERS, 16)))

# more typical case
stacked <- stack_contrasts(c("KO_Treated", "KO_Control",
   "WT_Treated", "WT_Control"))
stacked

# this contrast can be rewritten as a "comp"
stacked_comp <- contrast2comp(stacked)
stacked_comp

# of course the "comp" can be converted back to full contrast name
comp2contrast(stacked_comp)

# note when the contrast cannot be stacked, an error is thrown
tryCatch({
   stack_contrasts(head(LETTERS, 5))
}, error=function(e){
   print(e)
})


jmw86069/jamses documentation built on May 31, 2024, 1:36 p.m.