count_stats | R Documentation |
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).
count_stats(X, ...)
AVAILABLE_STATS()
## S3 method for class 'formula'
count_stats(X, ...)
## S3 method for class 'list'
count_stats(X, terms, attrs = NULL, ...)
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: '\Sexpr{paste(ergmito::AVAILABLE_STATS(), collapse="', '")}'. |
attrs |
A list of vectors. This is used when |
A matrix of size length(X) * length(terms)
with the corresponding
counts of statistics.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.