  Many popular models from the networks literature can be viewed through a
common lens of contingency tables on network dyads, resulting in
\emph{log-linear ERGMs}: exponential family models for random graphs whose
sufficient statistics are linear on the dyads. We propose a new model in this
family, the \emph{$p_1$-SBM}, which combines node and group effects common in
network formation mechanisms. In particular, it is a generalization of several
well-known ERGMs including the stochastic blockmodel for undirected graphs, the
degree-corrected version of it, and the directed $p_1$ model without group
structure.
  We frame the problem of testing model fit for the log-linear ERGM class
through an exact conditional test whose $p$-value can be approximated
efficiently in networks of both small and moderately large sizes. The sampling
methods we build rely on a dynamic adaptation of Markov bases. We use quick
estimation algorithms adapted from the contingency table literature and
effective sampling methods rooted in graph theory and algebraic statistics. The
performance and scalability of the method is demonstrated on two data sets from
biology: the connectome of \emph{C. elegans} and the interactome of
\emph{Arabidopsis thaliana}. These two networks -- a neuronal network and a
protein-protein interaction network -- have been popular examples in the
network science literature. Our work provides a model-based approach to
studying them.

Methodology;Combinatorics;Applications