Skip to contents

Convert conflictNet object to igraph object

Usage

prep_for_igraph(netlet, add_nodal_attribs = TRUE, add_dyad_attribs = TRUE)

Arguments

netlet

An R object

add_nodal_attribs

Add any nodal attributes from netlet to igraph object. Default is TRUE.

add_dyad_attribs

Add any dyad attributes from netlet to igraph object. Default is TRUE.

Value

igraph object

Author

Ha Eun Choi, Cassy Dorff, Colin Henry, Shahryar Minhas

Examples


# load data
data(icews)

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

# create netify object
dvars = c( 'matlCoop', 'verbConf', 'matlConf' )
nvars = c( 'i_polity2','i_log_gdp', 'i_log_pop' )
verbCoop_net = netify( 
  icews_10,
  actor1='i', actor2='j', 
  symmetric=FALSE, 
  weight='verbCoop',
  dyad_vars = dvars,
  dyad_vars_symmetric=rep(FALSE, length(dvars)),
  nodal_vars = nvars )

# convert to igraph object
igrph <- prep_for_igraph(verbCoop_net)
igrph
#> IGRAPH a517d07 DNW- 152 9976 -- 
#> + attr: name (v/c), i_polity2 (v/n), i_log_gdp (v/n), i_log_pop (v/n),
#> | weight (e/n), verbCoop (e/n), matlCoop (e/n), verbConf (e/n),
#> | matlConf (e/n)
#> + edges from a517d07 (vertex names):
#>  [1] Afghanistan->Argentina  Afghanistan->Armenia    Afghanistan->Australia 
#>  [4] Afghanistan->Austria    Afghanistan->Azerbaijan Afghanistan->Bahrain   
#>  [7] Afghanistan->Bangladesh Afghanistan->Belgium    Afghanistan->Brazil    
#> [10] Afghanistan->Bulgaria   Afghanistan->Canada     Afghanistan->China     
#> [13] Afghanistan->Colombia   Afghanistan->Croatia    Afghanistan->Cuba      
#> [16] Afghanistan->Denmark    Afghanistan->Egypt      Afghanistan->Estonia   
#> + ... omitted several edges

# longitudinal case
verbCoop_longit_net = netify(
  icews,
  actor1='i', actor2='j', time='year',
  symmetric=FALSE, 
  weight='verbCoop',
  dyad_vars = dvars,
  dyad_vars_symmetric=rep(FALSE, length(dvars)),
  nodal_vars = nvars )

# convert to igraph object
igrph_longit <- prep_for_igraph(verbCoop_longit_net)

# output in the longitudinal case is 
# a list of igraph objects
class(igrph_longit)
#> [1] "list"
names(igrph_longit)
#>  [1] "2002" "2003" "2004" "2005" "2006" "2007" "2008" "2009" "2010" "2011"
#> [11] "2012" "2013" "2014"
igrph_longit[['2002']]
#> IGRAPH 68215c1 DNW- 152 8692 -- 
#> + attr: name (v/c), i_polity2 (v/n), i_log_gdp (v/n), i_log_pop (v/n),
#> | weight (e/n), verbCoop (e/n), matlCoop (e/n), verbConf (e/n),
#> | matlConf (e/n)
#> + edges from 68215c1 (vertex names):
#>  [1] Afghanistan->Albania    Afghanistan->Armenia    Afghanistan->Australia 
#>  [4] Afghanistan->Austria    Afghanistan->Azerbaijan Afghanistan->Bahrain   
#>  [7] Afghanistan->Bangladesh Afghanistan->Belgium    Afghanistan->Brazil    
#> [10] Afghanistan->Bulgaria   Afghanistan->Cambodia   Afghanistan->Canada    
#> [13] Afghanistan->Chile      Afghanistan->China      Afghanistan->Cuba      
#> [16] Afghanistan->Denmark    Afghanistan->Egypt      Afghanistan->Estonia   
#> + ... omitted several edges