norm.network {CDatanet} R Documentation

## Creating objects for network models

### Description

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.

### Usage

norm.network(W)

vec.to.mat(u, N, normalise = FALSE, byrow = FALSE)

mat.to.vec(W, ceiled = FALSE, byrow = FALSE)


### Arguments

 W matrix or list of matrices to convert. u numeric vector to convert. N vector of sub-network sizes such that length(u) == sum(N*(N - 1)). normalise Boolean takes TRUE if the returned matrices should be row-normalized and FALSE otherwise. byrow Boolean takes TRUE is entries in the matrices should be taken by row and FALSE if they should be taken by column. ceiled Boolean takes TRUE if the given matrices should be ceiled before conversion and FALSE otherwise.

### Value

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.

### Examples

# 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)


[Package CDatanet version 2.2.0 Index]