statnet / tergm

Fit, Simulate and Diagnose Models for Network Evolution Based on Exponential-Family Random Graph Models

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Change appears to malfunction with isolates

chad-klumb opened this issue · comments

e.g.

require(tergm)
set.seed(0)
nw0 <- network.initialize(100, dir = FALSE)
nw1 <- simulate(nw0 ~ edges, coef = c(-4), dynamic = TRUE, monitor = ~Change(~edges + isolates), output = "final")
attributes(nw1)$stats

produces

> attributes(nw1)$stats
Markov Chain Monte Carlo (MCMC) output:
Start = 1 
End = 1 
Thinning interval = 1 
     Change~edges Change~isolates
[1,]           78             120

I'll look into it.

Looks like an issue in the handling of empty network statistics.

require(tergm)
set.seed(0)
nw0 <- network.initialize(100, dir = FALSE)
# Correct values: 100, 100, -100, 100
summary(nw0 ~ Form(~isolates) + Persist(~isolates) + Diss(~isolates) + Change(~isolates), dynamic=TRUE)
#>    Form~isolates Persist~isolates    Diss~isolates  Change~isolates 
#>              200              100              100              200

Created on 2021-06-21 by the reprex package (v2.0.0)

library(tergm)
nw <- network.initialize(100, dir = FALSE)

# y0, y1 empty.

# Correct values: 0, 100, 0, 100, 0, -100, 0, 100
summary(nw ~ Form(~edges+isolates) + Persist(~edges+isolates) + Diss(~edges+isolates) + Change(~edges+isolates), dynamic=TRUE)
#>       Form~edges    Form~isolates    Persist~edges Persist~isolates 
#>                0              100                0              100 
#>       Diss~edges    Diss~isolates     Change~edges  Change~isolates 
#>                0             -100                0              100

# y0, y1 both have (1,2)
nw[1,2] <- TRUE
# Correct values: 1, 98, 1, 98, -1, -98, 0, 100
summary(nw ~ Form(~edges+isolates) + Persist(~edges+isolates) + Diss(~edges+isolates) + Change(~edges+isolates), dynamic=TRUE)
#>       Form~edges    Form~isolates    Persist~edges Persist~isolates 
#>                1               98                1               98 
#>       Diss~edges    Diss~isolates     Change~edges  Change~isolates 
#>               -1              -98                0              100


# y1 has (1,2), y0 has (1,2) and (3,4)
nw %n% "time" <- 1
nw %n% "lasttoggle" <- cbind(3,4,1)

# Correct values: 2, 96, 1, 98, -1, -98, 1, 98
summary(nw ~ Form(~edges+isolates) + Persist(~edges+isolates) + Diss(~edges+isolates) + Change(~edges+isolates), dynamic=TRUE)
#>       Form~edges    Form~isolates    Persist~edges Persist~isolates 
#>                2               96                1               98 
#>       Diss~edges    Diss~isolates     Change~edges  Change~isolates 
#>               -1              -98                1               98


# y1 has (1,2), y0 has (1,2), (2,3), and (3,4)
nw %n% "lasttoggle" <- rbind(nw %n% "lasttoggle", cbind(2,3,1))

# Correct values: 3, 96, 1, 98, -1, -98, 2, 97
summary(nw ~ Form(~edges+isolates) + Persist(~edges+isolates) + Diss(~edges+isolates) + Change(~edges+isolates), dynamic=TRUE)
#>       Form~edges    Form~isolates    Persist~edges Persist~isolates 
#>                3               96                1               98 
#>       Diss~edges    Diss~isolates     Change~edges  Change~isolates 
#>               -1              -98                2               97

Created on 2021-06-21 by the reprex package (v2.0.0)

@chad-klumb, seems to be better now. Can you please turn these into unit tests?