Skip to contents

Performs LD pruning using one of two backends. The default "hclust" backend groups the columns as single-linkage hierarchical clustering on the distance (1 - |cor|), cut at 1 - corThres, would, and keeps the first column of each group. Those groups are the connected components of the graph joining columns with |cor| >= corThres, found from the correlations a stripe of rows at a time, so the full correlation matrix is never formed. The "snprelate" backend delegates to SNPRelate::snpgdsLDpruning, which performs a sliding-window greedy prune directly on a temporary GDS file.

Usage

ldPruneByCorrelation(
  X,
  corThres = 0.8,
  backend = c("hclust", "snprelate"),
  verbose = FALSE,
  methodArgs = LdPruningOptions()
)

Arguments

X

Numeric matrix. Columns are the variables to prune (typically SNP genotype dosages); rows are observations.

corThres

Numeric in (0, 1). Absolute correlation threshold. Columns whose pairwise |cor| exceeds this are grouped; one survivor is kept per group. Default 0.8.

backend

Character, one of "hclust" (default) or "snprelate". Controls the pruning algorithm:

"hclust"

Single-linkage groups, found as the connected components of the |cor| >= corThres graph.

"snprelate"

Requires SNPRelate and gdsfmt. Creates a temporary GDS file and runs SNPRelate::snpgdsLDpruning(method = "corr"). GDS stores genotypes as the integer codes 0, 1 and 2, so fractional dosages are refused rather than rounded.

verbose

Logical. If TRUE, print progress messages. Default FALSE.

methodArgs

Extra arguments for SNPRelate::snpgdsLDpruning(), built with LdPruningOptions – the window controls in particular. Only the "snprelate" backend has an engine to configure, so supplying options alongside backend = "hclust" is an error rather than a silent no-op.

Value

A list with:

X.new

Matrix containing the retained columns of X.

filter.id

Integer vector of the column indices of X that were retained (in original order).

Examples

set.seed(1)
X <- matrix(rnorm(100 * 5), 100, 5)
X[, 2] <- X[, 1] + rnorm(100, sd = 0.01)   # near-duplicate of col 1
res <- ldPruneByCorrelation(X, corThres = 0.9)
ncol(res$X.new)
#> [1] 4