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