rnetwork-programmingmodelstatnetblockdiag

issue running valued exponential random graph model (ergm) with block diagonal constraint


I am trying to run an exponential random graph model (ergm) on a weighted network (network_ex). This network shows the interactions between individuals in four different groups. Interactions between groups cannot occur so a blockdiagonal constraint needs to be included in the model. However when I include the blockdiagonal constraint the ergm function (that runs otherwise) returns an error (see below) and my R session either runs indefinitely or abort directly.

Is there a way to run an ergm based on a weighted block diagonal matrix?

# load necessary packages
library(ergm)
library(ergm.count)

# create a toy example network to illustrate the issue presented  
VEC=c(0,0,5,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,4,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,2,4,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,1,0,1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,1,2,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,2,0,0,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,4,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,4,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,2,2,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,6,2,4,4,2,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,1,5,0,1,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,1,0,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,2,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,2,0)
mat_ex=matrix(VEC,25,25)

nb=1:25
ID=rep("ID_",25)
names=paste0(ID,nb)
rownames(mat_ex)=names
colnames(mat_ex)=names

SeAg=c("F_Adult","F_Adult","M_Adult","M_Adult","M_Sub-Adult","F_Adult","M_Adult","F_Adult","M_Sub-Adult","M_Adult","F_Adult","M_Adult","M_Adult","M_Adult","F_Adult","F_Adult","F_Adult","F_Adult","F_Adult","M_Sub-Adult","M_Adult","M_Adult","M_Adult","F_Adult","M_Adult")
Group=c(1,1,1 ,1,1 ,2, 2, 2 ,2, 2, 2, 2, 3, 3, 3, 3, 3, 4 ,4 ,4, 4, 4, 4,4, 4)
network_ex=as.network(x = mat_ex,
                            directed = TRUE,
                            loops = FALSE,
                            matrix.type = "adjacency",
                            ignore.eval=FALSE,
                            names.eval='weight')
set.vertex.attribute(network_ex, "Sex_Age", as.character(SeAg))
set.vertex.attribute(network_ex, "Group", as.character(Group))

# run the ergm function with blockdiagonal constraint
ergm_ex <- ergm(network_ex~ 
                  sum
                +nodematch("Sex_Age",diff=TRUE,levels=c(1,2),form="sum")
                , response = 'weight'
                 , constraints = ~blockdiag("Group")
                , estimate = 'MLE'
                , reference = ~Poisson
                , control = control.ergm(MCMC.interval = 1000
                                         , MCMLE.maxit = 200
                                         , init.method = 'CD'
                                         , MCMC.samplesize = 1000
                                         , MCMC.prop.weights="random"
                                         , MCMC.burnin=100,seed=12345)
)

Starting contrastive divergence estimation via CD-MCMLE: Iteration 1 of at most 60:

Depending on VEC values I additionally get:

MH proposal function's initial network configuration is one from which no toggle(s) can be proposed


Solution

  • That does appear to be a bug. I've fixed it in the latest development version. These can be obtained by going to https://github.com/statnet/ergm and https://github.com/statnet/ergm.count and either using install_github() or downloading the binaries found in the README. Note, also that, the blockdiag() constraint has been provisionally moved to https://github.com/statnet/tergm .