norm.network | R Documentation |
The vec.to.mat
function creates a list of square matrices from a given vector.
Elements of the generated matrices are taken from the vector and placed column-wise or row-wise, progressing from the first matrix in the list to the last.
The diagonals of the generated matrices are set to zeros.
The mat.to.vec
function creates a vector from a given list of square matrices.
Elements of the generated vector are taken column-wise or row-wise, starting from the first matrix in the list to the last, excluding diagonal entries.
The norm.network
function row-normalizes matrices in a given list.
norm.network(W)
vec.to.mat(u, N, normalise = FALSE, byrow = FALSE)
mat.to.vec(W, ceiled = FALSE, byrow = FALSE)
W |
A matrix or list of matrices to convert. |
u |
A numeric vector to convert. |
N |
A vector of sub-network sizes such that |
normalise |
A boolean indicating whether the returned matrices should be row-normalized ( |
byrow |
A boolean indicating whether entries in the matrices should be taken by row ( |
ceiled |
A boolean indicating whether the given matrices should be ceiled before conversion ( |
A vector of size sum(N * (N - 1))
or a list of length(N)
square matrices, with matrix sizes determined by N[1], N[2], ...
.
simnetwork
, peer.avg
.
# Generate a list of adjacency matrices
## Sub-network sizes
N <- c(250, 370, 120)
## Rate of friendship
p <- c(0.2, 0.15, 0.18)
## Network data
u <- unlist(lapply(1:3, function(x) rbinom(N[x] * (N[x] - 1), 1, p[x])))
W <- vec.to.mat(u, N)
# Convert W into a list of row-normalized matrices
G <- norm.network(W)
# Recover u
v <- mat.to.vec(G, ceiled = TRUE)
all.equal(u, v)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.