diff --git a/DESCRIPTION b/DESCRIPTION index beddc9c29..4e44c5439 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ergm -Version: 4.0-6565 -Date: 2021-07-12 +Version: 4.0-6570 +Date: 2021-07-13 Title: Fit, Simulate and Diagnose Exponential-Family Models for Networks Authors@R: c( person("Mark S.", "Handcock", role=c("aut"), email="handcock@stat.ucla.edu"), diff --git a/R/ergm.getMCMCsample.R b/R/ergm.getMCMCsample.R index ba1882c1a..2f54a652f 100644 --- a/R/ergm.getMCMCsample.R +++ b/R/ergm.getMCMCsample.R @@ -348,8 +348,11 @@ ergm_MCMC_slave <- function(state, eta,control,verbose,..., burnin=NULL, samples .find_OK_burnin <- function(x, ...){ n <- nrow(x[[1]]) ssr <- function(b, s){ + # b is basically the number of steps corresponding to halving of + # the difference in the expected value of the variable at the + # current MCMC draw from the ultimate expected value. b <- round(b) - a <- lm(s ~ c(seq_len(b) - 1, rep(b, n - b))) + a <- lm(s ~ 1 + I(2^(-seq_len(n)/b))) sum(sigma(a)^2) } geweke <- function(b){ @@ -362,9 +365,12 @@ ergm_MCMC_slave <- function(state, eta,control,verbose,..., burnin=NULL, samples xs <- x %>% map(scale) %>% map(~.[,attr(.,"scaled:scale")>0,drop=FALSE]) %>% discard(~ncol(.)==0) if(length(xs)==0) return(FAIL) - best <- sapply(xs, function(x) optimize(ssr, c(0, n/2), s=x, tol=1)$minimum) + bscl <- 10 # I.e., reduce error to about 1/2^10 of the initial value. + + best <- sapply(xs, function(x) optimize(ssr, c(0, n/bscl/4), s=x)$minimum) if(all(is.na(best) | is.infinite(best))) return(FAIL) - best <- max(best, na.rm=TRUE) + best <- max(best, na.rm=TRUE) * bscl + list(burnin=round(best), pval=geweke(round(best))) } diff --git a/tests/testthat/test-offsets.R b/tests/testthat/test-offsets.R index d93a8918c..eb85e7900 100644 --- a/tests/testthat/test-offsets.R +++ b/tests/testthat/test-offsets.R @@ -41,7 +41,7 @@ test_that("Linear ERGM with partial offsets", { test_that("Curved ERGM with partial offsets", { e4 <- ergm(samplike~edges+gwesp(0.25, fix=TRUE), control=control.ergm(seed=0,MCMLE.maxit=2)) e4a <- ergm(samplike~edges+offset(gwesp(),c(FALSE,TRUE)), offset.coef=0.25, control=control.ergm(seed=0,MCMLE.maxit=2)) - expect_equal(coef(e4a)[-3], coef(e4), tolerance=0.03, ignore_attr=TRUE) + expect_equal(coef(e4a)[-3], coef(e4), tolerance=0.06, ignore_attr=TRUE) expect_equal(logLik(e4a), logLik(e4), tolerance=0.01, ignore_attr=TRUE) })