Closed smjenness closed 1 year ago
cc: @adrienleguillou
Can you try reinstalling tergm
from source as well? If that fixes it, I'll explain.
Yes, that solved it. Updated with the CRAN version of tergm with:
install.packages("tergm", type = "source")
Interested to know why...
However, now, a new error message pops up. Here is an example with EpiModel code, I will try to isolate with a MRE with ergm only.
nw <- network_initialize(n = 100)
nw <- set_vertex_attribute(nw, "group", rep(1:2, each = 50))
formation <- ~edges
target.stats <- 50
coef.diss <- dissolution_coefs(dissolution = ~offset(edges), duration = 20)
est1 <- netest(nw, formation, target.stats, coef.diss, verbose = FALSE)
# Epidemic model
param <- param.net(inf.prob = 0.3, inf.prob.g2 = 0.15)
init <- init.net(i.num = 10, i.num.g2 = 10)
control <- control.net(type = "SI", nsteps = 100, nsims = 5, verbose.int = 0)
mod1 <- netsim(est1, param, init, control)
Error:
Starting Network Simulation...Error in select_ergm_proposal(object, class = class, ref = reference, :
The combination of class (t), model constraints and hints (‘.’, ‘.attributes’, ‘discord’, and ‘sparse’), reference measure ("Bernoulli"), proposal weighting (default), and conjunctions and disjunctions is not implemented. Check your arguments for typos.
Here is an MRE with ergm/tergm code only:
nw <- network.initialize(n = 100, FALSE)
x <- ergm(nw ~ edges, target.stats = 50)
x$coefficients[1] <- x$coefficients - 2.94 # edges dissolution approx
nw <- simulate(x$formula,
coef = x$coefficients,
basis = x$newnetwork,
dynamic = FALSE)
sim <- simulate(nw ~ Form(x$formula) + Persist(~offset(edges)),
coef = c(x$coefficients, 2.94),
time.slices = 1,
time.start = 0,
time.offset = 1,
nsim = 1,
dynamic = TRUE)
Same error as above.
Note that I tested this against both CRAN and Github master versions of tergm, same error.
Yes, that solved it. Updated with the CRAN version of tergm with: Interested to know why...
Long story short, for technical reasons, tergm
grabs a copy of ergm
's simulate_formula.network()
method at build time, before overriding it with its own. Unfortunately, it means that if ergm
's copy of simulate_formula.network()
gets updated without rebuilding tergm
, it may be calling the old version, causing an error.
I'll look into the new issue tomorrow.
Small correction to the MWE:
library(tergm)
nw <- network.initialize(n = 100, FALSE)
x <- ergm(nw ~ edges, target.stats = 50)
x$coefficients[1] <- x$coefficients - 2.94 # edges dissolution approx
nw <- simulate(x$formula,
coef = x$coefficients,
basis = x$newnetwork,
dynamic = FALSE)
sim <- simulate(nw ~ Form(x$formula) + Persist(~offset(edges)),
coef = c(x$coefficients, 2.94),
time.slices = 1,
time.start = 0,
time.offset = 1,
nsim = 1,
dynamic = TRUE)
I can confirm this resolved the issue. Thanks @krivit!
With the latest master of
ergm
andstatnet.common
, simulating from a formula when loading ergm is fine:Session Info
But then loading EpiModel, and running the same code generates an error:
Session Info