Attribute specification problem in multiple layer networks using ergm.multi in R

58 views Asked by At

I try to run a multi-layered ERGM with the ergm.multi package in R with two layers. Before, I ran an ERGM for each layer, which all worked our perfectly. However, when trying to run the respective multi-layer ERGM, I get the error message concerning nodal attributes:

Error in `ergm_Init_abort()`:! In term ‘nodeifactor’ in package ‘ergm’ (called from term ‘L’ in package ‘ergm.multi’): ‘srh’ is/are not valid nodal attribute(s).

Following the statnet tutorial (https://statnet.org/workshop-advanced-ergm/), I specified my multi-layered network as follows:

hf2_A <- network1 | network2 # superset of all edges in any layer
# set attributes
hf2_A[,, names.eval="network1"] <- as.matrix(network1)
hf2_A[,, names.eval="network2"] <- as.matrix(network2)
hf2_A

hf_A <- Layer(hf2_A, c("network1","network2"))
hf_A

#A
set.vertex.attribute(hf_A, attrname = "pid", value = as.vector(network_names_A))
set.vertex.attribute(hf_A,  attrname = "sup", value = as.vector(sup_A))
set.vertex.attribute(hf_A,  attrname = "nas", value = as.vector(nas_A))
set.vertex.attribute(hf_A,  attrname = "age", value = as.vector(age_A))
set.vertex.attribute(hf_A,  attrname = "srh", value = as.vector(srh_A))
set.vertex.attribute(hf_A,  attrname = "casmin", value = as.vector(casmin_A))

hf_A looks then like this:

 Combined 2 networks on ‘.LayerID’/‘.LayerName’:
  1: n = 50, directed = TRUE, bipartite = FALSE, loops = FALSE
  2: n = 50, directed = TRUE, bipartite = FALSE, loops = FALSE

 Network attributes:
  vertices = 100 
  directed = TRUE 
  hyper = FALSE 
  loops = FALSE 
  multiple = FALSE 
  bipartite = FALSE 
  ergm:
            Length Class   Mode
constraints 2      formula call
  total edges= 247 
    missing edges= 0 
    non-missing edges= 247 

 Vertex attribute names: 
    .bipartite .LayerID .LayerName .undirected age casmin nas pid srh sup vertex.names 

 Edge attribute names: 
    network1 network2 

However, when running my multi-layered ERGM, I will still get the error message specified above.

m1 <- ergm(hf_A ~ L(~edges + mutual + gwidegree(decay=.1, fixed=TRUE) + gwodegree(decay=.1, fixed=TRUE) + gwesp(decay=.1, fixed=TRUE)
                         +edgecov(A_friend_w1)+edgecov(A_kin_w1)
                         +nodeifactor("srh")+nodeofactor("srh")+nodeifactor("nas")+nodeofactor("nas")+nodematch("srh")+nodematch("nas")
                         +nodematch("age")+nodematch("casmin")+nodefactor("age")+nodefactor("casmin"), ~network1) 
              + L(~edges + mutual + gwidegree(decay=.1, fixed=TRUE) + gwodegree(decay=.1, fixed=TRUE) + gwesp(decay=.1, fixed=TRUE)
                         +edgecov(A_health_w1)+edgecov(A_kin_w1)
                         +nodeifactor("srh")+nodeofactor("srh")+nodeifactor("nas")+nodeofactor("nas")+nodematch("srh")+nodematch("nas")
                         +nodematch("age")+nodematch("casmin")+nodefactor("age")+nodefactor("casmin"), ~network2)
)

Did anyone else encounter a similar problem? Or knows why I get the error message?

1

There are 1 answers

0
Michał On

Thanks @Amelie. This looks like a bug, follow up at Issue 27 on GitHub.