Learn R Programming

zenplots (version 0.0-1)

extreme_pairs: Find So-Many Pairs with Largest/Smallest Values in a Symmetric Matrix

Description

Find those n pairs with the largest/smallest/both values (entries) in a symmetric matrix.

Usage

extreme_pairs(x, n = 6, method = c("largest", "smallest", "both"),
              use.names = FALSE)
extreme_pairs_graph(x, n = 6, method = c("largest", "smallest", "both"),
                    use.names = FALSE)

Arguments

x

symmetric numeric matrix.

n

number of pairs with extreme values in x to be considered.

method

character string indicating the method to be used (with "largest" to comute the n pairs with largest entries in x (sorted in decreasing order); with "smallest" to compute the n pairs with smallest entries in x (sorted in increasing order); and with "both" to comute the 2n pairs with n largest entries and n smallest entries (sorted in decreasing order)).

use.names

logical indicating whether colnames(x) are used as labels (if !is.null(colnames(x))).

Value

extreme_pairs() returns a data.frame consisting of three columns (row (index or name), col (index or name), value).

extreme_pairs_graph() returns a graphNEL object representing the output of extreme_pairs(); this can be plotted.

Examples

Run this code
# NOT RUN {
set.seed(271)
n <- 1000
d <- 10
set.seed(271)
X <- matrix(rnorm(n*d), ncol = d)
P <- cor(X)
colnames(P) <- paste("Var", 1:d)
extreme_pairs(P, n = 5, method = "both")
if(FALSE) {
    require(graph) # requires 'graph' from Bioconductor
    plot(extreme_pairs_graph(P, n = 5))
}
# }

Run the code above in your browser using DataLab