contrasts_to_venn_setlists: Convert contrast names to Venn setlists for visual comparison

contrasts_to_venn_setlistsR Documentation

Convert contrast names to Venn setlists for visual comparison

Description

Convert contrast names to Venn setlists for visual comparison

Usage

contrasts_to_venn_setlists(
  contrast_names = NULL,
  sestats = NULL,
  sedesign = NULL,
  include_multifactor = TRUE,
  include_singlefactor = TRUE,
  factor_names = NULL,
  contrast_style = c("contrast", "comp", "factors"),
  max_venn_size = 4,
  verbose = FALSE,
  ...
)

Arguments

contrast_names

character vector of contrast names, used as the priority input when supplied.

sestats

list output from se_contrast_stats(), used only when contrast_names is not supplied.

sedesign

SEDesign object, used only when neither contrast_names nor sestats are supplied.

include_multifactor

logical indicating whether to include twoway contrasts in the Venn diagram logic. Currently the logic includes comparisons only across compatible twoway comparisons, it does not (yet) include Venn diagrams that include oneway and corresponding twoway comparisons together. Note: One of include_multifactor and include_singlefactor must be true.

include_singlefactor

logical indicating whether to include single-factor contrasts in the Venn diagram logic. Note: One of include_multifactor and include_singlefactor must be true.

contrast_style

character string indicating how to return the resulting Venn set lists:

  • "contrast" (default) returns a list with contrast names

  • "comp" returns a list with comp names from contrast2comp()

  • "factors" returns a data.frame from contrasts_to_factors() with one column per design factor. In this case it may be useful to pass factor_names in order to assign column names to the factor columns.

max_venn_size

numeric maximum number of groups to include per Venn diagram. When the number of contrasts to be included in a Venn set contains one extra contrast, the last two sets will be adjusted to accomodate the extra set:

  • when max_venn_size=2 the last set will contain 3 members;

  • when max_venn_size=3 (or higher) the last set will contain 2 members, and the previous set will contain (max_venn_size - 1) members.

verbose

logical indicating whether to print verbose output.

...

additional arguments are passed to contrasts_to_factors().

Details

This function is still under active development to be improved, feedback is welcomed.

The motivation is to take a set of contrast names, and return reasonable subsets of contrasts suitable for visual comparison using Venn diagrams. Ultimately, the process is analogous to defining contrasts themselves: keep experimental factors fixed while varying one factor at a time. The difference is that experimental "factors" may themselves involve a comparison.

The process is currently being tested for two-factor design scenarios, and will be extended to handle higher factor designs in future.

The process

  • Contrasts are converted to data.frame with contrasts_to_factors()

  • Each factor column is iterated to produce sets of contrasts as follows:

    • The factor data.frame is subset for rows with a comparison in the factor column.

    • When include_multifactor=FALSE (not default) then data is filtered to remove rows with comparisons in any other factor columns.

    • When include_singlefactor=FALSE (not default) then data is filtered to remove rows with single values in any other factor columns.

    • The remaining rows are iteratively split using values in the other factor columns.

    • Remaining rows are also iteratively split by the depth of the contrast, oneway comparisons, and twoway comparisons.

    • If any subset contains more than max_venn_size rows, it is first split by the control factor level in the factor comparison, then it is split by the depth of the comparison.

    • In all cases, the resulting sets are split into subsets with size max_venn_size.

Value

list with contrast names suitable for use in Venn diagrams.

See Also

Other jam experiment design: check_sedesign(), contrast2comp(), contrast_colors_by_group(), contrast_names_to_sedesign(), contrasts_to_factors(), draw_oneway_contrast(), draw_twoway_contrast(), filter_contrast_names(), groups_to_sedesign(), plot_sedesign(), sedesign_to_factors(), validate_sedesign()

Examples

group_names <- paste0(
   rep(c("UL3", "dH1A", "dH1B"), each=5), "_",
   c("Veh", "DEX", "PMA", "SF", "Ins"))
sedesign <- groups_to_sedesign(group_names)

# by default it returns contrast names
venn_setlists <- contrasts_to_venn_setlists(sedesign=sedesign,
   include_multifactor=FALSE,
   factor_names=c("Genotype", "Treatment"))
jamba::sdim(venn_setlists)

# plot the contrasts included in one particular Venn setlist
par("mfrow"=c(2, 2));
for (n in 1:4) {
setest <- sedesign;
contrast_names(setest) <- venn_setlists[[n]];
plot_sedesign(setest, contrast_style="none")
}
par("mfrow"=c(1, 1))

venn_set_comps <- contrasts_to_venn_setlists(sedesign=sedesign,
   contrast_style="comp",
   factor_names=c("Genotype", "Treatment"))
venn_set_comps
data.frame(names(venn_set_comps))

venn_set_factors <- contrasts_to_venn_setlists(sedesign=sedesign,
   contrast_style="factors",
   factor_names=c("Genotype", "Treatment"))
venn_set_factors
data.frame(names(venn_set_factors))


jmw86069/jamses documentation built on Nov. 4, 2024, 9:25 p.m.