Learn R Programming

cograph (version 2.7.2)

invert_weights: Invert Edge Weights (Similarity to Distance and Back)

Description

Turns strong ties into short distances, which is what path-based measures need when the weights are similarities rather than costs.

Usage

invert_weights(
  x,
  method = c("reciprocal", "max_minus", "reflect"),
  keep_format = FALSE,
  directed = NULL
)

Value

A cograph_network with inverted weights, or the input format when keep_format = TRUE.

Arguments

x

Network input.

method

How to invert:

"reciprocal"

(default) 1 / w. The standard similarity-to-distance map; requires non-zero weights, which every stored edge has.

"max_minus"

max(w) - w. The strongest edge becomes zero and is therefore dropped; a cograph_edges_dropped warning says how many.

"reflect"

max(w) + min(w) - w. Reverses the order of the weights while keeping every edge, so no edge is lost.

keep_format

Logical. Return the input format when TRUE.

directed

Logical or NULL. If NULL (default), auto-detect.

See Also

normalize_weights, shortest_paths

Examples

Run this code
adj <- matrix(c(0, .5, .8, 0,
                .5, 0, .3, .6,
                .8, .3, 0, .4,
                 0, .6, .4, 0), 4, 4, byrow = TRUE)
rownames(adj) <- colnames(adj) <- c("A", "B", "C", "D")

invert_weights(adj)
invert_weights(adj, method = "reflect")

Run the code above in your browser using DataLab