statnet / ergm.multi

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

Multi-Network Representation of Multi-Layer Networks Yields Inconsistent Results #31

Closed mschalberger closed 2 months ago

mschalberger commented 3 months ago

Description

I want to use the Networks() function to combine several multi-layer networks (specified with the Layer() function) to use network-specific terms (N()). However, it appears that the statistics calculated across layers do not match the statistics calculated over the whole network.

To reproduce

To illustrate this behaviour, I will use the New Guinea Highlands Tribes dataset. Three multilayer networks consisting of two layers (positive and negative) are combined into a multilayer network representation.

library(ergm.multi)
library(latentnet)
data(tribes, package = "latentnet")
Ltribes <- Layer(tribes, c(`+`="pos", `-`="neg"))
nets <- Networks(Ltribes,Ltribes,Ltribes)
summary(nets ~ edges + L(~edges, ~`+`) + L(~edges, ~`-`))

Issue

Each tribe data set consists of 58 edges (29 positive and 29 negative). The edges term is, as expected, the number of networks multiplied by the number of edges, giving 174. However, for the layer specific terms I still get 29 and 29 instead of 87 and 87.

krivit commented 3 months ago

Interesting. It looks like L() doesn't unpack the networks correctly, though in principle it should.

summary(nets ~ N(~edges) + N(~L(~edges, ~`+`)) + N(~L(~edges, ~`-`)))

produces the expected result. I'll look into it, but it would probably be easier to add a warning to layer logic helper functions when there is non-layer structure on top of them.

krivit commented 3 months ago

And thanks for the bug report!

krivit commented 2 months ago

Turns out that this can sometimes even crash R, so I am going to go ahead and make it an error to unpack things in the wrong order. If there is a use case for it, please open a ticket.