问题 运行 具有块对角线约束的值指数随机图模型 (ergm)
issue running valued exponential random graph model (ergm) with block diagonal constraint
我正在尝试 运行 加权网络 (network_ex) 上的指数随机图模型 (ergm)。该网络显示了四个不同群体中个体之间的相互作用。组之间的相互作用不会发生,因此模型中需要包含块对角线约束。但是,当我包含 blockdiagonal 约束时,ergm 函数(否则 运行s)returns 错误(见下文)并且我的 R 会话无限期地 运行s 或直接中止。
有没有办法 运行 基于加权块对角矩阵的 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)
)
Starting contrastive divergence estimation via CD-MCMLE:
Iteration 1 of at most 60:
根据 VEC 值,我还得到:
MH proposal function's initial network configuration is one from which no toggle(s) can be proposed
这似乎是一个错误。我已经在最新的开发版本中修复了它。这些可以通过 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 .
获得
我正在尝试 运行 加权网络 (network_ex) 上的指数随机图模型 (ergm)。该网络显示了四个不同群体中个体之间的相互作用。组之间的相互作用不会发生,因此模型中需要包含块对角线约束。但是,当我包含 blockdiagonal 约束时,ergm 函数(否则 运行s)returns 错误(见下文)并且我的 R 会话无限期地 运行s 或直接中止。
有没有办法 运行 基于加权块对角矩阵的 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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_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:
根据 VEC 值,我还得到:
MH proposal function's initial network configuration is one from which no toggle(s) can be proposed
这似乎是一个错误。我已经在最新的开发版本中修复了它。这些可以通过 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 .
获得