statnet / ergm.multi

Fit, Simulate and Diagnose Exponential-Family Models for Multiple or Multilayer Networks
Other
14 stars 1 forks source link

L() operator (and others) uses the vertex attributes from the first layer for submodel initialisation. #29

Closed krivit closed 2 months ago

krivit commented 2 months ago

In InitErgmTerm.L() (and elsewhere), submodel initialisation uses the first layer as the template network for calling ergm_model(). This means that if different layers' have different vertex (say, for nodecov()) or network attributes (say, for edgecov()), only that network's attributes will be used and others' will be ignored.

For example, here, which network is listed first determines whether the initialisation can find the vertex attribute:

library(ergm.multi)
data(florentine)

flomarriage %v% "a" <- letters[1:16] # Vertex attr. only on one layer.

z <- summary(Layer(m=flomarriage,b=flobusiness)~ L(~nodefactor("a"), ~m)) # Should work and works
z <- summary(Layer(m=flomarriage,b=flobusiness)~ L(~nodefactor("a"), ~b)) # Should fail but works
z <- summary(Layer(b=flobusiness,m=flomarriage)~ L(~nodefactor("a"), ~m)) # Should work but fails
#> Error in `ergm_Init_abort()`:
#> ! In term 'nodefactor' in package 'ergm' (called from term 'L' in package 'ergm.multi'): 'a' is/are not valid nodal attribute(s).
z <- summary(Layer(b=flobusiness,m=flomarriage)~ L(~nodefactor("a"), ~b)) # Should fail and fails
#> Error in `ergm_Init_abort()`:
#> ! In term 'nodefactor' in package 'ergm' (called from term 'L' in package 'ergm.multi'): 'a' is/are not valid nodal attribute(s).

Created on 2024-05-11 with reprex v2.1.0

krivit commented 2 months ago

As a stopgap, it should be possible to include a check in Layer() that will warn the user about such discrepancies.