network.collapse: Convert a time range of a networkDynamic object into a static...

View source: R/extract.R

network.collapseR Documentation

Convert a time range of a networkDynamic object into a static network object.


This function provides an easy way to sensibly collapse the time-related information in a networkDynamic object and return a plain network object with a set of vertices, edges, and attributes that appropriately correspond to those appearing in the original networkDynamic object during the query interval.


network.collapse(dnet, onset = NULL, terminus = NULL, at = NULL, length = NULL, 
                 rule = c("any", "all","earliest","latest"), active.default = TRUE, 
                 retain.all.vertices=FALSE,, ...)



A networkDynamic object with possible vertex, edge, network, and attribute spell information.


optionally, the start of the specified interval. This must be accompanied by one of terminus or length.


optionally, the end of the specified interval. This must be accompanied by one of onset or length.


optionally, the length of the specified interval. This must be accompanied by one of onset or terminus.


optionally, a single time point.


a text string for defining “active” for this call: any if elements active at any time during the interval are to be used, or all if elements must be active over the entire interval. The value earliest behaves like any but specifies that when multiple attribute values are encountered, only the earliest will be returned. The value latest behaves like any but specifies that when multiple attribute values are encountered, only the latest will be returned.


logical; should elements without an activity attribute be regarded as active by default?


logical; should the extracted network retain all vertices, ignoring the vertex activity spells of x in order to ensure that the network returned has the same size as dnet?

logical; if TRUE, the net.obs.period attribute will be removed (if it exists), and the activity summary attributes activity.count and activity.duration will not be attached to edges and vertices


Possible additional arguments (not yet invented) to handle aggregation of attributes.


First performs a network.extract on the passed networkDynamic object with the specified time range to get the appropriate set of active edges. Extracts appropriate values from any dynamic attributes and stores them as static attributes and optionally (if computes some crude summary attributes for edge and vertex spells (activity.count, activity.duration),. Then removes all activity.attribute and dynamic.attributes information and returns a plain network without the networkDynamic class.

The %k% operator (‘K’ for kollapse) is a shortcut for the 'at' version of network.collapse.

If no temporal arguments are specified, defaults to collapsing entire time range of the input network (onset=-Inf,terminus=Inf). Original network is not modified.

Arbitrary attribute values may be returned when query spells with a duration are used for continuous time networks (i.e. anything other than 'at') or query spells that don't line up with the discrete units for discrete time networks are used. If a query spell intersects with multiple attribute values, a warning will be produced and only the earliest value will be used (see To avoid ambiguity (and the warning), appropriate handling can be specified by setting rule='earliest' or rule='latest' to indicate which of the multiple values should be returned.

The duration values returned for edges do not account for any potential ‘censoring’ of observations in the original network.


A new 'static' network object corresponding to the specified time range of the networkDynamic argument. If the original network contained dynamic TEA attributes (i.e. ''), the appropriate (if possible) value is queried and stored as a non-TEA attribute ('weight').


This function may be quite computationally expensive if the network contains lots of attributes. For many tasks it is possible to avoid collapsing the network by using, the dynamic network.extensions, and the attribute.activity.functions.


Skye Bender-deMoll

See Also

See also network.extract for extracting sub-ranges of a networkDynamic, for more on TEA attributes, and for stripping the the networkDynamic class from an object without the expense of modifying or removing the activity attributes.


# create a network with some basic activity
test<-network.initialize(5), tail=c(1,2,3), head=c(2,3,4),onset=0,terminus=1)

# collapse the whole thing
net <-network.collapse(test)

# add a dynamic edge attribute

# collapse with an interval query

# note that if we use a query that intersects mutiple 
# attribute values it will generate a warning. 
# try commented line below:

# net3<-network.collapse(test,onset=3,terminus=5)

# but should be safe from attribute issues when
# collapsing with a point query

# can use operator version for point query instead

networkDynamic documentation built on Feb. 16, 2023, 10:08 p.m.