Skip to contents

This function takes in a dyadic dataset and outputs a list of adjacency matrices in which the actor composition in the network can vary over time.

Usage

get_adjacency_list(
  dyad_data,
  actor1 = NULL,
  actor2 = NULL,
  time = NULL,
  symmetric = TRUE,
  mode = "unipartite",
  weight = NULL,
  sum_dyads = FALSE,
  actor_time_uniform = FALSE,
  actor_pds = NULL,
  diag_to_NA = TRUE,
  missing_to_zero = TRUE
)

Arguments

dyad_data

a dyadic dataframe (or a tibble)

actor1

character: name of the actor 1 variable in dyad_data

actor2

character: name of the actor 2 variable in dyad_data

time

character: name of the time variable in dyad_data, the values of the time variable itself should be numeric

symmetric

logical: whether ties are symmetric, default is TRUE

mode

character: whether the network is unipartite or bipartite, default is unipartite

weight

character: name of the weighted edges variable, default is NULL

sum_dyads

logical: whether to sum up the weight value when there exists repeating dyads within time periods

actor_time_uniform

logical: whether to assume actors are the same across the full time series observed in the data TRUE means that actors are the same across the full time series observed in the data FALSE means that actors come in and out of the observed data and their "existence" should be determined by the data, meaning that their first year of existence will be determined by the time point of their first event and their last year of existence by the time point of their last event

actor_pds

a data.frame indicating start and end time point for every actor, this can be created manually (see example) or using get_actor_time_info.R, if provided then choice of actor_time_uniform is irrelevant.

diag_to_NA

logical: whether diagonals should be set to NA, default is TRUE

missing_to_zero

logical: whether missing values should be set to zero, default is TRUE

Value

a list of adjacency matrices of class netify

Author

Cassy Dorff, Ha Eun Choi, Shahryar Minhas

Examples



# load example directed event data from ICEWS
# this data comes in the form of a dyadic
# dataframe where all dyad pairs are listed
data(icews)

# generate a longitudinal, directed, and weighted network
# where the weights are verbConf
# note that in longitudinal networks we can have all the 
# same actors in every year and if that's the case
# we set actor_time_uniform to TRUE, in the next
# example we'll show how to adjust when actors
# change over time
icews_verbConf <- get_adjacency_list(
  dyad_data=icews, 
  actor1='i', actor2='j', time='year',
  actor_time_uniform=TRUE,
  symmetric=FALSE, weight='verbConf' )
icews_verbConf
#>  Hello, you have created network data, yay!
#> • Unipartite
#> • Asymmetric
#> • Weights from `verbConf`
#> • Longitudinal: 13 Periods
#> • # Unique Actors: 152
#> Network Summary Statistics (averaged across time):
#>           dens miss mean recip trans
#> verbConf 0.111    0  1.5 0.831 0.374
#> • Nodal Features: None
#> • Dyad Features: None

# another example using cow data
# gathered from the peacesciencer package
library(peacesciencer)
library(dplyr)

# create dyadic data set over time (NGOs)
cow_dyads <- create_dyadyears( 
    subset_years = c(1980:2001)
    ) %>%
    # add mids
    add_cow_mids()
#> Joining with `by = join_by(ccode1, ccode2, year)`
#> Joining with `by = join_by(ccode1, ccode2, year)`
#> add_cow_mids() IMPORTANT MESSAGE: By default, this function whittles dispute-year data into dyad-year data by first selecting on unique onsets. Thereafter, where duplicates remain, it whittles dispute-year data into dyad-year data in the following order: 1) retaining highest `fatality`, 2) retaining highest `hostlev`, 3) retaining highest estimated `mindur`, 4) retaining highest estimated `maxdur`, 5) retaining reciprocated over non-reciprocated observations, 6) retaining the observation with the lowest start month, and, where duplicates still remained (and they don't), 7) forcibly dropping all duplicates for observations that are otherwise very similar.
#> See: http://svmiller.com/peacesciencer/articles/coerce-dispute-year-dyad-year.html

# now lets create a network object in which
# we generate list of networks in which the
# cross-sections represent mid onset
# additionally note that the raw data involves
# country years in which we saw countries go in
# and out of existence so we set actor_time_uniform
# to FALSE
mid_network <- netify(
  cow_dyads,
  actor1='ccode1', actor2='ccode2', time='year',
  weight='cowmidonset', 
  actor_time_uniform=FALSE,
  sum_dyads=FALSE, symmetric=TRUE,
  diag_to_NA=TRUE, missing_to_zero=TRUE)
#> ! Warning: Converting `actor1` and/or `actor2` to character vector(s).
mid_network
#>  Hello, you have created network data, yay!
#> • Unipartite
#> • Symmetric
#> • Weights from `cowmidonset`
#> • Longitudinal: 22 Periods
#> • # Unique Actors: 196
#> Network Summary Statistics (averaged across time):
#>              dens miss trans
#> cowmidonset 0.003    0  0.03
#> • Nodal Features: None
#> • Dyad Features: None

# you can also supply your own set of actors
# with custom start and end years using the
# actor_pds argument, to use this first you 
# need to create a data.frame with information
# about actor composition as follows
actor_comp <- data.frame(
    actor = c(2, 365, 220, 710),
    min_time = c(1980, 1980, 1991, 1980),
    max_time = c(2001, 2001, 2001, 2001)
)

# now pass this actor_comp object to the 
# actor_pds argument
mid_network_subset <- netify(
  cow_dyads,
  actor1='ccode1', actor2='ccode2', time='year',
  weight='cowmidonset', 
  actor_pds=actor_comp,
  sum_dyads=FALSE, symmetric=TRUE,
  diag_to_NA=TRUE, missing_to_zero=TRUE)
#> ! Warning: Converting `actor1` and/or `actor2` to character vector(s).
mid_network_subset
#>  Hello, you have created network data, yay!
#> • Unipartite
#> • Symmetric
#> • Weights from `cowmidonset`
#> • Longitudinal: 3 Periods
#> • # Unique Actors: 4
#> Network Summary Statistics (averaged across time):
#>              dens miss trans
#> cowmidonset 0.278    0     0
#> • Nodal Features: None
#> • Dyad Features: None