network_view {ergm.multi}R Documentation

Construct a "view" of a network.

Description

Returns a network with edges optionally filtered according to a specified criterion and with edge attributes optionally computed from other edge attributes.

Usage

network_view(x, ..., .clear = FALSE, .sep = ".")

Arguments

x

a network object.

...

a list of attribute or filtering specifications. See Details.

.clear

whether the edge attributes not set by this call should be deleted.

.sep

when specifying via a character vector, use this as the separator for concatenating edge values.

Details

Attribute specification arguments have the form ⁠<newattrname> = <expr>⁠, where ⁠<newattrname>⁠ specifies the name of the new edge attribute (or attribute to be overwritten) and ⁠<expr>⁠ can be one of the following:

a function

The function will be passed two arguments, the edgelist tibble and the network, and must return a vector of edge attribute values to be set on the edges in the order specified.

a formula

The expression on the RHS of the formula will be evaluated with names in it referencing the edge attributes. The input network may be referenced as .nw. The expression's result is expected to be a vector of edge attribute values to be set on the edges in the order specified.

a character vector

If of length one, the edge attribute with that name will simply be copied; if greater than one, the attribute values will be concatenated wtih the .sep argument as the separator.

an object enclosed in I()

The object will be used directly to set the edge attribute.

Filtering arguments are specified the same way as attribute arguments, but they must be unnamed arguments (i.e., must be passed without the =) and must return a logical or numeric vector suitable for indexing the edge list. Multiple filtering arguments may be specified, and the edge will be kept if it satisfies all. If the conjunction of the edge's original states and the filtering results is ambiguous (i.e., NA), it will be set as missing.

Value

A network object with modified edges and edge attributes.

Examples

data(florentine)
flo <- flomarriage
flo[,,add.edges=TRUE] <- as.matrix(flomarriage) | as.matrix(flobusiness)
flo[,, names.eval="m"] <- as.matrix(flomarriage)==1
flobusiness[3,5] <- NA
flo[,, names.eval="b"] <- as.matrix(flobusiness)==1
flo
(flob <- network_view(flo, "b"))
(flobusiness) # for comparison


(flob <- network_view(flo, ~b&m))
(flobusiness & flomarriage) # for comparison


as.matrix(flob <- network_view(flo, bm=~b+m), attrname="bm")
(as.matrix(flobusiness) + as.matrix(flomarriage)) # for comparison


as.matrix(flob <- network_view(flo, ~b, bm=~b+m), attrname="bm")
as.matrix(flobusiness)*(1+as.matrix(flomarriage)) # for comparison




[Package ergm.multi version 0.2.1 Index]