gofstatistics {btergm} | R Documentation |
Statistics for goodness-of-fit assessment of network models.
b1deg(mat, ...) b1star(mat, ...) b2deg(mat, ...) b2star(mat, ...) comemb(vec) deg(mat, ...) dsp(mat, ...) edgebetweenness.modularity(mat, ...) edgebetweenness.pr(sim, obs, ...) edgebetweenness.roc(sim, obs, ...) esp(mat, ...) fastgreedy.modularity(mat, ...) fastgreedy.pr(sim, obs, ...) fastgreedy.roc(sim, obs, ...) geodesic(mat, ...) ideg(mat, ...) istar(mat, ...) kcycle(mat, ...) kstar(mat, ...) louvain.modularity(mat, ...) louvain.pr(sim, obs, ...) louvain.roc(sim, obs, ...) maxmod.modularity(mat, ...) maxmod.pr(sim, obs, ...) maxmod.roc(sim, obs, ...) nsp(mat, ...) odeg(mat, ...) ostar(mat, ...) rocpr(sim, obs, roc = TRUE, pr = TRUE, joint = FALSE, pr.impute = "poly4", ...) spinglass.modularity(mat, ...) spinglass.pr(sim, obs, ...) spinglass.roc(sim, obs, ...) triad.directed(mat, ...) triad.undirected(mat, ...) walktrap.modularity(mat, ...) walktrap.pr(sim, obs, ...) walktrap.roc(sim, obs, ...)
vec |
A vector of community memberships in order to create a community co-membership matrix. |
mat |
A sparse network matrix as created by the |
sim |
A list of simulated networks. Each element in the list should be a sparse matrix as created by the |
obs |
A list of observed (= target) networks. Each element in the list should be a sparse matrix as created by the |
roc |
Compute receiver-operating characteristics (ROC)? |
pr |
Compute precision-recall curve (PR)? |
joint |
Merge all time steps into a single big prediction task and compute predictive fit (instead of computing GOF for all time steps separately)? |
pr.impute |
In some cases, the first precision value of the precision-recall curve is undefined. The |
... |
Additional arguments. This must be present in all auxiliary GOF statistics. |
These functions can be plugged into the statistics
argument of the gof
methods in order to compare observed with simulated networks (see the gof-methods help page). There are three types of statistics:
(1) Univariate statistics, which aggregate a network into a single quantity. For example, modularity measures or density. The distribution of statistics can be displayed using histograms, density plots, and median bars. Univariate statistics take a sparse matrix (mat
) as an argument and return a single numeric value that summarize a network matrix.
(2) Multivariate statistics, which aggregate a network into a vector of quantities. For example, the distribution of geodesic distances, edgewise shared partners, or indegree. These statistics typically have multiple values, e.g., esp(1), esp(2), esp(3) etc. The results can be displayed using multiple boxplots for simulated networks and a black curve for the observed network(s). Multivariate statistics take a sparse matrix (mat
) as an argument and return a vector of numeric values that summarize a network matrix.
(3) Tie prediction statistics, which predict dyad states the observed network(s) by the dyad states in the simulated networks. For example, receiver operating characteristics (ROC) or precision-recall curves (PR) of simulated networks based on the model, or ROC or PR predictions of community co-membership matrices of the simulated vs. the observed network(s). Tie prediction statistics take a list of simulated sparse network matrices and another list of observed sparse network matrices (possibly containing only a single sparse matrix) as arguments and return a rocpr
, roc
, or pr
object (as created by the rocpr function).
Users can create their own statistics for use with the codegof methods. To do so, one needs to write a function that accepts and returns the respective objects described in the enumeration above. It is advisable to look at the definitions of some of the existing functions to add custom functions. It is also possible to add an attribute called label
to the return object, which describes what is being returned by the function. This label will be used as a descriptive label in the plot and for verbose output during computations. The examples section contains an example of a custom user statistic. Note that all statistics _must_ contain the ...
argument to ensure that custom arguments of other statistics do not cause an error.
To aid the development of custom statistics, the helper function comemb
is available: it accepts a vector of community memberships and converts it to a co-membership matrix. This function is also used internally by statistics like walktrap.roc
and others.
The following built-in functions can be handed over to the statistics
argument. See the usage section for their respective arguments.
(1) Univariate statistics:
walktrap.modularity(mat, ...)
Modularity distribution as computed by the Walktrap algorithm.
fastgreedy.modularity(mat, ...)
Modularity distribution as computed by the fast and greedy algorithm. Only sensible with undirected networks.
louvain.modularity(mat, ...)
Modularity distribution as computed by the Louvain algorithm.
maxmod.modularity(mat, ...)
Optimal modularity distribution.
edgebetweenness.modularity(mat, ...)
Modularity distribution as computed by the Girvan-Newman edge betweenness community detection method.
spinglass.modularity(mat, ...)
Modularity distribution as computed by the Spinglass algorithm.
(2) Multivariate statistics:
dsp, ...
Dyad-wise shared partner distribution.
esp(mat, ...)
Edge-wise shared partner distribution.
nsp(mat, ...)
Non-edge-wise shared partner distribution.
deg(mat, ...)
Degree distribution (for undirected networks).
ideg(mat, ...)
Indegree distribution (for directed networks).
odeg(mat, ...)
Outdegree distribution (for directed networks).
b1deg(mat, ...)
Degree distribution (for the first mode in a two-mode network).
b2deg(mat, ...)
Degree distribution (for the second mode in a two-mode network).
kstar(mat, ...)
k-star distribution (for undirected networks).
istar(mat, ...)
in-star distribution (for directed networks).
ostar(mat, ...)
out-star distribution (for directed networks).
b1star(mat, ...)
k-star distribution (for the first mode in a two-mode network).
b2star(mat, ...)
k-star distribution (for the second mode in a two-mode network).
kcycle(mat, ...)
k-cycle distribution (for undirected networks).
geodesic(mat, ...)
Geodesic distance (or shortest path) distribution.
triad.directed(mat, ...)
Triad census (directed networks).
triad.undirected(mat, ...)
Triad census (undirected networks).
(3) Tie prediction statistics:
walktrap.roc(sim, obs, ...)
Receiver-operating characteristics of predicting the community structure in the observed network(s) by the community structure in the simulated networks, as computed by the Walktrap algorithm.
walktrap.pr(sim, obs, ...)
Precision-recall curve for predicting the community structure in the observed network(s) by the community structure in the simulated networks, as computed by the Walktrap algorithm.
fastgreedy.roc(sim, obs, ...)
Receiver-operating characteristics of predicting the community structure in the observed network(s) by the community structure in the simulated networks, as computed by the fast and greedy algorithm. Only sensible with undirected networks.
fastgreedy.pr(sim, obs, ...)
Precision-recall curve for predicting the community structure in the observed network(s) by the community structure in the simulated networks, as computed by the fast and greedy algorithm. Only sensible with undirected networks.
louvain.roc(sim, obs, ...)
Receiver-operating characteristics of predicting the community structure in the observed network(s) by the community structure in the simulated networks, as computed by the Louvain algorithm.
louvain.pr(sim, obs, ...)
Precision-recall curve for predicting the community structure in the observed network(s) by the community structure in the simulated networks, as computed by the Louvain algorithm.
maxmod.roc(sim, obs, ...)
Receiver-operating characteristics of predicting the community structure in the observed network(s) by the community structure in the simulated networks, as computed by the modularity maximization algorithm.
maxmod.pr(sim, obs, ...)
Precision-recall curve for predicting the community structure in the observed network(s) by the community structure in the simulated networks, as computed by the modularity maximization algorithm.
edgebetweenness.roc(sim, obs, ...)
Receiver-operating characteristics of predicting the community structure in the observed network(s) by the community structure in the simulated networks, as computed by the Girvan-Newman edge betweenness community detection method.
edgebetweenness.pr(sim, obs, ...)
Precision-recall curve for predicting the community structure in the observed network(s) by the community structure in the simulated networks, as computed by the Girvan-Newman edge betweenness community detection method.
spinglass.roc(sim, obs, ...)
Receiver-operating characteristics of predicting the community structure in the observed network(s) by the community structure in the simulated networks, as computed by the Spinglass algorithm.
spinglass.pr(sim, obs, ...)
Precision-recall curve for predicting the community structure in the observed network(s) by the community structure in the simulated networks, as computed by the Spinglass algorithm.
rocpr(sim, obs, roc = TRUE, pr = TRUE, joint = FALSE, pr.impute = "poly4", ...)
Receiver-operating characteristics (ROC) and precision-recall curve (PR). Prediction of the dyad states of the observed network(s) by the dyad states of the simulated networks.
Philip Leifeld (https://www.philipleifeld.com)
Leifeld, Philip, Skyler J. Cranmer and Bruce A. Desmarais (2017): Temporal Exponential Random Graph Models with btergm: Estimation and Bootstrap Confidence Intervals. Journal of Statistical Software 83(6): 1-36. http://dx.doi.org/10.18637/jss.v083.i06.
btergm-package gof gof-methods
# To see how these statistics are used, look at the examples section of # ?"gof-methods". The following example illustrates how custom # statistics can be created. Suppose one is interested in the density # of a network. Then a univariate statistic can be created as follows. dens <- function(mat, ...) { # univariate: one argument mat <- as.matrix(mat) # sparse matrix -> normal matrix d <- sna::gden(mat) # compute the actual statistic attributes(d)$label <- "Density" # add a descriptive label return(d) # return the statistic } # Note that the '...' argument must be present in all statistics. # Now the statistic can be used in the statistics argument of one of # the gof methods. # For illustrative purposes, let us consider an existing statistic, the # indegree distribution, a multivariate statistic. It also accepts a # single argument. Note that the sparse matrix is converted to a # normal matrix object when it is used. First, statnet's summary # method is used to compute the statistic. Names are attached to the # resulting vector for the different indegree values. Then the vector # is returned. ideg <- function(mat, ...) { d <- summary(mat ~ idegree(0:(nrow(mat) - 1))) names(d) <- 0:(length(d) - 1) attributes(d)$label <- "Indegree" return(d) } # See the gofstatistics.R file in the package for more complex examples.