View source: R/wrangle-weights.R
| normalize_weights | R Documentation |
Rescales the weight matrix. Row normalization is what turns a transition count matrix into the transition probabilities that TNA models use.
normalize_weights(
x,
method = c("row", "column", "max", "sum", "minmax"),
keep_format = FALSE,
directed = NULL
)
x |
Network input. |
method |
How to rescale:
|
keep_format |
Logical. Return the input format when TRUE. |
directed |
Logical or NULL. If NULL (default), auto-detect. |
A row (or column, or the whole matrix) whose total is zero is left at zero
rather than producing NaN: there is nothing to distribute. Rows with
a zero total are reported in a cograph_zero_norm warning so that the
zeros are a stated result rather than a silent one.
"minmax" maps the weakest edge to .Machine$double.eps rather
than to exactly 0, because 0 is how this representation stores "no edge":
mapping to it would delete the weakest edge instead of rescaling it.
"max", "sum" and "minmax" rescale each edge
independently and therefore keep any extra edge columns. "row" and
"column" scale an edge by a total that differs at its two endpoints,
so they break symmetry and return a directed network.
Row and column normalization are meaningful on directed networks. On an undirected network they still work but break symmetry, so the result is returned as directed.
A cograph_network with rescaled weights, or the input format
when keep_format = TRUE.
binarize, invert_weights,
symmetrize
counts <- matrix(c(0, 3, 1,
2, 0, 4,
5, 1, 0), 3, 3, byrow = TRUE)
rownames(counts) <- colnames(counts) <- c("A", "B", "C")
normalize_weights(counts, method = "row")
normalize_weights(counts, method = "max")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.