Converts a dyadic data into a network in various formats
get_adjacency.Rd
get_adjacency
takes in a dyadic dataset and outputs an adjacency matrix representation.
Usage
get_adjacency(
dyad_data,
actor1 = NULL,
actor2 = NULL,
symmetric = TRUE,
mode = "unipartite",
weight = NULL,
sum_dyads = FALSE,
diag_to_NA = TRUE,
missing_to_zero = TRUE
)
Arguments
- dyad_data
a dyadic dataframe (or a tibble)
- actor1
character: name of the actor 1 in dyad_data
- actor2
character: name of the actor 2 in dyad_data
- 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 the dataset- 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
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)
# subset to a particular year
icews <- icews[icews$year=='2010', ]
# generate a cross sectional, directed, and weighted network
# where the weights are verbCoop
icews_verbCoop <- get_adjacency(
dyad_data=icews, actor1='i', actor2='j',
symmetric=FALSE, weight='verbCoop' )
# generate a cross sectional, directed and weighted network
# where the weights are matlConf
icews_matlConf <- get_adjacency(
dyad_data=icews, actor1='i', actor2='j',
symmetric=FALSE, weight='matlConf' )
# another example using cow data
# gathered from the peacesciencer package
library(peacesciencer)
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
# create dyadic data set over time
cow_dyads <- create_dyadyears(
subset_years = c(1992:2014)
) %>%
# 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
# the cross-sections refer to the number of
# conflict onsets between dyads during
# the time period of the data
mid_network <- netify(
cow_dyads,
actor1='ccode1', actor2='ccode2',
weight='cowmidonset',
sum_dyads=TRUE, 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
#> • Sum of Weights from `cowmidonset`
#> • Cross-Sectional
#> • # Unique Actors: 196
#> Network Summary Statistics:
#> dens miss mean trans
#> cowmidonset 0.018 0 0.095 0.139
#> • Nodal Features: None
#> • Dyad Features: None
# now lets say that we just want to
# see whether any conflict onset
# occurred between a dyad during
# this period and generate
# a network object that represents this
# to generate this we need to first subset
# the raw data into an edge list like format
# this only involves subsetting the variable
# that you are using to represent edges to be
# a value above zero
cow_dyad_conflict_onset <- cow_dyads %>%
filter(
cowmidonset > 0
)
# then we use the netify function and
# we no longer supply a weight, since the
# dyads themselves are giving information about
# edges that occurred and in addition we leave
# sum_dyads as FALSE
any_mid_network <- netify(
cow_dyad_conflict_onset,
actor1='ccode1', actor2='ccode2',
sum_dyads=FALSE, symmetric=TRUE,
diag_to_NA=TRUE, missing_to_zero=TRUE)
#> ! Warning: Converting `actor1` and/or `actor2` to character vector(s).
#> ! Warning: there are repeating dyads within time periods in the dataset. When `weight` is not supplied and `sum_dyads` is set to FALSE, edges in the outputted adjacency matrix will represent binary interactions between actors.
mid_network
#> ✔ Hello, you have created network data, yay!
#> • Unipartite
#> • Symmetric
#> • Sum of Weights from `cowmidonset`
#> • Cross-Sectional
#> • # Unique Actors: 196
#> Network Summary Statistics:
#> dens miss mean trans
#> cowmidonset 0.018 0 0.095 0.139
#> • Nodal Features: None
#> • Dyad Features: None