diff --git a/tests/testthat/test-offsets.R b/tests/testthat/test-offsets.R index fbb9daa49..c125cd615 100644 --- a/tests/testthat/test-offsets.R +++ b/tests/testthat/test-offsets.R @@ -15,6 +15,13 @@ data(sampson) total.theta <- coef(ergm(samplike~edges)) offset.theta <- pi +wald_pval <- function(fit1, fit2, i1=TRUE, i2=TRUE){ + d <- coef(fit1)[i1] - coef(fit2)[i2] + df <- length(d) + vcov <- vcov(fit1, sources="estimation")[i1,i1] + vcov(fit2, sources="estimation")[i2,i2] + pchisq(d %*% solve(vcov) %*% d, df, lower.tail=FALSE) +} + test_that("Linear ERGM with free parameter before offset", { e1 <- ergm(samplike~edges+offset(edges), offset.coef=c(pi)) expect_equal(coef(e1)[1], total.theta-offset.theta, tolerance=0.00001, ignore_attr=TRUE) @@ -40,7 +47,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.06, ignore_attr=TRUE) + expect_gt(wald_pval(e4a, e4, -3, TRUE), 0.01) expect_equal(logLik(e4a), logLik(e4), tolerance=0.01, ignore_attr=TRUE) })