norm.network | R Documentation |
vec.to.mat
creates a list of square matrices from a given vector.
The elements of the generated matrices are taken from the vector and placed column-wise (ie. the first column is filled up before filling the second column) and from the first matrix of the list to the last matrix of the list.
The diagonal of the generated matrices are zeros.
mat.to.vec
creates a vector from a given list of square matrices .
The elements of the generated vector are taken from column-wise and from the first matrix of the list to the last matrix of the list, while dropping the diagonal entry.
norm.network
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 |
matrix or list of matrices to convert. |
u |
numeric vector to convert. |
N |
vector of sub-network sizes such that |
normalise |
Boolean takes |
byrow |
Boolean takes |
ceiled |
Boolean takes |
a vector of size sum(N*(N - 1))
or list of length(N)
square matrices. The sizes of the matrices are N[1], N[2], ...
simnetwork
, peer.avg
.
# Generate a list of adjacency matrices
## sub-network size
N <- c(250, 370, 120)
## rate of friendship
p <- c(.2, .15, .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 G 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.