Create network object from data.frame
netify.Rd
This function takes in a dyadic dataset and outputs a netlet object.
Usage
netify(
dyad_data,
actor1 = NULL,
actor2 = NULL,
time = NULL,
symmetric = TRUE,
mode = "unipartite",
weight = NULL,
sum_dyads = FALSE,
actor_time_uniform = TRUE,
actor_pds = NULL,
diag_to_NA = TRUE,
missing_to_zero = TRUE,
output_format = ifelse(is.null(time), "cross_sec", "longit_list"),
nodal_vars = NULL,
dyad_vars = NULL,
dyad_vars_symmetric = rep(symmetric, length(dyad_vars))
)
Arguments
- dyad_data
data object to netify
- actor1
character: name of the actor 1 variable in the data
- actor2
character: name of the actor 2 variable in the data
- time
character: name of the time variable in the data, if no time is provided then it will be assumed
- 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 edge variable in the data, default is NULL
- sum_dyads
logical: whether to sum up the
weight
value when there exists repeating dyads- 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 and the outputted netify object will be in an array format. 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. Outputted netify object will be in a list format.
- actor_pds
a data.frame indicating start and end time point for every actor, this can be created using
get_actor_time_info.R
, unless provided this will estimated for the user based on their choice ofactor_time_uniform
- 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
- output_format
character: "cross_sec", "longit_array", or "longit_list. If not specified and time is NULL then output_format will be "cross_sec" and if time is specified then output_format will default to "longit_list".
- nodal_vars
character vector: names of the nodal variables in the dyad_data object that should be added as attributes to the netify object
- dyad_vars
character vector: names of the dyadic variables in the dyad_data object that should be added as attributes to the netify object, default is to add all the variables from the extra_dyadic_data data.frame
- dyad_vars_symmetric
logical vector: whether ties are symmetric, default is to use the same choice as the symmetric argument
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 longitudional, directed and weighted network
# where the weights are matlConf and results are organized
# in an array
icews_matlConf <- netify(
dyad_data=icews,
actor1='i', actor2='j', time='year',
symmetric=FALSE, weight='matlConf')
# generate a longitudional, directed and weighted network
# where the weights are matlConf and results are organized
# in an array and we have both dyadic and nodal attributes
icews_matlConf <- netify(
dyad_data=icews,
actor1='i', actor2='j', time='year',
symmetric=FALSE, weight='matlConf',
nodal_vars=c('i_polity2', 'i_log_gdp', 'i_log_pop'),
dyad_vars=c('matlCoop', 'verbCoop', 'verbConf'),
dyad_vars_symmetric=c(FALSE, FALSE, FALSE) )
# example using cow data
# gathered from the peacesciencer package
library(peacesciencer)
library(dplyr)
# create dyadic data set over time
cow_dyads <- create_dyadyears(
subset_years = c(1992:2001)
) %>%
# add mids
add_cow_mids() %>%
# add capital distance
add_capital_distance() %>%
# add cow trade
add_cow_trade() %>%
# add democracy
add_democracy()
#> 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
#> Joining with `by = join_by(ccode1, ccode2, year)`
# 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',
# network of interest variable
weight='cowmidonset',
actor_time_uniform=FALSE,
sum_dyads=FALSE, symmetric=TRUE,
diag_to_NA=TRUE, missing_to_zero=FALSE,
# nodal features/covariates
nodal_vars = c('v2x_polyarchy1', 'v2x_polyarchy2'),
# dyadic features/covariates
dyad_vars = c('capdist', 'flow1'),
dyad_vars_symmetric = c(TRUE, FALSE)
)
#> ! 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: 10 Periods
#> • # Unique Actors: 192
#> Network Summary Statistics (averaged across time):
#> dens miss trans
#> cowmidonset 0.003 0 0.05
#> • Nodal Features: v2x_polyarchy1, v2x_polyarchy2
#> • Dyad Features: capdist, flow1