These functions offer tools for splitting manynet-consistent objects (matrices, igraph, tidygraph, or network objects) into lists of networks.

  • to_egos() splits a network into ego (or focal) networks.

  • to_subgraphs() splits a network into subgraphs on some given node attribute.

  • to_layers() splits a multiplex network into its layers, i.e. a list of uniplex networks, one per tie type. Use to_uniplex(), or its alias to_layer(), to retain just one of them.

  • to_components() splits a network into its components, ordered from the largest to the smallest. Use to_component() to retain just one of them.

  • to_times() splits a network into the network as it stood at each moment it records, however it records time. This is where new work on splitting a network by time belongs; to_waves() and to_slices() are the older, form-specific spellings.

  • to_waves() splits a panel network into a list of its waves.

  • to_slices() splits a network that increments its ties into the state it had accumulated to at each of the given time slice(s).

to_egos(.data, max_dist = 1, min_dist = 0, direction = c("out", "in"))

to_subgraphs(.data, attribute)

to_layers(.data)

to_components(.data, connectivity = c("weak", "strong"))

to_waves(.data, attribute = "wave", panels = NULL, cumulative = FALSE)

to_times(.data, times = NULL)

to_slices(.data, attribute = "time", slice = NULL)

Arguments

.data

An object of a {manynet}-consistent class:

  • adjacency or incidence matrix from {base} R

  • edgelist data.frame from {base} R or tbl/tbl_df from {tibble}

  • stocnet stocnet, from the {manynet} package

  • igraph igraph, from the {igraph} package

  • network network, from the {network} package

  • tidygraph tbl_graph, from the {tidygraph} package

max_dist

The maximum breadth of the neighbourhood. By default 1.

min_dist

The minimum breadth of the neighbourhood. By default 0. Increasing this to 1 excludes the ego, and 2 excludes ego's direct alters.

direction

Character string, “out” bases the measure on outgoing ties, “in” on incoming ties, and "all" on either/the sum of the two. By default "all".

attribute

One or two attributes used to slice data.

connectivity

Character string, "weak" treats a directed network's components as if the network were undirected, and "strong" requires ties in both directions between members. This is ignored for undirected networks, where the two notions coincide. Note that the default differs by function: marks that assert connectedness default to "strong", while functions that scope or split a network into components default to "weak".

panels

Would you like to select certain waves? NULL by default. That is, a list of networks for every available wave is returned. Users can also list specific waves they want to select.

cumulative

Whether to make wave ties cumulative. FALSE by default. That is, each wave is treated isolated.

times

The moments to return the network at. By default NULL, in which case every moment the network records is returned, as net_times() counts them.

slice

Character string or character list indicating the date(s) or integer(s) range used to slice data (e.g slice = c(1:2, 3:4)).

Value

An object of the same class as the function was given, modified as explained in the function description, details, or section. Functions that split a network return a list of such objects.

Details

Not all functions have methods available for all object classes. Below are the currently implemented S3 methods:

              data.frame default diff_model igraph matrix network stocnet
to_components          *       *                 *      *       *       *
to_egos                *       *                 *      *       *       *
to_layers              *       *                 *              *
to_slices                      *                 *
to_subgraphs                   *                 *              *       *
to_times                       *                 *                      *
to_waves               *       *          *      *
              tbl_graph
to_components         *
to_egos               *
to_layers             *
to_slices             *
to_subgraphs          *
to_times              *
to_waves              *

to_times() returns the network as it stood at each moment it records, whichever way it records time, by calling to_time() on each in turn. to_waves() and to_slices() are the older, form-specific spellings: to_waves() splits a panel by its waves, and to_slices() accumulates an event network up to each of its moments. Unlike them, to_times() always returns a list, named by the moments and ordered by them, even where the network records only one, so that net_times(.data) and length(to_times(.data)) always agree.

to_layers()

The layers of a multiplex network are held in a tie attribute, type in tidygraph/igraph objects and layer in 'stocnet' objects. Each layer is extracted by to_uniplex(), so that the layers returned here are the same networks as retrieving them one at a time, and the returned list is named by the tie types found in the network. Where a network holds no tie types it is already uniplex, and a list of length one is returned.

Examples

  to_egos(ison_adolescents)
#> $Betty
#> # A labelled, undirected network of 2 nodes and 1 ties
#> 
#> ── Nodes 
#> # A tibble: 2 × 1
#>   name 
#>   <chr>
#> 1 Betty
#> 2 Sue  
#> 
#> ── Ties 
#> # A tibble: 1 × 2
#>    from    to
#>   <int> <int>
#> 1     1     2
#> 
#> 
#> $Sue
#> # A labelled, undirected network of 5 nodes and 6 ties
#> 
#> ── Nodes 
#> # A tibble: 5 × 1
#>   name 
#>   <chr>
#> 1 Betty
#> 2 Sue  
#> 3 Alice
#> 4 Dale 
#> 5 Pam  
#> 
#> ── Ties 
#> # A tibble: 6 × 2
#>    from    to
#>   <int> <int>
#> 1     1     2
#> 2     2     3
#> 3     2     4
#> 4     3     4
#> 5     2     5
#> 6     3     5
#> 
#> 
#> $Alice
#> # A labelled, undirected network of 5 nodes and 7 ties
#> 
#> ── Nodes 
#> # A tibble: 5 × 1
#>   name 
#>   <chr>
#> 1 Sue  
#> 2 Alice
#> 3 Jane 
#> 4 Dale 
#> 5 Pam  
#> 
#> ── Ties 
#> # A tibble: 7 × 2
#>    from    to
#>   <int> <int>
#> 1     1     2
#> 2     2     3
#> 3     1     4
#> 4     2     4
#> 5     3     4
#> 6     1     5
#> # ℹ 1 more row
#> 
#> 
#> $Jane
#> # A labelled, undirected network of 3 nodes and 3 ties
#> 
#> ── Nodes 
#> # A tibble: 3 × 1
#>   name 
#>   <chr>
#> 1 Alice
#> 2 Jane 
#> 3 Dale 
#> 
#> ── Ties 
#> # A tibble: 3 × 2
#>    from    to
#>   <int> <int>
#> 1     1     2
#> 2     1     3
#> 3     2     3
#> 
#> 
#> $Dale
#> # A labelled, undirected network of 4 nodes and 5 ties
#> 
#> ── Nodes 
#> # A tibble: 4 × 1
#>   name 
#>   <chr>
#> 1 Sue  
#> 2 Alice
#> 3 Jane 
#> 4 Dale 
#> 
#> ── Ties 
#> # A tibble: 5 × 2
#>    from    to
#>   <int> <int>
#> 1     1     2
#> 2     2     3
#> 3     1     4
#> 4     2     4
#> 5     3     4
#> 
#> 
#> $Pam
#> # A labelled, undirected network of 4 nodes and 4 ties
#> 
#> ── Nodes 
#> # A tibble: 4 × 1
#>   name 
#>   <chr>
#> 1 Sue  
#> 2 Alice
#> 3 Pam  
#> 4 Carol
#> 
#> ── Ties 
#> # A tibble: 4 × 2
#>    from    to
#>   <int> <int>
#> 1     1     2
#> 2     1     3
#> 3     2     3
#> 4     3     4
#> 
#> 
#> $Carol
#> # A labelled, undirected network of 3 nodes and 2 ties
#> 
#> ── Nodes 
#> # A tibble: 3 × 1
#>   name 
#>   <chr>
#> 1 Pam  
#> 2 Carol
#> 3 Tina 
#> 
#> ── Ties 
#> # A tibble: 2 × 2
#>    from    to
#>   <int> <int>
#> 1     1     2
#> 2     2     3
#> 
#> 
#> $Tina
#> # A labelled, undirected network of 2 nodes and 1 ties
#> 
#> ── Nodes 
#> # A tibble: 2 × 1
#>   name 
#>   <chr>
#> 1 Carol
#> 2 Tina 
#> 
#> ── Ties 
#> # A tibble: 1 × 2
#>    from    to
#>   <int> <int>
#> 1     1     2
#> 
#> 
  # graphs(to_egos(ison_adolescents,2))
ison_adolescents |>
  mutate(unicorn = sample(c("yes", "no"), 8,
                          replace = TRUE)) |>
  to_subgraphs(attribute = "unicorn")
#> [[1]]
#> # A labelled, undirected network of 3 nodes and 1 ties
#> 
#> ── Nodes 
#> # A tibble: 3 × 2
#>   name  unicorn
#>   <chr> <chr>  
#> 1 Betty yes    
#> 2 Alice yes    
#> 3 Jane  yes    
#> 
#> ── Ties 
#> # A tibble: 1 × 2
#>    from    to
#>   <int> <int>
#> 1     2     3
#> 
#> 
#> [[2]]
#> # A labelled, undirected network of 5 nodes and 4 ties
#> 
#> ── Nodes 
#> # A tibble: 5 × 2
#>   name  unicorn
#>   <chr> <chr>  
#> 1 Sue   no     
#> 2 Dale  no     
#> 3 Pam   no     
#> 4 Carol no     
#> 5 Tina  no     
#> 
#> ── Ties 
#> # A tibble: 4 × 2
#>    from    to
#>   <int> <int>
#> 1     1     2
#> 2     1     3
#> 3     3     4
#> 4     4     5
#> 
#> 
as_tidygraph(create_filled(5)) |>
  mutate_ties(type = sample(c("friend", "enemy"), 10, replace = TRUE)) |>
  to_layers()
#> $enemy
#> ── # Filled network ────────────────────────────────────────────────────────────
#> # A undirected network of 5 nodes and 5 enemy ties
#> 
#> ── Ties 
#> # A tibble: 5 × 2
#>    from    to
#>   <int> <int>
#> 1     1     2
#> 2     1     3
#> 3     2     3
#> 4     2     5
#> 5     3     5
#> 
#> 
#> $friend
#> ── # Filled network ────────────────────────────────────────────────────────────
#> # A undirected network of 5 nodes and 5 friend ties
#> 
#> ── Ties 
#> # A tibble: 5 × 2
#>    from    to
#>   <int> <int>
#> 1     1     4
#> 2     1     5
#> 3     2     4
#> 4     3     4
#> 5     4     5
#> 
#> 
  to_components(to_uniplex(fict_marvel, "relationship"))
#> [[1]]
#> ── # Marvel universe ───────────────────────────────────────────────────────────
#> # A labelled, complex, signed, undirected network of 50 nodes and 558
#> relationship ties (138 parallel)
#> # Transformed by exclusion and symmetrisation
#> 
#> ── Nodes 
#> # A tibble: 50 × 10
#>   label    Gender Appearances Attractive  Rich Intellect Omnilingual PowerOrigin
#>   <chr>    <chr>        <int>      <int> <int>     <int>       <int> <chr>      
#> 1 Abomina… Male           427          0     0         1           1 Radiation  
#> 2 Ant-Man  Male           589          1     0         1           0 Human      
#> 3 Apocaly… Male          1207          0     0         1           1 Mutant     
#> 4 Beast    Male          7609          1     0         1           0 Mutant     
#> 5 Black P… Male          2189          1     1         1           0 Human      
#> 6 Black W… Female        2907          1     0         1           0 Human      
#> # ℹ 44 more rows
#> # ℹ 2 more variables: UnarmedCombat <int>, ArmedCombat <int>
#> 
#> ── Ties 
#> # A tibble: 558 × 3
#>    from    to weight
#>   <int> <int>  <dbl>
#> 1     1     1     -1
#> 2     1     4     -1
#> 3     1    10     -1
#> 4     1    11     -1
#> 5     1    22     -1
#> 6     1    23     -1
#> # ℹ 552 more rows
#> 
#> 
#> [[2]]
#> ── # Marvel universe ───────────────────────────────────────────────────────────
#> # A labelled, weighted, undirected network of 1 node and 0 relationship ties
#> # Transformed by exclusion and symmetrisation
#> 
#> ── Nodes 
#> # A tibble: 1 × 10
#>   label Gender Appearances Attractive  Rich Intellect Omnilingual PowerOrigin
#>   <chr> <chr>        <int>      <int> <int>     <int>       <int> <chr>      
#> 1 Cable Male          2734          0     0         1           0 Mutant     
#> # ℹ 2 more variables: UnarmedCombat <int>, ArmedCombat <int>
#> 
#> ── Ties 
#> # A tibble: 0 × 3
#> # ℹ 3 variables: from <int>, to <int>, weight <dbl>
#> 
#> 
#> [[3]]
#> ── # Marvel universe ───────────────────────────────────────────────────────────
#> # A labelled, weighted, undirected network of 1 node and 0 relationship ties
#> # Transformed by exclusion and symmetrisation
#> 
#> ── Nodes 
#> # A tibble: 1 × 10
#>   label    Gender Appearances Attractive  Rich Intellect Omnilingual PowerOrigin
#>   <chr>    <chr>        <int>      <int> <int>     <int>       <int> <chr>      
#> 1 Iron Fi… Male          1789          0     1         1           0 Human      
#> # ℹ 2 more variables: UnarmedCombat <int>, ArmedCombat <int>
#> 
#> ── Ties 
#> # A tibble: 0 × 3
#> # ℹ 3 variables: from <int>, to <int>, weight <dbl>
#> 
#> 
#> [[4]]
#> ── # Marvel universe ───────────────────────────────────────────────────────────
#> # A labelled, weighted, undirected network of 1 node and 0 relationship ties
#> # Transformed by exclusion and symmetrisation
#> 
#> ── Nodes 
#> # A tibble: 1 × 10
#>   label    Gender Appearances Attractive  Rich Intellect Omnilingual PowerOrigin
#>   <chr>    <chr>        <int>      <int> <int>     <int>       <int> <chr>      
#> 1 Luke Ca… Male          2466          0     0         0           0 Human      
#> # ℹ 2 more variables: UnarmedCombat <int>, ArmedCombat <int>
#> 
#> ── Ties 
#> # A tibble: 0 × 3
#> # ℹ 3 variables: from <int>, to <int>, weight <dbl>
#> 
#> 
  # Strong decomposition of a directed network returns many small components,
  # ordered here from largest to smallest, so just the largest is shown:
  to_components(fict_starwars, connectivity = "strong")[[1]]
#> ── # Star Wars network data ────────────────────────────────────────────────────
#> # A longitudinal, labelled, complex, weighted, directed network of 46
#> characters and 274 interaction arcs over 7 waves
#> # Transformed by exclusion: not in component 1 (64 nodes excluded)
#> 
#> ── Nodes 
#> # A tibble: 46 × 12
#>   label       species homeworld sex   height hair_color eye_color skin_color
#>   <chr>       <chr>   <chr>     <chr>  <int> <chr>      <chr>     <chr>     
#> 1 Anakin      Human   Tatooine  male     188 blond      blue      fair      
#> 2 Bail Organa Human   Alderaan  male     191 black      brown     tan       
#> 3 Bib Fortuna Twi'lek Ryloth    male     180 none       pink      pale      
#> 4 Biggs       Human   Tatooine  male     183 black      brown     light     
#> # ℹ 42 more rows
#> # ℹ 4 more variables: birth_year <dbl>, mass <dbl>, faction <chr>, active <lgl>
#> 
#> ── Changes 
#> # A tibble: 82 × 4
#>    time  node var         value
#>   <int> <int> <chr>      <list>
#> 1     2     5 active  TRUE<chr>
#> 2     2     6 active FALSE<chr>
#> 3     2    10 active FALSE<chr>
#> 4     2    11 active  TRUE<chr>
#> # ℹ 78 more rows
#> 
#> ── Ties 
#> # A tibble: 274 × 4
#>    from    to weight  time
#>   <int> <int>  <int> <int>
#> 1    32    24      1     1
#> 2    30    43      1     1
#> 3    43    25      1     1
#> 4    32    43      1     1
#> # ℹ 270 more rows
#> 
ison_adolescents |>
  mutate_ties(wave = sample(1995:1998, 10, replace = TRUE)) |>
  to_waves(attribute = "wave")
#> $`1995`
#> # A longitudinal, labelled, undirected network of 8 nodes and 3 ties over 1
#> waves
#> 
#> ── Nodes 
#> # A tibble: 8 × 1
#>   name 
#>   <chr>
#> 1 Betty
#> 2 Sue  
#> 3 Alice
#> 4 Jane 
#> 5 Dale 
#> 6 Pam  
#> # ℹ 2 more rows
#> 
#> ── Ties 
#> # A tibble: 3 × 3
#>    from    to  wave
#>   <int> <int> <int>
#> 1     2     3  1995
#> 2     4     5  1995
#> 3     7     8  1995
#> 
#> 
#> $`1996`
#> # A longitudinal, labelled, undirected network of 8 nodes and 3 ties over 1
#> waves
#> 
#> ── Nodes 
#> # A tibble: 8 × 1
#>   name 
#>   <chr>
#> 1 Betty
#> 2 Sue  
#> 3 Alice
#> 4 Jane 
#> 5 Dale 
#> 6 Pam  
#> # ℹ 2 more rows
#> 
#> ── Ties 
#> # A tibble: 3 × 3
#>    from    to  wave
#>   <int> <int> <int>
#> 1     1     2  1996
#> 2     2     5  1996
#> 3     3     5  1996
#> 
#> 
#> $`1997`
#> # A longitudinal, labelled, undirected network of 8 nodes and 3 ties over 1
#> waves
#> 
#> ── Nodes 
#> # A tibble: 8 × 1
#>   name 
#>   <chr>
#> 1 Betty
#> 2 Sue  
#> 3 Alice
#> 4 Jane 
#> 5 Dale 
#> 6 Pam  
#> # ℹ 2 more rows
#> 
#> ── Ties 
#> # A tibble: 3 × 3
#>    from    to  wave
#>   <int> <int> <int>
#> 1     2     6  1997
#> 2     3     6  1997
#> 3     6     7  1997
#> 
#> 
#> $`1998`
#> # A longitudinal, labelled, undirected network of 8 nodes and 1 ties over 1
#> waves
#> 
#> ── Nodes 
#> # A tibble: 8 × 1
#>   name 
#>   <chr>
#> 1 Betty
#> 2 Sue  
#> 3 Alice
#> 4 Jane 
#> 5 Dale 
#> 6 Pam  
#> # ℹ 2 more rows
#> 
#> ── Ties 
#> # A tibble: 1 × 3
#>    from    to  wave
#>   <int> <int> <int>
#> 1     3     4  1998
#> 
#> 
  length(to_times(irps_wwi))
#> [1] 7
  to_times(ison_tailorshop)
#> $`1`
#> ── # Kapferer's Tailor Shop ────────────────────────────────────────────────────
#> # A labelled, multiplex, directed network of 39 workers and 109 instrumental
#> arcs and 158 sociational ties
#> # Transformed by exclusion: not tied at time 1 (370 ties excluded)
#> 
#> ── Nodes 
#> # A tibble: 39 × 1
#>   label   
#>   <chr>   
#> 1 Kamwefu 
#> 2 Nkumbula
#> 3 Abraham 
#> 4 Seams   
#> 5 Chipata 
#> 6 Donald  
#> # ℹ 33 more rows
#> 
#> ── Ties 
#> # A tibble: 267 × 3
#>    from    to layer       
#>   <int> <int> <chr>       
#> 1     3     1 instrumental
#> 2     4     1 instrumental
#> 3    14     1 instrumental
#> 4    11     2 instrumental
#> 5    12     2 instrumental
#> 6     1     3 instrumental
#> # ℹ 261 more rows
#> 
#> 
#> $`2`
#> ── # Kapferer's Tailor Shop ────────────────────────────────────────────────────
#> # A labelled, multiplex, directed network of 39 workers and 147 instrumental
#> arcs and 223 sociational ties
#> # Transformed by exclusion: not tied at time 2 (267 ties excluded)
#> 
#> ── Nodes 
#> # A tibble: 39 × 1
#>   label   
#>   <chr>   
#> 1 Kamwefu 
#> 2 Nkumbula
#> 3 Abraham 
#> 4 Seams   
#> 5 Chipata 
#> 6 Donald  
#> # ℹ 33 more rows
#> 
#> ── Ties 
#> # A tibble: 370 × 3
#>    from    to layer       
#>   <int> <int> <chr>       
#> 1     3     1 instrumental
#> 2    11     1 instrumental
#> 3     1     2 instrumental
#> 4     5     2 instrumental
#> 5    12     2 instrumental
#> 6    16     2 instrumental
#> # ℹ 364 more rows
#> 
#> 
ison_adolescents |>
  mutate_ties(time = 1:10, increment = 1) |> 
  add_ties(c(1,2), list(time = 3, increment = -1)) |> 
  to_slices(slice = 7)
#> # A labelled, undirected network of 8 nodes and 6 ties
#> 
#> ── Nodes 
#> # A tibble: 8 × 1
#>   name 
#>   <chr>
#> 1 Betty
#> 2 Sue  
#> 3 Alice
#> 4 Jane 
#> 5 Dale 
#> 6 Pam  
#> # ℹ 2 more rows
#> 
#> ── Ties 
#> # A tibble: 6 × 3
#>    from    to weight
#>   <int> <int>  <dbl>
#> 1     2     3      1
#> 2     3     4      1
#> 3     2     5      1
#> 4     3     5      1
#> 5     4     5      1
#> 6     2     6      1
#>