Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

get.inducedSubgraph

Retrieve Induced Subgraphs and Cuts


Description

Given a set of vertex IDs, get.inducedSubgraph returns the subgraph induced by the specified vertices (i.e., the vertices and all associated edges). Optionally, passing a second set of alters returns the cut from the first to the second set (i.e., all edges passing between the sets), along with the associated endpoints. Alternatively, passing in a vector of edge ids will induce a subgraph containing the specified edges and their incident vertices. In all cases, the result is returned as a network object, with all attributes of the selected edges and/or vertices (and any network attributes) preserved.

Usage

get.inducedSubgraph(x, v, alters = NULL, eid = NULL)

x %s% v

Arguments

x

an object of class network.

v

a vector of vertex IDs, or, for %s%, optionally a list containing two disjoint vectors of vertex IDs (see below).

alters

optionally, a second vector of vertex IDs. Must be disjoint with v.

eid

optionally, a numeric vector of valid edge ids in x that should be retained (cannot be used with v or alter)

Details

For get.inducedSubgraph, v can be a vector of vertex IDs. If alter=NULL, the subgraph induced by these vertices is returned. Calling %s% with a single vector of vertices has an identical effect.

Where alters is specified, it must be a vector of IDs disjoint with v. Where both are given, the edges spanning v and alters are returned, along with the vertices in question. (Technically, only the edges really constitute the “cut,” but the vertices are included as well.) The same result can be obtained with the %s% operator by passing a two-element list on the right hand side; the first element is then interpreted as v, and the second as alters.

When eid is specified, the v and alters argument will be ignored and the subgraph induced by the specified edges and their incident vertices will be returned.

Any network, vertex, or edge attributes for the selected network elements are retained (although features such as vertex IDs and the network size will typically change). These are copies of the elements in the original network, which is not altered by this function.

Value

A network object containing the induced subgraph.

Author(s)

Carter T. Butts buttsc@uci.edu

See Also

Examples

#Load the Drabek et al. EMON data
data(emon)

#For the Mt. St. Helens, EMON, several types of organizations are present:
type<-emon$MtStHelens %v% "Sponsorship"

#Plot interactions among the state organizations
plot(emon$MtStHelens %s% which(type=="State"), displaylabels=TRUE)

#Plot state/federal interactions
plot(emon$MtStHelens %s% list(which(type=="State"), 
    which(type=="Federal")),  displaylabels=TRUE)

#Plot state interactions with everyone else
plot(emon$MtStHelens %s% list(which(type=="State"), 
    which(type!="State")), displaylabels=TRUE)
    
# plot only interactions with frequency of 2
subG2<-get.inducedSubgraph(emon$MtStHelens,
            eid=which(emon$MtStHelens%e%'Frequency'==2))
plot(subG2,edge.label='Frequency')

network

Classes for Relational Data

v1.16.1
GPL (>= 2)
Authors
Carter T. Butts [aut, cre], David Hunter [ctb], Mark Handcock [ctb], Skye Bender-deMoll [ctb], Jeffrey Horner [ctb], Li Wang [ctb]
Initial release
2020-10-06

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.