full_mm: Create a 3-dimensional mixingm matrix

Description Usage Arguments Value Examples

View source: R/full_mm.R

Description

Given contact layer of the mixing matrix compute a full 3-dimensional mixing matrix by rebuilding the non-contact layer from supplied group sizes and other arguments.

Usage

1
full_mm(cl, gsizes, directed = TRUE, loops = FALSE)

Arguments

cl

numeric matrix with contact layer of the mixing matrix

gsizes

numeric vector or matrix with group sizes, see Details.

directed

logical, whether the network is directed

loops

logical, whether loops (self-ties) are allowed

Contact layer of the mixing matrix is a cross-classification of ties according to the attributes of tie sender (ego) and tie receiver (alter). Classically, the same attribute is used for ego and alter resulting in a square mixing matrix. In such cases cl shoud be square with cl[i,j] being the number of ties from actors in group i to actors in group j and gsizes should be a numeric vector with number of nodes in each group. Consequently, it must hold that length(gsizes) == nrow(cl) == ncol(cl).

In more general case we can use different node attributes for ego and alter. Then cl does not have to be square. In such cases gsizes should be a cross-tabulation of nodes according to their values on both attributes. See Examples.

Value

full_mm returns a full three-dimenstional mixing matrix as an array with dim attribute equal to c( nrow(cl), ncol(cl), 2 ).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
### Square example

# Contact layer of the mixing matrix
mm1 <- matrix( c( 20, 10, 5,
                 12, 30, 10,
                 3, 11, 25 ),
              byrow=TRUE, ncol=3, nrow=3)
dimnames(mm1) <- list(ego=letters[1:3], alter=letters[1:3])
mm1

# Assuming some group sizes
gs1 <- c(a=9, b=12, c=10)

# Full mixing matrix
full_mm( mm1, gs1)




### Non-square example

# Mixing matrix
# Now using different attributes for ego and alter
mm2 <- cbind(mm1, c(20, 10, 5))
colnames(mm2) <- LETTERS[1:4]
names(dimnames(mm2)) <- c("ego", "alter")
mm2

# Create artificial distribution of attributes
set.seed(123)
a1 <- sample(letters[1:3], sum(gs1), replace=TRUE, prob=gs1/sum(gs1))
table(a1)
a2 <- sample(LETTERS[1:4], sum(gs1), replace=TRUE)
table(a2)
(x <- table(a1, a2))         # Cross-tablulation

# Full mixing matrix
full_mm( mm2, gsizes=x)

mbojan/isnar documentation built on Feb. 18, 2021, 4:38 a.m.