我正在尝试在加权网络(network_ex)上运行指数随机图模型(ergm)。该网络显示了四个不同组中的个人之间的交互。组之间不能发生交互,因此需要在模型中包含块对角约束。但是,当我包含块对角线约束时,ergm 函数(否则运行)返回错误(见下文),我的 R 会话要么无限期运行,要么直接中止。
有没有办法基于加权块对角矩阵运行 ergm?
# 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)
)
通过 CD-MCMLE 开始对比散度估计:迭代 1,最多 60 次:
根据 VEC 值,我还得到:
MH 提议功能的初始网络配置是不能提议任何切换的网络配置