Bayesian community detection for networks with covariates
Abstract
The increasing prevalence of network data in a vast variety of fields and the need to extract useful information out of them have spurred fast developments in related models and algorithms. Among the various learning tasks with network data, community detection, the discovery of node clusters or “communities,” has arguably received the most attention in the scientific community. In many real-world applications, the network data often come with additional information in the form of node or edge covariates that should ideally be leveraged for inference. In this paper, we add to a limited literature on community detection for networks with covariates by proposing a Bayesian stochastic block model with a covariate-dependent random partition prior. Under our prior, the covariates are explicitly expressed in specifying the prior distribution on the cluster membership. Our model has the flexibility of modeling uncertainties of all the parameter estimates including the community membership. Importantly, and unlike the majority of existing methods, our model has the ability to learn the number of the communities via posterior inference without having to assume it to be known. Our model can be applied to community detection in both dense and sparse networks, with both categorical and continuous covariates, and our MCMC algorithm is very efficient with good mixing properties. We demonstrate the superior performance of our model over existing models in a comprehensive simulation study and an application to two real datasets.
keywords:
, and
1 Introduction
The ubiquity of network data in modern science and engineering and the need to extract meaningful information out of them has spurred rapid developments in the models, theory, and algorithms for the inference of networks (Erdős and Rényi, 1959; Bickel and Chen, 2009; Wolfe and Olhede, 2013; Kolaczyk, 2009; Lovász, 2012; Kolaczyk et al., 2020). Among the specific learning tasks with network data, community detection, which aims to detect communities or clusters among nodes, has arguably received the most attention in the scientific community. Various models and algorithms have been developed for community detection in networks including modularity-based methods (Newman, 2006), spectral clustering algorithms (Luxburg, 2007; Rohe et al., 2011), stochastic block models (Holland et al., 1983; Karrer and Newman, 2011; Ball et al., 2011), optimization-based approaches via semidefinite programming (Amini and Levina, 2018), and various Bayesian models (Mørup and Schmidt, 2012; Amini et al., 2019), among others.
Besides the edge information of an observed network, there are often additional covariates or nodal information available in many real-world networks. These additional covariates should be ideally utilized when performing community detection. For example, in a Facebook network, one can obtain from an individual’s profile covariates including current city, workplace, hometown, education, and hobbies. Another example is the Weddell Sea trophic network, which describes the marine ecosystem of the Weddell Sea (Jacob et al., 2011). It is a predator-prey network that includes the average adult body mass for each of the species. If one were to only utilize the network information, it is hard to differentiate all the different feeding types. However, the body mass of each species shows a partial clustering by the group, as seen in Figure 1. Therefore, a better clustering should be achievable when both the network and covariates are incorporated.

Such network data have motivated an emerging line of work that aims to deal with community detection problems that leverage both the network and the exogenous covariates. A node-coupled SBM is proposed in Weng and Feng (2022) in which cluster information or the block matrix is uniquely encoded by the covariates. Another model from Zhang et al. (2019) specifies that the link probability between a pair of nodes is contributed additively by the block probability in an SBM and a similarity measure between the covariates of a pair of nodes. A similar class of block models is proposed in Sweet (2015) that also accommodates covariates in an additive way such that the link probability is influenced by both block membership and covariates. A covariate-assisted spectral clustering algorithm is proposed in Binkiewicz et al. (2017) and later modified for degree-corrected block models in Hu and Wang (2022). Categorical covariates on the actor level are included in the model in Tallberg (2004), and the block affiliation probabilities are modeled conditional on the covariates via a multinomial probit model. Another prominent method in the frequentist literature is due to Zhang et al. (2016) in which a joint community detection criterion is proposed using both the adjacency matrix of the network and the node features, and their algorithm weights the edges according to feature similarities. Recently, the interplay between network information and covariates is investigated in an optimization framework for community detection in sparse networks in Yan and Sarkar (2021). From a Bayesian perspective, there are a few papers that are closely related to our work. We introduce them in Section 2.1 and provide a detailed discussion of their connections to our work (and to each other).
We add to this literature by proposing a Bayesian community detection procedure in which the effects of the covariates are incorporated via a covariate-dependent random partition prior on the node labels of an SBM. The covariates are explicitly expressed and incorporated in the prior probability of generating clusters. One of the distinctive features of our models compared with the ones already proposed in the literature is that ours has the ability to learn the number of communities via posterior inference without having to assume it to be known. The proposed model has the flexibility of assessing uncertainties for all the model parameters through an efficient MCMC algorithm for posterior inference. Note that there are several works in the literature that have employed the idea of a random partition prior or Bayesian nonparametric models for modeling network or relational data. We discuss these comparisons in Section 2.1 after introducing our model.
Our model can be applied in both dense and sparse regimes. In a sparse regime, as one of our simulation studies shows, our model outperforms other state-of-the-art methods such as that of Yan and Sarkar (2021), whose primary goal was to deal with sparse network condition with covariates. We also apply our methods to networks that have covariates with relatively high-dimensions. Our extensive simulations demonstrate our overall superior performance over existing methods in networks with continuous or categorical features, even when those methods are given the true number of communities.
The remainder of our paper is organized as follows. Section 2 is devoted to our model description and MCMC algorithms. In Section 3, we carry out several simulation studies in various settings to demonstrate the utility of our proposed model and algorithms. We also apply our model to two data examples in Section 4. We conclude in Section 5 with possiblities for future work.
2 Prior, model, and MCMC algorithm
Consider an observed network on nodes represented by an adjacency matrix with indicating the presence of a link between nodes and , and otherwise. Assume in addition that we have some covariate information for each node . The covariate information associated with the node are often referred to as nodal information or node features of the network, and are frequently encountered in modern network data. We let denote all of the node covariates of a given network. Our goal is to perform network community detection by incorporating both the network structure and the nodal information. The key challenge is how to jointly model these two sources of information. Below we propose a Bayesian model that incorporates the nodal information in the prior probability of cluster membership within an SBM.
Let be a node membership vector and indicate the total number of clusters implied by . We do not assume to be known a priori. Let be the set of indices of nodes belonging to the cluster according to . For any subset and , let be a nonnegative function that measures the homogeneity of the covariates . That is, takes larger values when all of the with are more similar. One can think of as a potential cluster of nodes and as a measure of the quality of such cluster, with regards the nodal information
Inspired by Müller and Quintana (2010); Park and Dunson (2010); Müller et al. (2011), we consider the following covariate-dependent random partition model:
(1) |
The non-negative function is known as the cohesion function of the product partition probability model. In a random partition model based on the Dirichlet process, with baseline probability measure and concentration parameter , one has (Ferguson, 1973; Sethuraman, 1994).
Borrowing from Müller et al. (2011), we define based on an auxiliary probability model , where
(2) |
Note that the covariates are not random. The term measures the effect or contribution of the covariates on the prior probability of cluster . One can choose and as a conjugate pair to facilitate the analytic evaluation of . For the cohesion function, we adopt .
Combining equations (1) and (2), we have
(3) |
In this model, can be considered the center of the nodal covarites in cluster , and a measure of how far the covariates in cluster are from its center . The model then averages over all possible centers .
The distribution in (3) can be written as the marginal of
(4) |
where . One can use (4) to derive a Gibbs sampler for sampling the prior. To simplify the notation, we let
(5) |
for denote the number of clusters of and the clusters themselves. Let
(6) |
One can show that for ,
(7) |
where . This is equivalent to first drawing , and then drawing as follows:
(8) |
Example.
For continuous features, we can take
(9) |
where denotes the density of a normal distribution with mean and covariance matrix , evaluated at . Then, in (8) will be proportional to , which shows that if is the closest to among , then the inclusion of the covariate information increases the chance of assigning to cluster .
Example.
For categorical covariates, one can choose to be a multinomial distribution and to be a Dirichlet distribution. Suppose there are categorical features and the th feature has categories for . Then , where is the -th feature of node , and . Each collects parameters of multinomial vectors, that is, , where the coordinates are independent draws from . We have
(10) |
We usually take .
An alternative approach to sample from the prior is to perform Gibbs sampling on the marginalized distribution (3). This leads to the following updates. For each ,
(11) |
where and . This approach is, in particular, useful when and are conjugate so that is easy to compute.
With the priors thus defined, the network is assumed to follow a SBM, that is,
(12) |
where is the connectivity matrix of SBM, with representing the link probability between nodes in clusters and .
It is possible to obtain closed forms for the full conditional distributions of the unknown model parameters , and with appropriate choices of and , as demonstrated in Section 2.2. We note that since the prior random partition model (1) puts mass on all potential partitions of the nodes, the posterior distribution also puts mass on all such partitions; however, the posterior will be concentrated around certain partition(s), hence a posteriori, there is a most likely value of , the number of communities in . That is how the model learns the number of communities.
2.1 Comparison with literature
There are several works in the literature similar to our model that also use a Bayesian nonparametric approach for tasks related to node clustering.
A pioneering work in the area is that of Kemp et al. (2006). Motivated by the complex system of relations underlying semantic knowledge, Kemp et al. (2006) propose the infinite relational model (IRM) for discovering and clustering underlying structure in relational data sets. In this framework, the observed data are assumed from types (people, demographic features, answers to a personality test, etc.) and relationships (person likes person , feature causes answer , etc). The motivating example given in Kemp et al. (2006) is that of clustering people, represented by set , based on social predicates, represented by set . The observed data is the tensor whose entry determines whether persons and have social predicate type . The idea is to simultaneously cluster and so that the tensor is roughly constant within the resulting clusters. In modern language, the model proposed by Kemp et al. (2006) is the so-called tensor SBM (Kim et al., 2017; Wang and Zeng, 2019; Lei et al., 2020) but with a CRP prior on the labels of each dimension to allow for infinite clusters a priori. IRM was later explicitly adopted in Mørup and Schmidt (2012) for community detection in network data, as opposed to relational data. IRM is quite flexible and can, for example, be used to incorporate an attribute or feature taking finite values, by taking above to be the levels of that attribute. However, this attribute should be interpreted as an edge feature, and moreover, IRM needs to have observations on the connectivity of persons for all possible levels of this attribute. Adding each feature then requires increasing the dimension of the tensor by one, and demanding lots of observations which are not available in practice in network problems.
More recently, nonparametric Bayesian network models that accommodate nodal covariates have been considered, but mostly with the mixed membership SBM (MMSBM) framework of Airoldi et al. (2008). For example, Kim et al. (2012) introduced the nonparametric metadata dependent relational (NMDR) model, that essentially couples the MMSBM likelihood with node-covariate-dependent prior on cluster labels. More specifically, they assume latent community vectors that interact with node features to produce a score that determines how likely node belongs to community , a priori. They assume that are normal with mean and then translate these real-valued affinities to probabilities via a logistic-stick breaking process (Ren et al., 2011). The then determine the edge probabilities via where is the connectivity matrix.
Along the same lines, Zhao et al. (2017) extends the edge partition model (EPM) of Zhou (2015) to incorporate binary node features. The EPM has similarities to MMSBM with novel uses of a Bernoulli-Poisson likelihood coupled with a nonparametric partition model. More specifically, the latent Poisson component still follows a MMSBM decomposition with where are the soft community assignments and the connectivity matrix. Similar to Kim et al. (2012), the nodal covariate information is incorporated in constructing a prior on . The prior assumes to be drawn from a Gamma distribution with mean where is the th binary feature of node . Note that by introducing and , one can write , showing that essentially the same inner product interaction of feature and latent community vectors as in Kim et al. (2012) is used by Zhao et al. (2017).
As in Kim et al. (2012) and Zhao et al. (2017), our model also incorporates node features into the partition prior; however, we are modeling hard community assignments rather than soft assignment vectors, making the problem somewhat more challenging. More importantly, our approach allows for a more general dependence of the partition on the features via a kernel , compared to the simple inner product approach used in both Kim et al. (2012) and Zhao et al. (2017). Our approach is not limited to binary features and by incorporating more complexity into , we can potentially model more complex feature/community interactions in the prior.
The last closely related work that we discuss is that of Newman and Clauset (2016). They consider node features (metadata) that take values in a finite discrete set (say ). Similar to our work, the node metadata is used to influence the prior on the community assignements. In our notation, they assume where is a parameter matrix to be estimated form the data. Compared to the inner product model of Kim et al. (2012) and Zhao et al. (2017), this approach gives a more flexible model for the interaction of the communities and features. The drawback is that it is limited to discrete features and if is large, there is potential for over-fitting without further regularization of the matrix. Newman and Clauset (2016) use an EM algorithm to estimate the parameters, and they assume the number of communities to be known.
2.2 Gibbs sampler
We now derive a Gibbs sampler to sample from the complete posterior distribution of given and . The main challenge is deriving the updates for .
We sample from , , and through their full conditional distributions, which are given bellow, until reaching convergence, and then obtain a sample of adequate size of the posterior distribution for inference.
2.2.1 Initialization
We initialize the labels by drawing from a Chinese Restaurant Process (CRP),
A CRP can be seen as a special case of our prior without any covariates. This follows from (11) by setting . Once is initialized, all the other parameters can be initialized by the Gibbs updates derived below.
Note that initializing the chain by sampling from a CRP provides a random start without having to specify the number of the communities . In many algorithms, spectral clustering is often used to initialize . For a Bayesian model, this is not a natural choice. Moreover, it requires the knowledge or an estimate of .
2.2.2 Sampling
Let and for simplicity, define
(13) |
Note that implicitly depends on . We have
Here, is the th community of . We assume that has communities and let . The convention is that while when is nonempty. Similarly, . In the above, we assume that collects all possible and similarly for .
Fix and let be the th community of . We assume that has communities and by convention, let . To get the communities of from , we either update to for some , or update to , generating a new community. With the convention we use, we can compactly write both cases as for all .
For any , we obtain
(14) |
Letting
(15) |
we have .
Noting that is a constant in (14), and similarly for any term in
that does not have an index equal to , we obtain
(16) |
The product over runs up to since only is a variable while is a constant. This is because can take the new value but with takes values in , hence we do not need to sample at this stage.
Since , we have
Hence for ,
where is defined in (6). Thus, we can compactly write
(17) |
This is equivalent to the following. First draw and for , all independently. Then draw from
(18) |
For continuous features, we use (9) for and , and for categorical variables we use (10) in the above updates.
Remark.
Note that update (18) is where a potentially new community (labeled ) is created. This happens if the following conditions are met: (a) when sampling according to (18), we happen to pick , (b) , that is, the current number of communities is , and (c) currently is not assigned to a singlton community. In such a case, the number of communities will increase from to . On the other hand, update (18) can also annihilate a community if the following holds: (a) When sampling , we pick and (b) which means that is currently assigned to a singleton community. In this case, the new number of communities will go from to .
2.2.3 Sampling
We have
where is the distribution with density
(19) |
That is, are independent draws from . We recall that .
The details of sampling are slightly different given different choices of and depending on whether continuous or categorical features are available. For continuous features with the Gaussian choice (9), which gives
For the categorical features with the choice (10), we have
where . That is, is the product of Dirichlet distributions,
2.2.4 Sampling
Let us define the index sets
(20) |
and block counts
(21) |
Then, we have
Thus, are independent draws from .
Remark (Directed networks).
Although our current MCMC algorithm is only for undirected networks, our prior can be used for Bayesian community detection in directed networks with covariates. One can simply replace the undirected SBM likelihood in (12) with a directed SBM, by replacing with and removing the symmetry constraint on . The resulting sampler will be almost identical, except for minor modifications to the counts (15) and (21) to account for the extra edge information.
3 Simulation study
In this section, we carry out multiple simulation studies in which we compare our methods, which we refer to as BCDC (Bayesian community detection for networks with covariates), with i) the covariate-assisted spectral clustering (CASC) algorithm (Binkiewicz et al., 2017), which uses both the network and the covariates information in a spectral clustering algorithm, ii) the covariated-assisted clustering on ratios of singular vectors (CASCORE) algorithm (Hu and Wang, 2022), which modfies CASC for degree heterogeneity, iii) -means algorithms (-means) applied only to the covariates, iv) spectral-clustering (SC) of the adjacency matrix, and v) a Bayesian SBM (BSBM), which is essentially a special case of our model with , therefore utilizing only the network information. For CASC, the core idea is to first construct a new Laplacian matrix , where is the Laplacian matrix for the network and denotes the by feature matrix, and then apply the standard spectral clustering algorithm on . Throughout, we select based on the automated procedure given in (Binkiewicz et al., 2017, Section 2.3).
We consider simulation designs with (a) continuous features, (b) discrete or categorical features, (c) a mix of continuous and discrete covariates, (d) high-dimensional features, and (e) homophily effects with networks simulated from stochastic block models with varying connectivity patterns and sparsity levels. The performance of the estimated communities is measured by normalized mutual information (NMI), a measure ranging from 0 (random guessing) to 1 (perfect agreement). NMI is a measure of similarity of two partitions, and is widely used in the community detection literature. It allows comparisons of two partitions with different number of clusters while accounting for the issue of label invariance.
To define NMI, consider two partitions (labelings) on a set of objects and let be the two labels of a randomly drawn object. The joint probability distribution of is the normalized confusion matrix between the two partitions. We can define the mutual information and joint and marginal entropies—, and —based on the aforementioned joint distribution, using standard definitions. It is common to define NMI as . However, there are other variants and to be consistent with prior work, in particular Yan and Sarkar (2021), we will use the variant implemented in the R package NMI, namely, , which is also referred to as symmetric uncertainty (Teukolsky et al. (1992, p. 634); Hall (1998)).
Overall, the simulation studies show that our method consistently outperforms the competitors and demonstrates the gain of our model by utilizing both the network and nodal information for detecting the community structures. The simulations were performed on a high-computing cluster. An R package for our samplers, as well as the code for these experiments, is available at the GitHub repository aaamini/bcdc (Shen et al., 2022). We ran our code on a high-performance cluster with an Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz with 28 cores and 256 GB RAM.
3.1 Continuous covariates
We first consider simulated networks with continuous covariates, and in particular, the Gaussian setting (9). We generate networks from an SBM having connectivity matrix with
(22) |
The parameter controls the magnitude of disparity between the within and between connectivites and is a measure of network information for the community structure. In our simulations, we set and vary . We consider nodes with communities of 100 and 50 nodes, respectively.
For each node, we generate features, with one signal feature related to the community structure and one noise feature whose distribution is the same for all nodes. Letting be the feature vector for node and , we take
where , and is the community label of node . Here is proportional to the signal-to-noise ratio of the covariate information.
Figure 2 shows the mean NMI with a 50% quantile band from BCDC and competing methods, averaged over 500 replications, under different settings of and . For BCDC, we have used parameters , and , and ran the sampler for 1000 iterations. Note that in our comparison, all of the competing methods were given an additional advantage by assuming the knowledge of the true number of communities. However, our method (red) consistently outperforms these other methods. An interesting notable case is that of high network information () and pure noise covariate information (). In this case, BCDC performs as well as BSBM which only operates on network information, while CASC performs much worse being misled by pure noise covariates.




3.2 Categorical covariates
We next consider a simulation study for networks with categorical covariates. For each node , we again generate features with one signal feature related to the community structure and one noise feature whose distribution is the same for all nodes. We consider two designs:
-
(0)
We consider networks with nodes and equally-sized communities. The signal features are taken to be the true community labels and the noise features are uniformly distributed on .
-
(0)
We consider networks with nodes and communities of 100 and 50 nodes. We create two 4-category features. Let be the feature vector for node . We use the following generative model
where, for example, means that is a categorical variable with probability vector .
In both cases, we use an SBM with connectivity (22), setting and varying from 0.1 to 0.8. For the parameters of our model, we again set , and ran the chain for 1,500 iterations. As above, the results are given over 500 replicates.
Figure 3 shows NMI as a function of (the network information measure) under the two covariate designs. Once again, all methods except BCDC were given the true number of communities. The NMI values obtained under the proposed model are generally higher than those of the other models with a slightly larger variance, which is likely due to the additional uncertainty in estimating the number of the communities.


3.3 Mix of continuous and discrete covariates
Here, we perform a simulation for larger networks with more communities and a mix of continuous and categorical variables. We let the number of nodes vary from 300 to 1000 and set communities. The features are chosen so that neither perfectly separates the clusters, but both are informative. In particular, we take
i.e. for and for . We also take for and for . As before, we use an SBM with connectivity (22), setting and .
The results are shown in Figure 4. We find that BCDC is competitive with the other methods when , but is superior for larger networks with . We also show in Figure 4 the run time for each method. We see that BCDC scales linearly with and is faster than CASC for all of the networks.


3.4 Sparse networks and high-dimensional features
We next consider a setting from Yan and Sarkar (2021), who proposed a covariate-regularized procedure for community detection in sparse graphs. This allows us to explore whether our model works for sparse networks, as well as networks with high-dimensional features. We consider the exact simulation setting as in Yan and Sarkar (2021), in which the networks are generated from a 3-block SBM on 800 nodes with block-size ratios . The true connectivity matrix is
leading to a very sparse network, with expected average degree . The covariates are generated from 100-dimensional Gaussian distributions , with centers that are only non-zero on the first two dimensions:
In this setting, it is difficult to distinguish clusters 1 and 2 using the network information alone, and clusters 2 and 3 based on nodal covariates alone.
This experiment was repeated 100 times for independently generated samples. In each replicate, we ran the chain for 1,000 iterations. The results are shown in Figure 5. Note that our method consistently achieves a better NMI than all of the other methods. Although we did not carry out a direct comparison with the method from Yan and Sarkar (2021) since their work focuses on regularizing high-dimensional features, our NMI results are stable and seem to be higher than those reported in Yan and Sarkar (2021). Importantly, we also see in Figure 5 that BCDC is only slightly slower than all of the methods that use only the network or only the covariates, but is considerably faster than CASC and CASCORE, which also use both the network and the nodal information. This illustrates the disadvantage of CASC for larger sparse networks and highlights the efficiency of our MCMC algorithm. That CASC slows down for larger networks can be attributed to the addition of the dense to the sparse Laplacian , resulting in an overall dense similarity matrix .


3.5 Homophily
Finally, we consider a network model with homophily, which is the tendency for nodes to be connected when they share a nodal feature. For this, we sample a categorical covariate with two levels, and let
where is an SBM with connectivity (22), setting and . This creates communities, and separates the effect of community structure from the effect of node-level covariates. We take and vary in . Note that when , we say the nodes exhibit positive homophily. We run this for and .


The results are show in Figure 6. We find that BCDC has superior performance to the other methods even when they are provided the true number () of communities. The performance increases as the homophily effect increases in magnitude, which we should expect because the homophily effect is an informative covariate that is not included with BSBM.
4 Real data analysis
In this section, we apply our model to the same two datasets from Yan and Sarkar (2021), a network representing Mexican political elites and a network representing the Weddell Sea ecosystem. We compare our the results from our models against several methods that use only the network, only the covariates, and both the network and covariates.
4.1 Performance measures
In addition to computing the NMI with the (alleged) ground truth labels, it is also helpful to compare the performance using the Bayesian information criterion (BIC) based on an SBM likelihood conditional on the labels. This is especially important because, unlike in the simulations, the “true” clusters are exogenously specified. The (conditional) BIC is defined as the log-marginal likelihood muliplied by . That is,
(23) | ||||
(24) |
where is the number of communities in , is the degrees of freedom in the parameters , is the label prior, and is the maximum likelihood estimator of those parameters, i.e., the maximizer of . We assume a uniform prior over and . Note that (24) is the well-known approximation to the BIC (Schwarz, 1978; Konishi and Kitagawa, 2008) and it shows the usefulness of as a measure of performance for real networks: Due to the presence of the complexity term , we get a good balance of the model fit and the number of communities. Label vectors with smaller are thus more desirable from a block modeling standpoint, regardless of their relation to the ground truth.
We have
where , and and are as in (21). Hence, the exact BIC in our setting is
where and is the multivariate Beta function.
4.2 Mexican Political Elites
The first dataset we consider involves Mexican political elites (Gil-Mendieta and Schmidt, 1996). In this network, the vertices represent Mexican presidents and their close collaborators, and the 117 edges represent significant political, kinship, friendship, or business ties among them. The ground truth is a classification of the politicians according to their professional background: military and civilians. The covariate we include is the number of years since 1990 that the actor first got a significant governmental position. Figure 7 reveals that this covariate has some discriminatory power in the cluster labels. This is due to the fact that after the Mexican revolution at the beginning of the twentieth century, the political elite was dominated by the military, and later the civilians gradually succeeded the power.

Table 1 contains the NMI results of our method compared with the same comparison methods in the simulation section. We see that our method achieves the best results, and we visualize our estimated clusters in the network compared with the true labels in Figure 8. Again, for the other methods, we assume the knowledge of the true number of clusters while ours learns the number of the clusters via posterior inference for NMI comparisons.


As already pointed out in Yan and Sarkar (2021), node 35 has exactly one connection to each of the military and civilian groups, but obtained a governmental position in the 90s, which greatly hinted at a civilian background. By using the covariate, our method accurately captures this label. On the other hand, node 9 seized power in 1940 when the government was almost equally represented by civilian and military politicians, which makes detecting his group difficult, but has more edges to the military group than the civilian group. In this case, our method correctly assigns the military label to it by considering the graph structure.
Dataset | bcdc | casc | cascore | -means | sc | bsbm |
---|---|---|---|---|---|---|
Mexican politicians | 0.43 | 0.37 | 0.28 | 0.26 | 0.37 | 0.10 |
Weddell Sea | 0.44 | 0.25 | 0.15 | 0.35 | 0.33 | 0.23 |
We also notice that node 1 has five connections to the military and only one connection to the civilian, and node 1 seized power in 1911. Similarly for node 7, which has five connections to the military and three connections to the civilian and seized power in 1928. For these nodes, both the network and the covariates strongly indicate a closer relationship to the military, which is what our method assigns despite the true label showing civilian. Finally, our method assigns node 12 to its own cluster. This is likely because this is the highest-degree node with 5 military connections and 12 civilian connections. However, in researching node 12, we discovered that Miguel Alemán Valdés was the first civilian president after several military presidents, which suggests that there may have been a labeling error in the original publication of this dataset from Gil-Mendieta and Schmidt (1996). This could explain why our method has the best BIC, even better than the “true” labels, in Table 2.
Dataset | “true” | bcdc | casc | cascore | -means | sc | bsbm |
---|---|---|---|---|---|---|---|
Mexican politicians | 636 | 586 | 587 | 607 | 626 | 587 | 598 |
Weddell Sea | 138k | 33k | 124k | 119k | 144k | 100k | 71k |
4.3 Weddell Sea Ecosystem
The second dataset we consider is a predator-prey, directed network representing the marine food web of the Weddell Sea off of the Antarctic Peninsula, which was collected by Jacob et al. (2011). Since ecosystems are complex, interconnected environments, network analyses have emerged as a popular technique for untangling these connections. The Weddell Sea network has 487 nodes that signify different marine species, and there is a link between nodes and if species (predator) feeds on species (prey). Following Yan and Sarkar (2021), we construct a binary, undirected network from this directed network in which if there are at least 5 common prey between species and , and otherwise. The network is shown in Figure 9.


In Jacob et al. (2011), the authors analyze the relationship between the body size of each species and its feeding type: primary producer, herbivorous/detrivorous, detrivorous, carnivorous, carnivorous/necrovorous, and omnivorous. Figure 1 shows these body sizes grouped by feeding type, where, again following Yan and Sarkar (2021), we group detrivorous, carnivorous, carnivorous/necrovorous as “Carnivore” to obtain four groups. The adjacency matrix in Figure 9 (left) is also sorted by these groups. The authors of Jacob et al. (2011) found body size to be positively correlated with trophic level, but noted that “predators on intermediate trophic levels do not necessarily feed on smaller or prey similar in size but depending on their foraging strategy have a wider prey size range available.” Therefore, body size is insufficient on its own to distinguish the groups, and it would be preferable to consider the interconnectedness of the food web when tasked with clustering the species.
Table 1 shows that BCDC provides the best clustering results compared to the other methods. Therefore, using all of the available information provides an improvement in clustering accuracy over the use of just the network structure or the nodal information. As before, BCDC is the only method that did not know that there are four “true” groups. Interestingly, BCDC estimates many more clusters – 21 in total – which may explain its higher NMI, since we see qualitatively in Figure 9 (right) a more refined block structure. This is quantified and corroborated through BIC in Table 2, which again shows our method outperforms even the “true” clusters. All of this suggests there may be distinct sub-blocks within the Herbivore, Carnivore, and Omnivore classes.
5 Discussion
In this work, we proposed a Bayesian model for community detection in networks with covariates in which both the network and node features of the network are jointly utilized for estimating community structure. In particular, the contribution of nodal information is explicitly modeled in the prior distribution for the community labels via a covariate-dependent random partition prior. We proposed efficient MCMC algorithms for sampling the posterior distributions of all the parameters including the community labels and the number of the communities. Numerical studies demonstrated the overall superior performance of our model over many of the existing methods.
Compared to an almost exclusive literature of frequentist methods, our work is among the first in proposing a Bayesian approach for tackling the problem, which confers some notable advantages in terms of uncertainty quantification, as well as estimating all the model parameters. Notably, unlike the other methods in the literature, our model estimates the number of communities via posterior inference without any knowledge or prior information on the true number. Future work will be devoted to developing Bayesian models for community detection in degree-corrected SBMs and dynamic network models.
We can also easily extend our model to a partially-observed SBM in the spirit of Zhou (2015). Specifically, we can modify (12) to
where is a (symmetric) observation mask, with for the observed edges. This only effects sampling and through the modified counts
replacing (15), and
replacing (21). This allows our model to also predict missing edges.
Finally, it may be of interest to test whether there is an association between the node covariates and inferred community structure. One approach to this is with Bayes factors comparing models with and without covariates, using, for example, the approach in Legramanti et al. (2020) for testing partition structures in SBMs. While this is a principled Bayesian approach, it only tests whether the set of covariates provides a more parsimonious clustering than without the covariates rather than identifying which covariates are significant. One idea for testing individual covariate significance is to test for a difference between the posterior distributions of the cluster centers implied by . Note that this corresponds to testing whether the priors on auxiliary probability distributions have overlapping variances, but we leave a rigorous treatment of this idea to future work.
References
- Airoldi et al. (2008) Airoldi, E. M., Blei, D., Fienberg, S., and Xing, E. (2008). “Mixed membership stochastic blockmodels.” Advances in neural information processing systems, 21.
-
Amini and Levina (2018)
Amini, A. A. and Levina, E. (2018).
“On semidefinite relaxations for the block model.”
The Annals of Statistics, 46(1): 149 – 179.
URL https://doi.org/10.1214/17-AOS1545 - Amini et al. (2019) Amini, A. A., Paez, M. S., and Lin, L. (2019). “Hierarchical Stochastic Block Model for Community Detection in Multiplex Networks.” arXiv e-prints, arXiv:1904.05330.
- Ball et al. (2011) Ball, B., Karrer, B., and Newman, M. (2011). “Efficient and principled method for detecting communities in networks.” Physical Review E, 84(3): 036103.
- Bickel and Chen (2009) Bickel, P. J. and Chen, A. (2009). “A nonparametric view of network models and Newman Girvan and other modularities.” Proceedings of the National Academy of Sciences of the Unites States of America, 106(50): 21068–21073.
- Binkiewicz et al. (2017) Binkiewicz, N., Vogelstein, J. T., and Rohe, K. (2017). “Covariate-assisted spectral clustering.” Biometrika, 104(2): 361–377.
- Erdős and Rényi (1959) Erdős, P. and Rényi, A. (1959). “On Random Graphs I.” Publicationes Mathematicae (Debrecen), 6: 290–297.
- Ferguson (1973) Ferguson, T. S. (1973). “A Bayesian analysis of some nonparametric problems.” The annals of statistics, 209–230.
- Gil-Mendieta and Schmidt (1996) Gil-Mendieta, J. and Schmidt, S. (1996). “The political network in Mexico.” Social Networks, 18(4): 355–381.
- Hall (1998) Hall, M. A. (1998). “Correlation-based feature subset selection for machine learning.” Thesis submitted in partial fulfillment of the requirements of the degree of Doctor of Philosophy at the University of Waikato.
- Holland et al. (1983) Holland, P. W., Laskey, K. B., and Leinhardt, S. (1983). “Stochastic blockmodels: First steps.” Social networks, 5(2): 109–137.
-
Hu and Wang (2022)
Hu, Y. and Wang, W. (2022).
“Covariate-Assisted Community Detection on Sparse Networks.”
arXiv.
URL https://arxiv.org/abs/2208.00257 - Jacob et al. (2011) Jacob, U., Thierry, A., Brose, U., Arntz, W. E., Berg, S., Brey, T., Fetzer, I., Jonsson, T., Mintenbeck, K., Möllmann, C., et al. (2011). “The role of body size in complex food webs: A cold case.” Advances in ecological research, 45: 181–223.
-
Karrer and Newman (2011)
Karrer, B. and Newman, M. E. J. (2011).
“Stochastic blockmodels and community structure in networks.”
Phys. Rev. E, 83: 016107.
URL http://link.aps.org/doi/10.1103/PhysRevE.83.016107 - Kemp et al. (2006) Kemp, C., Tenenbaum, J. B., Griffiths, T. L., Yamada, T., and Ueda, N. (2006). “Learning Systems of Concepts with an Infinite Relational Model.” In Proceedings of the 21st National Conference on Artificial Intelligence - Volume 1, AAAI’06, 381–388. AAAI Press.
- Kim et al. (2017) Kim, C., Bandeira, A. S., and Goemans, M. X. (2017). “Community detection in hypergraphs, spiked tensor models, and sum-of-squares.” In 2017 International Conference on Sampling Theory and Applications (SampTA), 124–128. IEEE.
-
Kim et al. (2012)
Kim, D. I., Hughes, M. C., and Sudderth, E. B. (2012).
“The Nonparametric Metadata Dependent Relational Model.”
In Proceedings of the 29th International Conference on Machine
Learning, ICML 2012, Edinburgh, Scotland, UK, June 26 - July 1, 2012.
icml.cc / Omnipress.
URL http://icml.cc/2012/papers/771.pdf - Kolaczyk (2009) Kolaczyk, E. (2009). Statistical Analysis of Network Data: Methods and Models. Springer Verlag.
-
Kolaczyk et al. (2020)
Kolaczyk, E. D., Lin, L., Rosenberg, S., Walters, J., and Xu, J. (2020).
“Averages of unlabeled networks: Geometric characterization
and asymptotic behavior.”
The Annals of Statistics, 48(1): 514 – 538.
URL https://doi.org/10.1214/19-AOS1820 - Konishi and Kitagawa (2008) Konishi, S. and Kitagawa, G. (2008). “Information criteria and statistical modeling.”
- Legramanti et al. (2020) Legramanti, S., Rigon, T., and Durante, D. (2020). “Bayesian testing for exogenous partition structures in stochastic block models.” Sankhya A, 1–19.
- Lei et al. (2020) Lei, J., Chen, K., and Lynch, B. (2020). “Consistent community detection in multi-layer network data.” Biometrika, 107(1): 61–73.
- Lovász (2012) Lovász, L. (2012). Large Networks and Graph Limits, volume 60. American Mathematical Society Providence.
- Luxburg (2007) Luxburg, U. V. (2007). “A tutorial on spectral clustering.” Statistics and Computing, 17(4): 395–416.
-
Mørup and Schmidt (2012)
Mørup, M. and Schmidt, M. N. (2012).
“Bayesian Community Detection.”
Neural Comput., 24(9): 2434–2456.
URL http://dx.doi.org/10.1162/NECO_a_00314 - Müller and Quintana (2010) Müller, P. and Quintana, F. (2010). “Random partition models with regression on covariates.” Journal of statistical planning and inference, 140(10): 2801–2808.
- Müller et al. (2011) Müller, P., Quintana, F., and Rosner, G. L. (2011). “A product partition model with regression on covariates.” Journal of Computational and Graphical Statistics, 20(1): 260–278.
- Newman and Clauset (2016) Newman, M. E. and Clauset, A. (2016). “Structure and inference in annotated networks.” Nature communications, 7(1): 1–11.
-
Newman (2006)
Newman, M. E. J. (2006).
“Modularity and community structure in networks.”
Proceedings of the National Academy of Sciences, 103(23):
8577–8582.
URL http://www.pnas.org/content/103/23/8577.abstract - Park and Dunson (2010) Park, J.-H. and Dunson, D. B. (2010). “Bayesian generalized product partition model.” Statistica Sinica, 1203–1226.
- Ren et al. (2011) Ren, L., Du, L., Carin, L., and Dunson, D. (2011). “Logistic Stick-Breaking Process.” J. Mach. Learn. Res., 12(null): 203–239.
- Rohe et al. (2011) Rohe, K., Chatterjee, S., and Yu, B. (2011). “Spectral clustering and the high-dimensional stochastic block model.” Annals of Statistics, 39: 1878–1915.
- Schwarz (1978) Schwarz, G. (1978). “Estimating the dimension of a model.” The annals of statistics, 461–464.
- Sethuraman (1994) Sethuraman, J. (1994). “A CONSTRUCTIVE DEFINITION OF DIRICHLET PRIORS.” Statistica Sinica, 4(2): 639–650.
- Shen et al. (2022) Shen, L., Amini, A. A., Josephs, N., and Lin, L. (2022). “BCDC model for community detection with node covariates.” https://github.com/aaamini/bcdc.
-
Sweet (2015)
Sweet, T. M. (2015).
“Incorporating Covariates Into Stochastic Blockmodels.”
Journal of Educational and Behavioral Statistics, 40(6):
635–664.
URL https://ideas.repec.org/a/sae/jedbes/v40y2015i6p635-664.html -
Tallberg (2004)
Tallberg, C. (2004).
“A Bayesian Approach to Modeling Stochastic Blockstructures
with Covariates.”
The Journal of Mathematical Sociology, 29(1): 1–23.
URL https://doi.org/10.1080/00222500590889703 - Teukolsky et al. (1992) Teukolsky, S. A., Flannery, B. P., Press, W., and Vetterling, W. (1992). “Numerical recipes in C.” SMR, 693(1): 59–70.
- Wang and Zeng (2019) Wang, M. and Zeng, Y. (2019). “Multiway clustering via tensor block models.” Advances in neural information processing systems, 32.
- Weng and Feng (2022) Weng, H. and Feng, Y. (2022). “Community detection with nodal information: Likelihood and its variational approximation.” Stat, 11.
- Wolfe and Olhede (2013) Wolfe, P. J. and Olhede, S. C. (2013). “Nonparametric graphon estimation.” ArXiv e-prints.
-
Yan and Sarkar (2021)
Yan, B. and Sarkar, P. (2021).
“Covariate Regularized Community Detection in Sparse Graphs.”
Journal of the American Statistical Association, 116(534):
734–745.
URL https://doi.org/10.1080/01621459.2019.1706541 -
Zhang et al. (2019)
Zhang, Y., Chen, K., Sampson, A., Hwang, K., and Luna, B. (2019).
“covariate Adjusted Stochastic Block Model.”
Journal of Computational and Graphical Statistics, 28(2):
362–373.
URL https://doi.org/10.1080/10618600.2018.1530117 - Zhang et al. (2016) Zhang, Y., Levina, E., Zhu, J., et al. (2016). “Community detection in networks with node features.” Electronic Journal of Statistics, 10(2): 3153–3178.
-
Zhao et al. (2017)
Zhao, H., Du, L., and Buntine, W. (2017).
“Leveraging Node Attributes for Incomplete Relational Data.”
In Precup, D. and Teh, Y. W. (eds.), Proceedings of the 34th
International Conference on Machine Learning, volume 70 of Proceedings of Machine Learning Research, 4072–4081. PMLR.
URL https://proceedings.mlr.press/v70/zhao17a.html - Zhou (2015) Zhou, M. (2015). “Infinite edge partition models for overlapping community detection and link prediction.” In Artificial intelligence and statistics, 1135–1143. PMLR.
[Acknowledgments] We are very grateful to the Editor, the Associate Editor and two reviewers for their valuable comments. LS and LL were supported by NSF grants DMS 2113642 and DMS 1654579. AA would like to acknowledge the support of NSF grant DMS-1945667. NJ was partially supported by NIH/NICHD grant 1DP2HD091799-01.