vec.to.mat: Creating objects for network models

Description Usage Arguments See Also Examples

View source: R/convertMV.R

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

1
2
3
4
5
vec.to.mat(u, N, normalise = FALSE)

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

norm.network(W)

Arguments

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.

W

matrix or list of matrixes to convert.

ceiled

boolean takes TRUE if the given matrices should be ceiled before conversion and FALSE otherwise..

See Also

sim.network, sim.dnetwork

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# 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)

ahoundetoungan/PartialNetwork documentation built on March 20, 2021, 3:08 p.m.