These functions offer tools for transforming manynet-consistent objects (matrices, igraph, tidygraph, or network objects). Transforming means that the returned object may have different dimensions than the original object.
to_ego() scopes a network into the local neighbourhood of a given node.
to_component() scopes a network to a single one of its components,
either the componentth largest or the one containing a named node.
It is the singular counterpart of to_components(),
which returns a list of all of them, largest first.
to_giant() scopes a network into one including only the main component
and no smaller components or isolates.
It is a wrapper, such that to_giant(.data) is to_component(.data, 1).
to_time() scopes a network to the network as it stood at a given
moment, in whichever of the ways set out in the Time section it records
time. to_wave() is an alias, using the wave-based vocabulary of
net_waves() and to_waves(). For one network per moment, see
to_times().
to_reporter() scopes a cognitive social structure to the report of
one of its reporters. For one network per reporter, see
to_reporters().
to_subgraph() scopes a network into a subgraph by filtering on some node-related logical statement.
to_blockmodel() reduces a network to the ties between the blocks of a
given partition membership vector.
to_ego(.data, node, max_dist = 1, min_dist = 0, direction = c("out", "in"))
to_time(.data, time = NULL, window = NULL, kernel = "uniform")
to_wave(.data, time = NULL, window = NULL, kernel = "uniform")
to_reporter(.data, reporter)
to_component(.data, component = 1, connectivity = c("weak", "strong"))
to_giant(.data, connectivity = c("weak", "strong"))
to_subgraph(.data, ...)
to_blockmodel(.data, membership, FUN = mean)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
Name or index of node.
The maximum breadth of the neighbourhood. By default 1.
The minimum breadth of the neighbourhood. By default 0. Increasing this to 1 excludes the ego, and 2 excludes ego's direct alters.
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".
A moment at which to present the network. A moment beyond the last one the network records reverts to the last, except in an interval network, which is defined between the moments it records as well as at them.
The width of a window of the moments up to time, or
NULL (the default) for no window.
Two widths, c(before, after), give a window that also reaches past
time, so that c(15, 15) gives a window centred on time.
A width is in the units of the moments the network records:
waves, years, or days where the moments are dates
(or seconds where they are date-times).
A difftime, such as as.difftime(30, units = "days"), is also accepted.
How each tie in a window is weighted by its distance
from time.
"uniform" (the default) weights every tie in the window the same,
and so leaves the ties as they are.
"triangular", "epanechnikov", and "gaussian" give a tie less weight
the further it is from time.
Only used with a window.
Label or index of the node whose report on the network is to be retained, in a cognitive social structure.
Which component to retain. By default 1, i.e. the largest (giant) component, with 2 the second largest, and so on. Alternatively, the name of a node, in which case the component containing that node is retained.
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".
Arguments passed on to dplyr::filter
A vector of partition memberships. For two-mode networks this is a single vector covering the nodes in both modes, and not one vector per mode; the blocks of each mode are established separately from it, so that the result has one row per block of the first mode and one column per block of the second.
A function for summarising block content.
By default mean.
Other recommended options include median, sum,
min or max.
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.
Not all functions have methods available for all object classes. Below are the currently implemented S3 methods:
Two things about how a network records time are independent of each other, and the network is scoped to a moment by both of them.
How a moment is represented can be read from the ties. A network either stamps each tie with the point it was recorded at, in a 'time' column, or states the interval each tie lasts over, in 'begin' and 'end' columns.
How a moment relates to the one before it cannot be read from the ties,
and the network declares it in info$update. Where this is "replace",
which it is by default, each moment re-states the ties, so the network at
a moment is the ties stamped with it. Where it is "increment", each row
is a change to a tie's value, so the network at a moment is every row up
to and including it, accumulated, and a tie that has accumulated to zero
is no longer a tie. An interval tie carries its own lifespan, so nothing
is declared about it: it is active at a moment where it began at or
before that moment and has not yet ended (begin <= time < end, the
half-open convention shared with network::networkDynamic, so a tie that
ends and one that begins at the same instant do not overlap). A tie with
no 'end' is right-censored, and active from its beginning onwards.
info$observation records a third thing, how densely the network is
observed: a "panel" of a few complete re-observations, or a stream of
many "event" records. This describes a network rather than scoping it.
The two go together without entailing each other: a panel re-observes
the whole network at each wave and so is usually "replace", and an event
stream is often "increment", but an event that states a value afresh is
"replace" too. is_longitudinal() marks the first, is_dynamic() the
second, and no network is both.
In every case the nodal changes recorded up to the moment are applied, and a layer that states something holding throughout is carried into whichever moment is asked for, since such a layer is a constant covariate rather than an observation of that moment. A layer holds throughout where the network declares it "cross-sectional", or where it records that layer at a single moment while another layer spans several.
A window asks for a third thing: not the state of the network at a
moment, but the ties recorded in a period that ends at it.
A window of width \(w\) holds the ties recorded after
time - w and up to and including time, so it looks back only,
and never holds a tie recorded after time.
In a panel, window = 1 holds the wave at time,
and window = 2 that wave and the one before it.
An infinite window, window = Inf, holds every tie recorded up to time.
Two widths, window = c(before, after), also hold the ties recorded
after time and up to and including time + after.
With equal widths the window is centred on time, a smoother that
describes the network around a moment without a lag.
But a network so made holds ties that were recorded after time,
so do not use it where the network at time must only know its past,
as a predictor in a model does.
A window holds its ties whatever info$update declares:
the ties are neither accumulated nor carried forward,
and each row in the window stays a tie of its own,
so a pair recorded twice in the window is tied twice.
As without a window, the 'time' stamp is dropped from the result,
since the network that is returned no longer varies in time,
and time is not reverted to the last moment the network records.
An interval tie is in the window where its interval overlaps the window,
and its distance from time is the distance from time to the nearest
moment of its interval, so a tie active at time is at no distance.
A kernel other than "uniform" multiplies the tie's 'weight'
by the kernel value, or gives an unweighted tie the kernel value as its
'weight'. Where \(u\) is the distance of the tie from time over the
width of the window on that side of time, the kernel values are
\(1 - u\) ("triangular"), \(1 - u^2\) ("epanechnikov"), and
\(\exp(-2u^2)\) ("gaussian", which puts the far edge of the window at
two standard deviations).
Each kernel is 1 at time, so a tie at time keeps its weight,
and in an infinite window every tie keeps its weight.
A tie that the kernel weights at zero, at the far edge of a triangular or
epanechnikov window, is dropped.
A layer that holds throughout is carried in with its weight unchanged.
to_blockmodel()Reduced graphs provide summary representations of network structures
by collapsing groups of connected nodes into single nodes
while preserving the topology of the original structures.
Like the other scoping functions, the reduced graph is returned in the
same class as the input: a blockmodel matrix of summarised block content
for matrix input, and the corresponding weighted network otherwise.
Memberships are usually obtained from one of the node_in_*() functions
in {netrics}.
to_times() for one network per moment, and net_times() for how
many moments there are to ask for.
Other modifications:
modif_backbone,
modif_concepts,
modif_direction,
modif_from_parts,
modif_from_ternary,
modif_influence,
modif_labels,
modif_layers,
modif_levels,
modif_loops,
modif_miss,
modif_motifs,
modif_paths,
modif_permutation,
modif_project,
modif_proximity,
modif_split,
modif_weight
# The ties a panel observed in a given wave:
to_time(ison_monks, 2)
#>
#> ── # Sampson's Monks ───────────────────────────────────────────────────────────
#> # A labelled, multiplex, signed, weighted, directed network of 18 nodes and 57
#> like arcs, 112 esteem arcs, 103 influence arcs, and 80 praise arcs
#> # Transformed by exclusion: not tied at time 2 (111 ties excluded)
#>
#> ── Nodes
#> # A tibble: 18 × 3
#> label groups left
#> <chr> <chr> <dbl>
#> 1 Romuald Interstitial 3
#> 2 Bonaventure Loyal 4
#> 3 Ambrose Loyal 4
#> 4 Berthold Loyal 4
#> 5 Peter Loyal 3
#> 6 Louis Loyal 4
#> # ℹ 12 more rows
#>
#> ── Ties
#> # A tibble: 352 × 4
#> from to weight layer
#> <int> <int> <dbl> <chr>
#> 1 1 2 1 like
#> 2 1 5 3 like
#> 3 1 15 2 like
#> 4 2 3 1 esteem
#> 5 2 5 3 esteem
#> 6 2 5 3 influence
#> # ℹ 346 more rows
#>
# The ties an interval network held in a given year:
to_time(irps_wwi, 1901)
#> ── # World War I Protagonists ──────────────────────────────────────────────────
#> # A dynamic, labelled, signed, undirected network of 6 European major powers
#> and 11 relationship ties from 1872 to 1918
#> # Transformed by exclusion: not tied at time 1901 (9 ties excluded)
#>
#> ── Nodes
#> # A tibble: 6 × 1
#> label
#> <chr>
#> 1 GBR
#> 2 FRA
#> 3 RUS
#> 4 AUH
#> 5 DEU
#> 6 ITA
#>
#> ── Ties
#> # A tibble: 11 × 5
#> from to weight begin end
#> <int> <int> <dbl> <dbl> <dbl>
#> 1 1 2 -1 1872 1904
#> 2 1 3 -1 1872 1907
#> 3 1 4 -1 1872 1918
#> 4 2 4 -1 1872 1918
#> 5 2 5 -1 1872 1918
#> 6 4 5 1 1872 1918
#> # ℹ 5 more rows
#>
# The state an event network had accumulated to by a given day:
to_time(irps_nuclear, as.Date("2011-04-01"))
#> ── # German nuclear discourse network ──────────────────────────────────────────
#> # A dynamic, labelled, signed, weighted, two-mode network of 337 speakers and
#> 54 concepts and 352 claim ties
#> # Transformed by exclusion: not tied at time 2011-04-01 (812 ties excluded)
#>
#> ── Nodes
#> # A tibble: 391 × 10
#> label mode active politician govt coalition office org party power
#> <chr> <chr> <lgl> <lgl> <lgl> <lgl> <lgl> <chr> <chr> <int>
#> 1 VfEW spea… TRUE FALSE FALSE NA FALSE VfEW NA 0
#> 2 Angela Merkel spea… TRUE TRUE TRUE TRUE TRUE CDU 31 2
#> 3 Sunday Times spea… TRUE FALSE FALSE NA FALSE Sund… NA 0
#> 4 SPD spea… TRUE TRUE FALSE FALSE FALSE SPD 32 1
#> 5 Norbert Rött… spea… TRUE TRUE TRUE TRUE TRUE CDU 31 1
#> 6 Torsten Krau… spea… TRUE FALSE FALSE NA FALSE Die … NA 0
#> # ℹ 385 more rows
#>
#> ── Ties
#> # A tibble: 352 × 3
#> from to weight
#> <int> <int> <int>
#> 1 1 338 -1
#> 2 2 339 6
#> 3 3 340 -1
#> 4 4 341 4
#> 5 2 342 -2
#> 6 5 343 1
#> # ℹ 346 more rows
#>
# The statements made in the 30 days up to that day,
# weighted down the longer ago they were made:
to_time(irps_nuclear, as.Date("2011-04-01"), window = 30,
kernel = "triangular")
#> ── # German nuclear discourse network ──────────────────────────────────────────
#> # A dynamic, labelled, signed, weighted, two-mode network of 337 speakers and
#> 54 concepts and 449 claim ties (152 parallel)
#> # Transformed by exclusion: not tied in the 30 up to time 2011-04-01
#>
#> ── Nodes
#> # A tibble: 391 × 10
#> label mode active politician govt coalition office org party power
#> <chr> <chr> <lgl> <lgl> <lgl> <lgl> <lgl> <chr> <chr> <int>
#> 1 VfEW spea… TRUE FALSE FALSE NA FALSE VfEW NA 0
#> 2 Angela Merkel spea… TRUE TRUE TRUE TRUE TRUE CDU 31 2
#> 3 Sunday Times spea… TRUE FALSE FALSE NA FALSE Sund… NA 0
#> 4 SPD spea… TRUE TRUE FALSE FALSE FALSE SPD 32 1
#> 5 Norbert Rött… spea… TRUE TRUE TRUE TRUE TRUE CDU 31 1
#> 6 Torsten Krau… spea… TRUE FALSE FALSE NA FALSE Die … NA 0
#> # ℹ 385 more rows
#>
#> ── Ties
#> # A tibble: 449 × 4
#> from to weight default
#> <int> <int> <dbl> <lgl>
#> 1 1 338 -0.3 FALSE
#> 2 2 339 0.333 TRUE
#> 3 3 340 -0.367 FALSE
#> 4 4 341 0.367 TRUE
#> 5 2 342 -0.367 TRUE
#> 6 5 343 0.367 TRUE
#> # ℹ 443 more rows
#>
# The statements made in the 15 days either side of that day:
to_time(irps_nuclear, as.Date("2011-04-01"), window = c(15, 15))
#> ── # German nuclear discourse network ──────────────────────────────────────────
#> # A dynamic, labelled, signed, two-mode network of 337 speakers and 54 concepts
#> and 393 claim ties (123 parallel)
#> # Transformed by exclusion: not tied from 15 before to 15 after time 2011-04-01
#>
#> ── Nodes
#> # A tibble: 391 × 10
#> label mode active politician govt coalition office org party power
#> <chr> <chr> <lgl> <lgl> <lgl> <lgl> <lgl> <chr> <chr> <int>
#> 1 VfEW spea… TRUE FALSE FALSE NA FALSE VfEW NA 0
#> 2 Angela Merkel spea… TRUE TRUE TRUE TRUE TRUE CDU 31 2
#> 3 Sunday Times spea… TRUE FALSE FALSE NA FALSE Sund… NA 0
#> 4 SPD spea… TRUE TRUE FALSE FALSE FALSE SPD 32 1
#> 5 Norbert Rött… spea… TRUE TRUE TRUE TRUE TRUE CDU 31 1
#> 6 Torsten Krau… spea… TRUE FALSE FALSE NA FALSE Die … NA 0
#> # ℹ 385 more rows
#>
#> ── Ties
#> # A tibble: 393 × 4
#> from to weight default
#> <int> <int> <int> <lgl>
#> 1 94 342 1 FALSE
#> 2 95 350 1 FALSE
#> 3 96 365 1 FALSE
#> 4 97 370 1 FALSE
#> 5 97 350 1 FALSE
#> 6 97 353 1 FALSE
#> # ℹ 387 more rows
#>
css <- as_stocnet(array(rbinom(27, 1, 0.5), c(3, 3, 3)), over = "by")
to_reporter(css, 2)
#> # A complex, directed network of 3 nodes and 6 arcs
#> # Transformed by exclusion: not reported by 2 (10 ties excluded)
#>
#> ── Ties
#> # A tibble: 6 × 2
#> from to
#> <int> <int>
#> 1 1 1
#> 2 2 1
#> 3 3 1
#> 4 1 2
#> 5 1 3
#> 6 3 3
#>
to_component(fict_greys, 2)
#> ── # Component 2 of Grey's Anatomy ─────────────────────────────────────────────
#> # A labelled, undirected network of 6 characters and 5 hook-up ties
#> # Transformed by exclusion: not in component 2 (47 nodes excluded)
#>
#> ── Nodes
#> # A tibble: 6 × 7
#> label sex race birthyear position season sign
#> <chr> <chr> <chr> <dbl> <chr> <dbl> <chr>
#> 1 Adele Webber F Black 1949 Non-Staff 2 "Leo"
#> 2 Catherine Avery F Other 1950 Attending 8 "Capricorn"
#> 3 Ellis Grey F White 1957 Attending 1 "Virgo"
#> 4 Susan Grey F White 1959 Non-Staff 2 "Taurus"
#> 5 Thatcher Grey M White 1955 Non-Staff 2 "Leo"
#> 6 Richard Webber M Black 1954 Chief 1 ""
#>
#> ── Ties
#> # A tibble: 5 × 2
#> from to
#> <int> <int>
#> 1 3 6
#> 2 3 5
#> 3 2 6
#> 4 4 5
#> 5 1 6
#>
to_component(fict_greys, "Miranda Bailey")
#> ── # Component containing Miranda Bailey of Grey's Anatomy ─────────────────────
#> # A labelled, undirected network of 4 characters and 3 hook-up ties
#> # Transformed by exclusion: not in the component containing Miranda Bailey
#>
#> ── Nodes
#> # A tibble: 4 × 7
#> label sex race birthyear position season sign
#> <chr> <chr> <chr> <dbl> <chr> <dbl> <chr>
#> 1 Miranda Bailey F Black 1969 Attending 1 Virgo
#> 2 Ben Warren M Black 1972 Other 6 Aquarius
#> 3 Eli Lloyd M Black 1971 Nurse 7 Capricorn
#> 4 Tucker Jones M Black 1970 Non-Staff 2 Leo
#>
#> ── Ties
#> # A tibble: 3 × 2
#> from to
#> <int> <int>
#> 1 1 2
#> 2 1 4
#> 3 1 3
#>
to_giant(fict_greys)
#> ── # Giant component of Grey's Anatomy ─────────────────────────────────────────
#> # A labelled, undirected network of 40 characters and 46 hook-up ties
#> # Transformed by exclusion: not in component 1 (13 nodes excluded)
#>
#> ── Nodes
#> # A tibble: 40 × 7
#> label sex race birthyear position season sign
#> <chr> <chr> <chr> <dbl> <chr> <dbl> <chr>
#> 1 Addison Montgomery F White 1967 Attending 1 Libra
#> 2 Teddy Altman F White 1969 Attending 6 Pisces
#> 3 Amelia Shepherd F White 1981 Attending 7 Libra
#> 4 Arizona Robbins F White 1976 Attending 5 Leo
#> 5 Rebecca Pope F White 1975 Non-Staff 3 Gemini
#> 6 Jackson Avery M Black 1981 Resident 6 Leo
#> # ℹ 34 more rows
#>
#> ── Ties
#> # A tibble: 46 × 2
#> from to
#> <int> <int>
#> 1 4 35
#> 2 16 35
#> 3 4 34
#> 4 4 30
#> 5 13 30
#> 6 16 30
#> # ℹ 40 more rows
#>