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

Description

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.

Usage

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

Arguments

f

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

polarity

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

fvals

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

Value

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

Author(s)

Johannes Rainer

See Also

Other grouping operations: groupByCorrelation()

Examples


## 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)
grp

## 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 Jan. 31, 2024, 1:14 p.m.