update_affiliation: Update sparse affiliation network with new data

Description Usage Arguments Details Value Examples

View source: R/create_matrices.R

Description

Updates a affiliation network stored in sparse format with new data of an ego-centric network

Usage

1
2
3
4
5
6
7
8
update_affiliation(
  aff_mat,
  x,
  lookup = NULL,
  update_diag = FALSE,
  normalize = FALSE,
  verbose = FALSE
)

Arguments

aff_mat

the affiliation network to be updated; must be a sparseMatrix of the Matrix package

x

a vector containing the (group) names to which the new individual is affiliated to (if lookup is provided); or a vector of class integer that contains the indices of these groups as stored in aff_mat; or a list of these vectors

lookup

optional lookup table. If lookup is provided, it has to be a data.table or data.frame with two columns named index and id, where id contains the (group-level) ids and index the numeric index of the groups (as stored in the affiliation matrix). If x itself contains the indices, lookup is not needed.

update_diag

boolean; if TRUE, updates the diagonals of the affiliation matrix

normalize

boolean; if TRUE the contribution of each ego-network to the affiliation matrix is weighted by the inverse-degree of ego (e.g., if ego has 4 ties, the weight for each tie is 1/4)

verbose

boolean; if TRUE shows progress text

Details

Given the affiliation matrix aff_mat, the function takes new data on a set of affiliations connected to the same unit and updates the affiliations accordingly. If x contains the indices 1,6,12, for example, the affiliation network is updated by adding one count to the entries (1, 6), (6, 1), (1, 12), (12, 1), (6, 12), (12, 6).

Value

updates aff_mat by adding counts to it based on the information provided in x.

Examples

1
2
3
4
5
6
library(Matrix)
k = 5L
aff_mat = Matrix(nrow = k, ncol = k, data = 0L, sparse = TRUE)
x = c(1L, 3L, 5L)

update_affiliation(aff_mat, x)

baruuum/btoolbox documentation built on Aug. 17, 2020, 1:29 a.m.