ergm_symmetrize | R Documentation |
Return a symmetrized version of a binary network
ergm_symmetrize(x, rule = c("weak", "strong", "upper", "lower"), ...)
## Default S3 method:
ergm_symmetrize(x, rule = c("weak", "strong", "upper", "lower"), ...)
## S3 method for class 'network'
ergm_symmetrize(x, rule = c("weak", "strong", "upper", "lower"), ...)
x |
an object representing a network. |
rule |
a string specifying how the network is to be
symmetrized; see |
... |
additional arguments to |
The network
method requires more flexibility, in order
to specify how the edge attributes are handled. Therefore, rule
can be one of the following types:
The string is interpreted as in
sna::symmetrize()
. For edge attributes, "weak"
takes the
maximum value and "strong"
takes the minimum
value" for ordered attributes, and drops the unordered.
The function is evaluated on a data.frame
constructed by joining (via merge()
) the edge tibble
with all
attributes and NA
indicators with itself reversing tail and head
columns, and appending original columns with ".th"
and the
reversed columns with ".ht"
. It is then evaluated for each
attribute in turn, given two arguments: the data frame and the name
of the attribute.
The list must have exactly one unnamed element, and the remaining elements must be named with the names of edge attributes. The elements of the list are interpreted as above, allowing each edge attribute to be handled differently. Unnamed arguments are dropped.
ergm_symmetrize(default)
: The default method, passing the input on to sna::symmetrize()
.
ergm_symmetrize(network)
: A method for network
objects, which preserves network and vertex attributes, and handles edge attributes.
This was originally exported as a generic to overwrite
sna::symmetrize()
. By developer's request, it has been renamed;
eventually, sna or network
packages will export the generic
instead.
data(sampson)
samplike[1,2] <- NA
samplike[4.1] <- NA
sm <- as.matrix(samplike)
tst <- function(x,y){
mapply(identical, x, y)
}
stopifnot(all(tst(as.logical(as.matrix(ergm_symmetrize(samplike, "weak"))), sm | t(sm))),
all(tst(as.logical(as.matrix(ergm_symmetrize(samplike, "strong"))), sm & t(sm))),
all(tst(c(as.matrix(ergm_symmetrize(samplike, "upper"))),
sm[cbind(c(pmin(row(sm),col(sm))),c(pmax(row(sm),col(sm))))])),
all(tst(c(as.matrix(ergm_symmetrize(samplike, "lower"))),
sm[cbind(c(pmax(row(sm),col(sm))),c(pmin(row(sm),col(sm))))])))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.