Skip to content

Inconsistent behaviour in network.list() with simulate(..., simplify = FALSE), paticularly for print() methods. #610

@krivit

Description

@krivit
library(ergm)
data(faux.desert.high)
s <- simulate(faux.desert.high ~ mm("sex"), coef = c(-3.486, -3.278, -3.361), nsim = 2, simplify = FALSE)
str(s)
#> List of 1
#>  $ :List of 2
#>   .. .. .. .. [networks]
#>   .. .. .. .. [list output truncated]
#>   .. .. ..- attr(*, "class")= chr "network"
#>  - attr(*, "constraints")=List of 2
#>   ..$ :Class 'formula'  language ~.
#>   .. .. ..- attr(*, ".Environment")=<environment: 0x55fadfc0d000> 
#>   ..$ :Class 'formula'  language ~.
#>   .. .. ..- attr(*, ".Environment")=<environment: 0x55fadfc0d000> 
#>  - attr(*, "reference")=Class 'formula'  language ~Bernoulli
#>   .. ..- attr(*, ".Environment")=<environment: 0x55fadfc0d000>
print(s)
#> Number of Networks: 1 
#> Model: faux.desert.high ~ mm("sex") 
#> Reference: ~Bernoulli 
#> Constraints: ~. ~.

Created on 2025-05-28 with reprex v2.1.1

The problem is that the underlying code always returns a list of lists: a list of parallel runs with each element being a list of resulting networks. When not running in parallel, the top-level list has length 1, and the network statistics are returned in an mcmc.list object.

When simplify = TRUE (the default), simulate() flattens this list and converts the mcmc.list into a matrix. If not, it returns them as they are.

The most immediate consequence of this is that it messes up the print() and summary() methods, since they rely on the length() of the object for the number of networks. This is easy to fix.

More generally, the resulting object isn't technically a list of networks anymore, but a list of lists of networks, so there is an argument to be made for creating a network.list.list class that contains network.list objects, one for each parallel run.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions