statnet / ergm.multi

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

Stochastic error in multilayer.R test #12

Closed krivit closed 2 years ago

krivit commented 2 years ago
library(ergm.multi)
nw0 <- network.initialize(3, dir=FALSE)
nw1 <- nw0
nw1[1,2] <- 1
nw1[2,3] <- 1

nw2 <- nw0
nw2[1,2] <- 1
nw2[1,3] <- 1

layer_and_MLE <- function(nw1, nw2){
  nd <- network.dyadcount(nw1)
  ne <- summary(nw1&nw2~edges)
  log(3*ne/nd)-log(1-ne/nd)
}

layer_and_Info <- function(nw1, nw2){
  mle <- layer_and_MLE(nw1, nw2)
  network.dyadcount(nw1)*(3*exp(mle))/(3+exp(mle))^2
}
set.seed(8)
layer <- ergm(Layer(nw1,nw2)~L(~edges, ~`1`&`2`))
logic.coef <- layer_and_MLE(nw1,nw2)
logic.info <- layer_and_Info(nw1,nw2)

stopifnot(isTRUE(all.equal(1/logic.info,c(vcov(layer, sources="model")),check.attributes=FALSE,tolerance=.4)))
#> Error: isTRUE(all.equal(1/logic.info, c(vcov(layer, sources = "model")),  .... is not TRUE

Created on 2022-07-03 by the reprex package (v2.0.1)