get_degree: Get Individual Degree from Network or Edgelist

View source: R/net.utils.R

get_degreeR Documentation

Get Individual Degree from Network or Edgelist

Description

A fast method for querying the current degree of all individuals within a network.

Usage

get_degree(x)

Arguments

x

Either an object of class network or edgelist generated from a network. If x is an edgelist, then it must contain an attribute for the total network size, n.

Details

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.

Value

A vector of length equal to the total network size, containing the current degree of each node in the network.

Examples

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)


statnet/EpiModel documentation built on March 30, 2024, 11:26 a.m.