get_degree | R Documentation |
A fast method for querying the current degree of all individuals within a network.
get_degree(x)
x |
Either an object of class |
Individual-level data on the current degree of nodes within a network is
often useful for summary statistics. Given a network
class object,
net
, one way to look up the current degree is to get a summary of the
ERGM term, sociality
, as in:
summary(net ~ sociality(nodes = NULL))
. But that is computationally
inefficient for a number of reasons. This function provides a fast method for
generating the vector of degrees using a query of the edgelist. It is even
faster if the parameter x
is already transformed into an edgelist.
A vector of length equal to the total network size, containing the current degree of each node in the network.
nw <- network_initialize(n = 500)
set.seed(1)
fit <- ergm(nw ~ edges, target.stats = 250)
sim <- simulate(fit)
# Slow ERGM-based method
ergm.method <- unname(summary(sim ~ sociality(nodes = NULL)))
ergm.method
# Fast tabulate method with network object
deg.net <- get_degree(sim)
deg.net
# Even faster if network already transformed into an edgelist
el <- as.edgelist(sim)
deg.el <- get_degree(el)
deg.el
identical(as.integer(ergm.method), deg.net, deg.el)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.