Sort contrasts by factor and level, given contrast names, or
SEDesign, or data.frame of factors.
Arguments
- x
one of:
charactervector of contrast namesSEDesigndata.framewith factors
- factor_order
integer, default NULL uses all factors, or specify the factor ordering to use for sorting.- ...
additional arguments are passed to internal functions. For example 'factor_names' is passed to
contrasts_to_factors().
Value
data.frame with factors in each column, and
factor levels or factor level contrasts as column values.
The rownames() contain contrast names.
Sort order
Contrasts are sorted by depth: one-factor comparisons, two-factor comparisons, etc.
Contrasts are sorted for factor level contrasts in each factor in
factor_order. Iffactor_order=1then contrasts appear first in the first factor column.Contrasts are then sorted by that factor column using the observed contrast order.
Contrasts are then sorted by other factor columns as they appear in
factor_order, using the observed level order in each factor column.
Sort order, described another way:
All one-way contrasts will appear at the top.
The first one-way contrasts will be comparisons using the first value in
factor_order, sorted by the comparison, then sorted by each remaining column infactor_order.The next set of one-way contrasts will be the second value in
factor_order, sorted by that comparison, then sorted by each remaining column infactor_order.
All two-way contrasts will appear at the end, since each two-way contrast involves two factors.
They will be sorted to involve contrasts in the same order as as
factor_order.The first two-way contrasts will involve comparisons involving the first two values in
factor_order.
See also
Other jam experiment design:
SEDesign(),
[,SEDesign-method,
check_sedesign(),
contrast2comp(),
contrast_colors_by_group(),
contrast_names_to_sedesign(),
contrastnames(),
contrasts(),
contrasts<-(),
contrasts_to_factors(),
contrasts_to_venn_setlists(),
design,SEDesign-method,
draw_oneway_contrast(),
draw_twoway_contrast(),
factors(),
filter_contrast_names(),
groups(),
groups_to_sedesign(),
plot.SEDesign(),
plot_sedesign(),
print,SEDesign-method,
samples(),
sedesign_to_factors(),
validate_sedesign()
Examples
isamples_1 <- paste0(
rep(c("DMSO", "Etop", "DMSO", "Etop"), each=6),
"_",
rep(c("NF", "Flag"), each=12),
"_",
rep(c("WT", "KO", "WT", "KO", "WT", "D955N", "WT", "D955N"), each=3),
"_",
LETTERS[1:3])
# simple data.frame with group information
idf <- data.frame(jamba::rbindList(strsplit(isamples_1, "_")))[,1:3]
rownames(idf) <- isamples_1;
colnames(idf) <- c("Treatment", "Flag", "Genotype")
# convert to sedesign
sedesign <- groups_to_sedesign(idf)
sort_contrasts(sedesign)
#> Treatment Flag
#> Etop_NF_WT-DMSO_NF_WT Etop-DMSO NF
#> Etop_NF_KO-DMSO_NF_KO Etop-DMSO NF
#> Etop_Flag_WT-DMSO_Flag_WT Etop-DMSO Flag
#> Etop_Flag_D955N-DMSO_Flag_D955N Etop-DMSO Flag
#> DMSO_Flag_WT-DMSO_NF_WT DMSO Flag-NF
#> Etop_Flag_WT-Etop_NF_WT Etop Flag-NF
#> DMSO_NF_KO-DMSO_NF_WT DMSO NF
#> Etop_NF_KO-Etop_NF_WT Etop NF
#> DMSO_Flag_D955N-DMSO_Flag_WT DMSO Flag
#> Etop_Flag_D955N-Etop_Flag_WT Etop Flag
#> (Etop_Flag_WT-DMSO_Flag_WT)-(Etop_NF_WT-DMSO_NF_WT) Etop-DMSO Flag-NF
#> (Etop_NF_KO-DMSO_NF_KO)-(Etop_NF_WT-DMSO_NF_WT) Etop-DMSO NF
#> (Etop_Flag_D955N-DMSO_Flag_D955N)-(Etop_Flag_WT-DMSO_Flag_WT) Etop-DMSO Flag
#> Genotype
#> Etop_NF_WT-DMSO_NF_WT WT
#> Etop_NF_KO-DMSO_NF_KO KO
#> Etop_Flag_WT-DMSO_Flag_WT WT
#> Etop_Flag_D955N-DMSO_Flag_D955N D955N
#> DMSO_Flag_WT-DMSO_NF_WT WT
#> Etop_Flag_WT-Etop_NF_WT WT
#> DMSO_NF_KO-DMSO_NF_WT KO-WT
#> Etop_NF_KO-Etop_NF_WT KO-WT
#> DMSO_Flag_D955N-DMSO_Flag_WT D955N-WT
#> Etop_Flag_D955N-Etop_Flag_WT D955N-WT
#> (Etop_Flag_WT-DMSO_Flag_WT)-(Etop_NF_WT-DMSO_NF_WT) WT
#> (Etop_NF_KO-DMSO_NF_KO)-(Etop_NF_WT-DMSO_NF_WT) KO-WT
#> (Etop_Flag_D955N-DMSO_Flag_D955N)-(Etop_Flag_WT-DMSO_Flag_WT) D955N-WT