remove_correlated: Remove highly correlated columns

Description Usage Arguments Details Value Examples

View source: R/remove-correlated.R

Description

remove_correlated removes one of column-pairs from sparse and dense matrices that have sample correlation value greater than a user-defined threshold.

Usage

1
2
3
4
5
6
7
remove_correlated(x, threshold)

## S3 method for class 'CsparseMatrix'
remove_correlated(x, threshold = 0.99)

## S3 method for class 'matrix'
remove_correlated(x, threshold = 0.99)

Arguments

x

A matrix or CsparseMatrix.

threshold

A double between 0 and 1 specifying the absolute correlation threshold value at which to remove columns.

Details

remove_correlated() is an S3 generic with methods for:

Value

x with one of highly correlated column-pairs removed.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Create a sparse matrix with very sparse columns
x <- Matrix::rsparsematrix(10, 5, 0.5)
x <- cbind(x, x[, 4:5], x[, 4:5])
# Create two perfectly correlated columns
colnames(x) <- paste0("x", 1:9)
# Print x
x

# Same matrix in dense format
xdense <- as.matrix(x)

# Drop highly correlated columns
remove_correlated(x, threshold = 0.99)
remove_correlated(xdense, threshold = 0.99)

dmolitor/sparseprepr documentation built on Jan. 7, 2022, 9:58 p.m.