count_stats {ergmito} | R Documentation |
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 class 'formula'
count_stats(X, ...)
## S3 method for class 'list'
count_stats(X, terms, attrs = NULL, ...)
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: 'mutual', 'edges', 'ttriad', 'ctriad', 'ctriple', 'nodeicov', 'nodeocov', 'nodematch', 'triangle', 'balance', 't300', 't102', 'absdiff', 'idegree1.5', 'odegree1.5', 'ostar1', 'ostar2', 'ostar3', 'ostar4', 'istar1', 'istar2', 'istar3', 'istar4'. |
attrs |
A list of vectors. This is used when |
Value
A matrix of size length(X) * length(terms)
with the corresponding
counts of statistics.
Examples
# 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)
[Package ergmito version 0.3-1 Index]