SelectFeaturesRW: SelectFeaturesRW

View source: R/SelectFeaturesRW.R

SelectFeaturesRWR Documentation

SelectFeaturesRW

Description

Finds the important variables presenting a coordinated response across all specified replicate-blocks for a given ComDim component.

Usage

SelectFeaturesRW(
  RW = RW,
  results = results,
  ndim = NULL,
  blocks = NULL,
  threshold_cor = 1,
  threshold_cov = 1,
  mean.RW = TRUE,
  plots = "NO"
)

Arguments

RW

The object used as input in the ComDim analysis.

results

The output object obtained in the ComDim analysis.

ndim

The number of the component for which the important variables are to be identified.

blocks

A vector with the indices or the names for the replicate blocks of the same data type.

threshold_cor

The "times" parameter used to calculate the threshold in the following formula: cor(variable) > times * sd(cor(variables)). Minimal value that can be assigned to threshold_cor is 1.

threshold_cov

The "times" parameter used to calculate the threshold in the following formula: cov(variable) > times * sd(cov(variables)). Minimal value that can be assigned to threshold_cov is 1.

mean.RW

Logical value to indicate whether the RW data must be mean-centered (TRUE) or not (FALSE).

plots

Parameter to indicate whether S-plots (covariance vs. correlation with the Q scores) must be produced. Possible values are "NO" for no plots, "separated" for displaying one S-plot per block individually (pausing between plots), and "together" to arrange all S-plots side by side in a single grid. In all plot variants, variables selected as important are highlighted in red and labelled with their variable name. Requires the ggplot2 package; "together" additionally requires gridExtra.

Details

The function applies an S-plot approach to identify variables that are both strongly covarying and strongly correlated with the Q scores of the chosen component. For each block in blocks, covariance (s1) and correlation (s2) of every variable with the (pseudo-inverse-scaled) Q scores are computed. A variable is considered important in a block if its absolute covariance exceeds threshold_cov * sd(s1) and its absolute correlation exceeds threshold_cor * sd(s2). Only variables that satisfy both criteria in all specified blocks simultaneously are returned. The sign of the local P-loadings is used to separate variables into positive and negative groups.

Value

A named list with two elements:

$positive

Integer indices (named by variable name) of the important variables presenting a positive relationship with the Q scores (positive covariance, positive correlation, and positive local P-loading) across all specified blocks.

$negative

Integer indices (named by variable name) of the important variables presenting a negative relationship with the Q scores (negative covariance, negative correlation, and negative local P-loading) across all specified blocks.

When plots is not "NO", S-plots are also displayed as a side effect: each plot shows covariance on the x-axis and correlation on the y-axis, with selected variables highlighted in red.

See Also

SplitRW, ComDim_PCA

Examples


b1 <- matrix(rnorm(500), 10, 50)
batch_b1 <- rep(1, 10)
b2 <- matrix(rnorm(800), 30, 80)
batch_b2 <- c(rep(1, 10), rep(2, 10), rep(3, 10))
mb <- MultiBlock(
  Data = list(b1 = b1, b2 = b2),
  Batch = list(b1 = batch_b1, b2 = batch_b2),
  ignore.names = TRUE, ignore.size = TRUE
)
rw <- SplitRW(mb)
results <- ComDim_PCA(rw, 2)
# Identify important variables for component 1 across replicate blocks 2, 3, and 4
features <- SelectFeaturesRW(RW = rw, results = results, ndim = 1, blocks = c(2, 3, 4))
# Use stricter thresholds and display S-plots side by side
features <- SelectFeaturesRW(RW = rw, results = results, ndim = 1, blocks = c(2, 3, 4),
                             threshold_cor = 2, threshold_cov = 2, plots = "together")


R.ComDim documentation built on May 13, 2026, 9:07 a.m.