groupToSinglePolarityPairs: Sub-group allowing only single positive/polarity pairs per...

View source: R/group_features.R

groupToSinglePolarityPairsR Documentation

Sub-group allowing only single positive/polarity pairs per group


Based on a grouping f and the polarity of each element polarity, the function ensures each feature group to consist of only a single positive/negative feature pair. Thus, each of the groups in f is further sub-grouped into positive/negative feature pairs with the highest correlation of feature values across samples. In the returned grouping no group will have more than one feature of the same polarity.

This function can be helpful for merging feature grouping results from positive and negative polarity.


groupToSinglePolarityPairs(f, polarity = rep(1, length(f)), fvals)



vector defining the initial grouping of elements (e.g. such as returned by groupByCorrelation.


vector (same length than f) with the polarity for each element (feature).


numeric matrix (number of rows matching length(f)) with feature values across e.g. samples. Correlations will be calculated between rows of this matrix.


factor with the grouping, ensuring that each group consists of only a single positive/negative pair.


Johannes Rainer

See Also

Other grouping operations: groupByCorrelation()


## Define a simple matrix where the first 4 and the last 3 rows are highly
## correlated with each other.
x <- rbind(
    c(4, 3, 5, 1),
    c(4, 2, 5, 1),
    c(4, 3, 4, 1),
    c(4, 3, 4, 1),
    c(4, 4, 4, 9),
    c(4, 4, 4, 9),
    c(4, 4, 4, 9))

## Determin the expected grouping by correlation
grp <- groupByCorrelation(x)

## Each second row represents however a feature measured in a different
## polarity. From another grouping (e.g. based on EIC correlation) we know
## however that none of the positive polarity features should be
## grouped together. We apply now the function to further subgroup `grp`
## keeping only single positive/negative pairs in each group of `grp`.
pol <- c("NEG", "POS", "NEG", "POS", "NEG", "POS", "NEG")

groupToSinglePolarityPairs(grp, pol, x)

EuracBiomedicalResearch/CompMetaboTools documentation built on May 5, 2022, 6:43 a.m.