Summary
tergm_MCMC_slave() passes MCMC.maxchanges directly to as.integer() before the .Call to MCMCDyn_wrapper, without wrapping it in deInf(). When MCMC.maxchanges = Inf, this produces:
Warning: NAs introduced by coercion to integer range
The analogous MCMC.maxedges parameter is correctly wrapped with deInf(maxedges, "maxint"), which converts Inf to .Machine$integer.max before the integer coercion. The same treatment appears to be missing for maxchanges.
Relevant code in tergm_MCMC_slave()
maxedges <- NVL(control$MCMC.maxedges, Inf)
maxchanges <- control$MCMC.maxchanges
z <- .Call("MCMCDyn_wrapper", state, as.double(deInf(eta)),
as.integer(control$time.samplesize), as.integer(control$MCMC.burnin.min),
as.integer(control$MCMC.burnin.max), as.double(control$MCMC.burnin.pval),
as.double(control$MCMC.burnin.add), as.integer(control$time.burnin),
as.integer(control$time.interval), as.integer(collect),
as.integer(deInf(maxedges, "maxint")), # <-- wrapped in deInf()
as.integer(maxchanges), # <-- NOT wrapped in deInf()
as.integer(control$changes), as.integer(verbose), PACKAGE = "tergm")
Suggested fix
Wrap maxchanges the same way as maxedges:
as.integer(deInf(maxchanges, "maxint"))
How we encountered this
EpiModel sets MCMC.maxchanges = Inf as a default in netdx(), control.net(), and netest() to remove the practical limit on MCMC changes per step for larger or denser networks. This worked without warnings until recently, when a recompilation of tergm (likely triggered by the ergm 4.12.0 release on 2026-02-17) surfaced the warning across all of our CI tests.
Our workaround was to replace Inf with .Machine$integer.max on the EpiModel side: EpiModel/EpiModel#956
Reproducible example
library(EpiModel)
n <- 100
nw <- network_initialize(n = n)
formation <- ~edges + concurrent + degrange(from = 4)
target.stats <- c(136, 49, 0)
coef.diss <- dissolution_coefs(dissolution = ~offset(edges), duration = 40, d.rate = 0.01)
est <- netest(nw, formation, target.stats, coef.diss)
# This produces: Warning: NAs introduced by coercion to integer range
dx <- netdx(est, nsims = 2, nsteps = 500,
nwstats.formula = ~edges + concurrent,
set.control.tergm = tergm::control.simulate.formula.tergm(MCMC.maxchanges = Inf),
verbose = FALSE)
Versions
- tergm 4.2.2
- ergm 4.12.0
- statnet.common 4.13.0
- R 4.5.2
Summary
tergm_MCMC_slave()passesMCMC.maxchangesdirectly toas.integer()before the.CalltoMCMCDyn_wrapper, without wrapping it indeInf(). WhenMCMC.maxchanges = Inf, this produces:The analogous
MCMC.maxedgesparameter is correctly wrapped withdeInf(maxedges, "maxint"), which convertsInfto.Machine$integer.maxbefore the integer coercion. The same treatment appears to be missing formaxchanges.Relevant code in
tergm_MCMC_slave()Suggested fix
Wrap
maxchangesthe same way asmaxedges:How we encountered this
EpiModel sets
MCMC.maxchanges = Infas a default innetdx(),control.net(), andnetest()to remove the practical limit on MCMC changes per step for larger or denser networks. This worked without warnings until recently, when a recompilation of tergm (likely triggered by the ergm 4.12.0 release on 2026-02-17) surfaced the warning across all of our CI tests.Our workaround was to replace
Infwith.Machine$integer.maxon the EpiModel side: EpiModel/EpiModel#956Reproducible example
Versions