Learn R Programming

RNewsflow (version 1.2.6)

network_aggregate: Aggregate the edges of a network by vertex attributes

Description

This function offers a versatile way to aggregate the edges of a network based on the vertex attributes. Although it was designed specifically for document similarity networks, it can be used for any network in the igraph class.

Usage

network_aggregate(
  g,
  by = NULL,
  by_from = by,
  by_to = by,
  edge_attribute = "weight",
  agg_FUN = mean,
  return_df = FALSE,
  keep_isolates = T
)

Value

A network/graph in the igraph class, or a data.frame if return_df is TRUE.

Arguments

g

A network/graph in the igraph class

by

A character string indicating the vertex attributes by which the edges will be aggregated.

by_from

Optionally, specify different vertex attributes to aggregate the `from` side of edges

by_to

Optionally, specify different vertex attributes to aggregate the `to` side of edges

edge_attribute

Select an edge attribute to aggregate using the function specified in `agg_FUN`. Defaults to 'weight'

agg_FUN

The function used to aggregate the edge attribute

return_df

Optional. If TRUE, the results are returned as a data.frame. This can in particular be convenient if by_from and by_to are used.

keep_isolates

if True, also return scores for isolates

Details

The first argument is the network (in the `igraph` class). The second argument, for the `by` parameter, is a character vector to indicate one or more vertex attributes based on which the edges are aggregated. Optionally, the `by` parameter can also be specified separately for `by_from` and `by_to`.

By default, the function returns the aggregated network as an igraph class. The edges in the aggregated network have five standard attributes. The `edges` attribute counts the number of edges from the `from` group to the `to` group. The `from.V` attribute shows the number of vertices in the `from` group that matched with a vertex in the `to` group. The `from.Vprop attribute shows this as the proportion of all vertices in the `from` group. The `to.V` and `to.Vprop` attributes show the same for the `to` group.

In addition, one of the edge attributes of the original network can be aggregated with a given function. These are specified in the `edge_attribute` and `agg_FUN` parameters.

Examples

Run this code
data(docnet)
aggdocnet = network_aggregate(docnet, by='sourcetype')
igraph::get.data.frame(aggdocnet, 'both')

aggdocdf = network_aggregate(docnet, by_from='sourcetype', by_to='source', return_df = TRUE)
head(aggdocdf)

Run the code above in your browser using DataLab