Learn R Programming

ergmito (version 0.3-1)

count_stats: Count Network Statistics

Description

This function is similar to what ergm::summary_formula does, but it provides a fast wrapper suited for matrix class objects (see benchmark in the examples).

Usage

count_stats(X, ...)

AVAILABLE_STATS()

# S3 method for formula count_stats(X, ...)

# S3 method for list count_stats(X, terms, attrs = NULL, ...)

Value

A matrix of size length(X) * length(terms) with the corresponding counts of statistics.

Arguments

X

List of square matrices. (networks)

...

Passed to the method.

terms

Character vector with the names of the statistics to calculate. Currently, the only available statistics are: 'paste(ergmito::AVAILABLE_STATS(), collapse="', '")'.

attrs

A list of vectors. This is used when term has a nodal attribute such as nodeicov(attrname="").

Examples

Run this code
# DGP 
set.seed(123199)
x <- rbernoulli(rep(5, 10))
ans0 <- count_stats(x, c("mutual", "edges"))

# Calculating using summary_formula
ans1 <- lapply(x, function(i) {
  ergm::summary_formula(i ~ mutual + edges)
})

ans1 <- do.call(rbind, ans1)

# Comparing
all.equal(unname(ans0), unname(ans1))

# count_stats is vectorized (and so faster)
bm <- benchmarkito(
  count_stats = count_stats(x, c("mutual", "edges")),
  lapply      = lapply(x, function(i) {
  ergm::summary_formula(i ~ mutual + edges)
}), times = 50
)

plot(bm)

Run the code above in your browser using DataLab