Skip to contents

add_nodal takes in a dataframe and outputs a netify object.

Usage

add_nodal(
  netlet,
  node_data,
  actor = NULL,
  time = NULL,
  node_vars = NULL,
  replace_existing = FALSE
)

Arguments

netlet

a netify object

node_data

a dataframe object

actor

a character object indicating which variable in node_data uniquely IDs each node

time

a character object indicating which variable in node_data tracks time

node_vars

a vector of which variables from node_data should be merged

replace_existing

a logical indicating whether to replace existing nodal data

Value

a netify object

Author

Colin Henry, Shahryar Minhas

Examples


data(icews)

# cross-sectional case
icews_10 <- icews[icews$year==2010,]


verbCoop_net <- netify(
  dyad_data=icews_10,
  actor1 = 'i', actor2 = 'j', 
  symmetric=FALSE, weight='verbCoop' )

# nodal data should be a dataframe with one row per actor
# in the cross-sectional case and one row per actor per 
# time period in the longitudinal case, e.g.:
nvars = c(
  'i_polity2',
  'i_gdp', 'i_log_gdp',
  'i_pop', 'i_log_pop' )
nodeData <- unique(icews_10[,c('i', nvars)])
head(nodeData)
#>                 i i_polity2        i_gdp i_log_gdp    i_pop i_log_pop
#> 10    Afghanistan        NA  16047892927  23.49884 28189672  17.15447
#> 2250      Albania         9  10420206418  23.06701  2913021  14.88470
#> 4490      Algeria         2 140977153156  25.67186 35856344  17.39503
#> 6730       Angola        -2  69938841426  24.97089 23364185  16.96671
#> 8970    Argentina         8 552738161802  27.03815 40788453  17.52391
#> 11210     Armenia         5   8513508876  22.86492  2946293  14.89606

verbCoop_net <- add_nodal( 
  netlet=verbCoop_net, node_data=nodeData, 
  actor='i', node_vars=nvars )

# nodal data is stored in the nodal_data attribute
# as a data.frame, it can be accessed in the following way:
node_data <- attr(verbCoop_net, 'nodal_data')
head(node_data)
#>         actor i_polity2        i_gdp i_log_gdp    i_pop i_log_pop
#> 1 Afghanistan        NA  16047892927  23.49884 28189672  17.15447
#> 2     Albania         9  10420206418  23.06701  2913021  14.88470
#> 3     Algeria         2 140977153156  25.67186 35856344  17.39503
#> 4      Angola        -2  69938841426  24.97089 23364185  16.96671
#> 5   Argentina         8 552738161802  27.03815 40788453  17.52391
#> 6     Armenia         5   8513508876  22.86492  2946293  14.89606

# longitudinal case
verbCoop_longit_net <- netify(
    dyad_data=icews, 
    actor1='i', actor2='j', time='year',
    symmetric=FALSE,
    weight='verbCoop' )

nodeData <- unique(icews[,c('i', 'year', nvars)])

verbCoop_longit_net <- add_nodal(
  netlet=verbCoop_longit_net,
  node_data=nodeData, 
  actor='i', time='year',
  node_vars = nvars )

# and in the longitudinal case, it can be accessed
# in the same way
node_data <- attr(verbCoop_longit_net, 'nodal_data')
head(node_data)
#>         actor time i_polity2       i_gdp i_log_gdp    i_pop i_log_pop
#> 1 Afghanistan 2002        NA  7555185296  22.74550 21000256  16.86005
#> 2 Afghanistan 2003        NA  8222480251  22.83014 22645130  16.93546
#> 3 Afghanistan 2004        NA  8338755823  22.84418 23553551  16.97479
#> 4 Afghanistan 2005        NA  9275174321  22.95061 24411191  17.01055
#> 5 Afghanistan 2006        NA  9772082812  23.00280 25442944  17.05195
#> 6 Afghanistan 2007        NA 11123202208  23.13230 25903301  17.06988