From adbcd4d161bde02cda2553b5a10f69183e1ff27c Mon Sep 17 00:00:00 2001
From: "Pavel N. Krivitsky"
Date: Tue, 13 Aug 2024 14:55:24 +1000
Subject: [PATCH] Redid the conditional MLE helper code to be smarter about
tolerances.
---
tests/testthat/helper-CMLE.R | 297 ++++++++++++++++++++---------------
1 file changed, 167 insertions(+), 130 deletions(-)
diff --git a/tests/testthat/helper-CMLE.R b/tests/testthat/helper-CMLE.R
index 3b2872b9..0260a443 100644
--- a/tests/testthat/helper-CMLE.R
+++ b/tests/testthat/helper-CMLE.R
@@ -8,51 +8,88 @@
# Copyright 2008-2023 Statnet Commons
################################################################################
logit<-function(p) log(p/(1-p))
+ilogit<-function(x) 1/(1+exp(-x))
o <- options(tergm.eval.loglik=FALSE)
CMLE.tools <- new.env()
-CMLE.tools$tolerance <- 3
CMLE.tools$n <- 10
CMLE.tools$m <- 6
CMLE.tools$theta <- -1.5
+expect_logit_ztest <- function(object, expected, variance = 0, alpha = 0.001, p_tolerance = 1e-6){
+ eval.parent(call("expect_named", substitute(object), names(expected)))
+
+ act <- quasi_label(rlang::enquo(object), arg = "object")
+ exp <- quasi_label(rlang::enquo(expected), arg = "expected")
+ var <- quasi_label(rlang::enquo(variance), arg = "variance")
+
+ if(abs(ilogit(exp$val)-ilogit(act$val)) < p_tolerance){
+ succeed() # Infinite case
+ return(invisible(act$val))
+ }
+
+ act$z <- (act$val - exp$val) / sqrt(var$val)
+ act$p <- 2 * pnorm(-abs(act$z))
+
+ expect(act$p >= alpha,
+ sprintf("z = ( %s - %s ) / sqrt(%s) = ( %f - %f ) / %f = %f; P(|Z|>|z|) = %0.3f < %0.2f",
+ act$lab, exp$lab, var$lab,
+ act$val, exp$val, sqrt(var$val),
+ act$z, act$p, alpha))
+
+ invisible(act$val)
+}
+
CMLE.tools$z.error <- function(truth, est, variance){
- if(abs(truth-est)<1e-6) 0 # Infinite case
+ if(abs(truth-est)<1e-6 || abs(ilogit(truth)-ilogit(est))<1e-6) 0 # Infinite case
else abs(truth-est)/sqrt(variance)
}
CMLE.tools$form.mle<-function(y0,y1,y2){
- if(missing(y2)) logit(network.edgecount(y1-y0,na.omit=TRUE)/(network.dyadcount(y1)-network.edgecount(y0-is.na(y1))))
- else logit((network.edgecount(y1-y0,na.omit=TRUE) +
- network.edgecount(y2-y1,na.omit=TRUE))/
- (network.dyadcount(y1)-network.edgecount(y0-is.na(y1)) +
- network.dyadcount(y2)-network.edgecount(y1-is.na(y2))))
+ setNames(
+ if(missing(y2)) logit(network.edgecount(y1-y0,na.omit=TRUE)/(network.dyadcount(y1)-network.edgecount(y0-is.na(y1))))
+ else logit((network.edgecount(y1-y0,na.omit=TRUE) +
+ network.edgecount(y2-y1,na.omit=TRUE))/
+ (network.dyadcount(y1)-network.edgecount(y0-is.na(y1)) +
+ network.dyadcount(y2)-network.edgecount(y1-is.na(y2)))),
+ "Form(1)~edges")
}
CMLE.tools$diss.mle<-function(y0,y1,y2){
- if(missing(y2)) -logit(network.edgecount(y0-y1,na.omit=TRUE)/(network.edgecount(y0-is.na(y1))))
- else -logit((network.edgecount(y0-y1,na.omit=TRUE) +
- network.edgecount(y1-y2,na.omit=TRUE))/
- (network.edgecount(y0-is.na(y1)) +
- network.edgecount(y1-is.na(y2))))
+ setNames(
+ if(missing(y2)) -logit(network.edgecount(y0-y1,na.omit=TRUE)/(network.edgecount(y0-is.na(y1))))
+ else -logit((network.edgecount(y0-y1,na.omit=TRUE) +
+ network.edgecount(y1-y2,na.omit=TRUE))/
+ (network.edgecount(y0-is.na(y1)) +
+ network.edgecount(y1-is.na(y2)))),
+ "Persist(1)~edges")
}
CMLE.tools$cross.mle<-function(y0,y1,y2){
- if(missing(y2)) logit(network.edgecount(y1, na.omit=TRUE)/network.dyadcount(y1, na.omit=TRUE))
- else logit((network.edgecount(y1, na.omit=TRUE) +
- network.edgecount(y2, na.omit=TRUE))/
- (network.dyadcount(y1, na.omit=TRUE) +
- network.dyadcount(y2, na.omit=TRUE)))
+ setNames(
+ if(missing(y2)) logit(network.edgecount(y1, na.omit=TRUE)/network.dyadcount(y1, na.omit=TRUE))
+ else logit((network.edgecount(y1, na.omit=TRUE) +
+ network.edgecount(y2, na.omit=TRUE))/
+ (network.dyadcount(y1, na.omit=TRUE) +
+ network.dyadcount(y2, na.omit=TRUE))),
+ "Cross(1)~edges"
+ )
+}
+
+CMLE.tools$plain.mle<-function(y0,y1,y2){
+ setNames(CMLE.tools$cross.mle(y0, y1, y2), "edges")
}
CMLE.tools$change.mle<-function(y0,y1,y2){
- if(missing(y2)) logit(network.edgecount((y0-y1)|(y1-y0), na.omit=TRUE)/network.dyadcount(y1, na.omit=TRUE))
- else logit((network.edgecount((y0-y1)|(y1-y0), na.omit=TRUE) +
- network.edgecount((y1-y2)|(y2-y1), na.omit=TRUE))/
- (network.dyadcount(y1, na.omit=TRUE) +
- network.dyadcount(y2, na.omit=TRUE)))
+ setNames(
+ if(missing(y2)) logit(network.edgecount((y0-y1)|(y1-y0), na.omit=TRUE)/network.dyadcount(y1, na.omit=TRUE))
+ else logit((network.edgecount((y0-y1)|(y1-y0), na.omit=TRUE) +
+ network.edgecount((y1-y2)|(y2-y1), na.omit=TRUE))/
+ (network.dyadcount(y1, na.omit=TRUE) +
+ network.dyadcount(y2, na.omit=TRUE))),
+ "Change(1)~edges")
}
CMLE.tools$do.run_2 <- function(dir, bip=FALSE, prop.weights="default"){
@@ -77,21 +114,21 @@ CMLE.tools$do.run_2 <- function(dir, bip=FALSE, prop.weights="default"){
set.seed(543)
fit<-tergm(list(y0,y1,y2) ~ Form(~edges) + Persist(~edges), estimate="CMPLE", times=c(1,2,3))
- expect_true(fit$estimate=="CMPLE")
- expect_true(z.error(form.mle(y0,y1,y2), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
- expect_true(z.error(diss.mle(y0,y1,y2), coef(fit)[2], vcov(fit, sources="estimation")[2,2]) <= tolerance)
+ expect_equal(fit$estimate, "CMPLE")
+ expect_logit_ztest(coef(fit)[1], form.mle(y0,y1,y2))
+ expect_logit_ztest(coef(fit)[2], diss.mle(y0,y1,y2))
fit<-tergm(list(y0,y1,y2) ~ edges, estimate="CMPLE", times=c(1,2,3))
- expect_true(fit$estimate=="CMPLE")
- expect_true(z.error(cross.mle(y0,y1,y2), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMPLE")
+ expect_logit_ztest(coef(fit)[1], plain.mle(y0,y1,y2))
fit<-tergm(list(y0,y1,y2) ~ Cross(~edges), estimate="CMPLE", times=c(1,2,3))
- expect_true(fit$estimate=="CMPLE")
- expect_true(z.error(cross.mle(y0,y1,y2), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMPLE")
+ expect_logit_ztest(coef(fit)[1], cross.mle(y0,y1,y2))
fit<-tergm(list(y0,y1,y2) ~ Change(~edges), estimate="CMPLE", times=c(1,2,3))
- expect_true(fit$estimate=="CMPLE")
- expect_true(z.error(change.mle(y0,y1,y2), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMPLE")
+ expect_logit_ztest(coef(fit)[1], change.mle(y0,y1,y2))
})
@@ -100,21 +137,21 @@ CMLE.tools$do.run_2 <- function(dir, bip=FALSE, prop.weights="default"){
set.seed(543)
fit<-tergm(list(y0,y1,y2) ~ Form(~edges) + Persist(~edges), estimate="CMLE", times=c(1,2,3))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(form.mle(y0,y1,y2), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
- expect_true(z.error(diss.mle(y0,y1,y2), coef(fit)[2], vcov(fit, sources="estimation")[2,2]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], form.mle(y0,y1,y2))
+ expect_logit_ztest(coef(fit)[2], diss.mle(y0,y1,y2))
fit<-tergm(list(y0,y1,y2) ~ edges, estimate="CMLE", times=c(1,2,3))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(cross.mle(y0,y1,y2), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], plain.mle(y0,y1,y2))
fit<-tergm(list(y0,y1,y2) ~ Cross(~edges), estimate="CMLE", times=c(1,2,3))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(cross.mle(y0,y1,y2), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], cross.mle(y0,y1,y2))
fit<-tergm(list(y0,y1,y2) ~ Change(~edges), estimate="CMLE", times=c(1,2,3))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(change.mle(y0,y1,y2), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], change.mle(y0,y1,y2))
})
@@ -127,21 +164,21 @@ CMLE.tools$do.run_2 <- function(dir, bip=FALSE, prop.weights="default"){
set.seed(543)
fit<-tergm(list(y0,y1,y2) ~ Form(~edges) + Persist(~edges), estimate="CMLE", control=ctrl, times=c(1,2,3))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(form.mle(y0,y1,y2), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
- expect_true(z.error(diss.mle(y0,y1,y2), coef(fit)[2], vcov(fit, sources="estimation")[2,2]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], form.mle(y0,y1,y2), vcov(fit, sources="estimation")[1,1])
+ expect_logit_ztest(coef(fit)[2], diss.mle(y0,y1,y2), vcov(fit, sources="estimation")[2,2])
fit<-tergm(list(y0,y1,y2) ~ edges, estimate="CMLE", control=ctrl, times=c(1,2,3))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(cross.mle(y0,y1,y2), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], plain.mle(y0,y1,y2), vcov(fit, sources="estimation")[1,1])
fit<-tergm(list(y0,y1,y2) ~ Cross(~edges), estimate="CMLE", control=ctrl, times=c(1,2,3))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(cross.mle(y0,y1,y2), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], cross.mle(y0,y1,y2), vcov(fit, sources="estimation")[1,1])
fit<-tergm(list(y0,y1,y2) ~ Change(~edges), estimate="CMLE", control=ctrl, times=c(1,2,3))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(change.mle(y0,y1,y2), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], change.mle(y0,y1,y2), vcov(fit, sources="estimation")[1,1])
})
}
@@ -159,21 +196,21 @@ CMLE.tools$do.run_2 <- function(dir, bip=FALSE, prop.weights="default"){
set.seed(765)
fit<-tergm(list(y0,y1,y2m) ~ Form(~edges) + Persist(~edges), estimate="CMPLE", times=c(1,2,3))
- expect_true(fit$estimate=="CMPLE")
- expect_true(z.error(form.mle(y0,y1,y2m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
- expect_true(z.error(diss.mle(y0,y1,y2m), coef(fit)[2], vcov(fit, sources="estimation")[2,2]) <= tolerance)
+ expect_equal(fit$estimate, "CMPLE")
+ expect_logit_ztest(coef(fit)[1], form.mle(y0,y1,y2m))
+ expect_logit_ztest(coef(fit)[2], diss.mle(y0,y1,y2m))
fit<-tergm(list(y0,y1,y2m) ~ edges, estimate="CMPLE", times=c(1,2,3))
- expect_true(fit$estimate=="CMPLE")
- expect_true(z.error(cross.mle(y0,y1,y2m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMPLE")
+ expect_logit_ztest(coef(fit)[1], plain.mle(y0,y1,y2m))
fit<-tergm(list(y0,y1,y2m) ~ Cross(~edges), estimate="CMPLE", times=c(1,2,3))
- expect_true(fit$estimate=="CMPLE")
- expect_true(z.error(cross.mle(y0,y1,y2m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMPLE")
+ expect_logit_ztest(coef(fit)[1], cross.mle(y0,y1,y2m))
fit<-tergm(list(y0,y1,y2m) ~ Change(~edges), estimate="CMPLE", times=c(1,2,3))
- expect_true(fit$estimate=="CMPLE")
- expect_true(z.error(change.mle(y0,y1,y2m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMPLE")
+ expect_logit_ztest(coef(fit)[1], change.mle(y0,y1,y2m))
})
@@ -182,21 +219,21 @@ CMLE.tools$do.run_2 <- function(dir, bip=FALSE, prop.weights="default"){
set.seed(765)
fit<-tergm(list(y0,y1,y2m) ~ Form(~edges) + Persist(~edges), estimate="CMLE", times=c(1,2,3))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(form.mle(y0,y1,y2m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
- expect_true(z.error(diss.mle(y0,y1,y2m), coef(fit)[2], vcov(fit, sources="estimation")[2,2]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], form.mle(y0,y1,y2m))
+ expect_logit_ztest(coef(fit)[2], diss.mle(y0,y1,y2m))
fit<-tergm(list(y0,y1,y2m) ~ edges, estimate="CMLE", times=c(1,2,3))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(cross.mle(y0,y1,y2m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], plain.mle(y0,y1,y2m))
fit<-tergm(list(y0,y1,y2m) ~ Cross(~edges), estimate="CMLE", times=c(1,2,3))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(cross.mle(y0,y1,y2m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], cross.mle(y0,y1,y2m))
fit<-tergm(list(y0,y1,y2m) ~ Change(~edges), estimate="CMLE", times=c(1,2,3))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(change.mle(y0,y1,y2m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], change.mle(y0,y1,y2m))
})
@@ -209,21 +246,21 @@ CMLE.tools$do.run_2 <- function(dir, bip=FALSE, prop.weights="default"){
set.seed(234)
fit<-tergm(list(y0,y1,y2m) ~ Form(~edges) + Persist(~edges), estimate="CMLE", control=ctrl, times=c(1,2,3))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(form.mle(y0,y1,y2m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
- expect_true(z.error(diss.mle(y0,y1,y2m), coef(fit)[2], vcov(fit, sources="estimation")[2,2]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], form.mle(y0,y1,y2m), vcov(fit, sources="estimation")[1,1])
+ expect_logit_ztest(coef(fit)[2], diss.mle(y0,y1,y2m), vcov(fit, sources="estimation")[2,2])
fit<-tergm(list(y0,y1,y2m) ~ edges, estimate="CMLE", control=ctrl, times=c(1,2,3))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(cross.mle(y0,y1,y2m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], plain.mle(y0,y1,y2m), vcov(fit, sources="estimation")[1,1])
fit<-tergm(list(y0,y1,y2m) ~ Cross(~edges), estimate="CMLE", control=ctrl, times=c(1,2,3))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(cross.mle(y0,y1,y2m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], cross.mle(y0,y1,y2m), vcov(fit, sources="estimation")[1,1])
fit<-tergm(list(y0,y1,y2m) ~ Change(~edges), estimate="CMLE", control=ctrl, times=c(1,2,3))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(change.mle(y0,y1,y2m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], change.mle(y0,y1,y2m), vcov(fit, sources="estimation")[1,1])
})
}
@@ -250,21 +287,21 @@ CMLE.tools$do.run_1 <- function(dir, bip=FALSE, prop.weights="default"){
set.seed(543)
fit<-tergm(list(y0,y1) ~ Form(~edges) + Persist(~edges), estimate="CMPLE", times=c(1,2))
- expect_true(fit$estimate=="CMPLE")
- expect_true(z.error(form.mle(y0,y1), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
- expect_true(z.error(diss.mle(y0,y1), coef(fit)[2], vcov(fit, sources="estimation")[2,2]) <= tolerance)
+ expect_equal(fit$estimate, "CMPLE")
+ expect_logit_ztest(coef(fit)[1], form.mle(y0,y1))
+ expect_logit_ztest(coef(fit)[2], diss.mle(y0,y1))
fit<-tergm(list(y0,y1) ~ edges, estimate="CMPLE", times=c(1,2))
- expect_true(fit$estimate=="CMPLE")
- expect_true(z.error(cross.mle(y0,y1), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMPLE")
+ expect_logit_ztest(coef(fit)[1], plain.mle(y0,y1))
fit<-tergm(list(y0,y1) ~ Cross(~edges), estimate="CMPLE", times=c(1,2))
- expect_true(fit$estimate=="CMPLE")
- expect_true(z.error(cross.mle(y0,y1), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMPLE")
+ expect_logit_ztest(coef(fit)[1], cross.mle(y0,y1))
fit<-tergm(list(y0,y1) ~ Change(~edges), estimate="CMPLE", times=c(1,2))
- expect_true(fit$estimate=="CMPLE")
- expect_true(z.error(change.mle(y0,y1), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMPLE")
+ expect_logit_ztest(coef(fit)[1], change.mle(y0,y1))
})
@@ -273,21 +310,21 @@ CMLE.tools$do.run_1 <- function(dir, bip=FALSE, prop.weights="default"){
set.seed(543)
fit<-tergm(list(y0,y1) ~ Form(~edges) + Persist(~edges), estimate="CMLE", times=c(1,2))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(form.mle(y0,y1), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
- expect_true(z.error(diss.mle(y0,y1), coef(fit)[2], vcov(fit, sources="estimation")[2,2]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], form.mle(y0,y1))
+ expect_logit_ztest(coef(fit)[2], diss.mle(y0,y1))
fit<-tergm(list(y0,y1) ~ edges, estimate="CMLE", times=c(1,2))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(cross.mle(y0,y1), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], plain.mle(y0,y1))
fit<-tergm(list(y0,y1) ~ Cross(~edges), estimate="CMLE", times=c(1,2))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(cross.mle(y0,y1), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], cross.mle(y0,y1))
fit<-tergm(list(y0,y1) ~ Change(~edges), estimate="CMLE", times=c(1,2))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(change.mle(y0,y1), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], change.mle(y0,y1))
})
@@ -300,21 +337,21 @@ CMLE.tools$do.run_1 <- function(dir, bip=FALSE, prop.weights="default"){
set.seed(543)
fit<-tergm(list(y0,y1) ~ Form(~edges) + Persist(~edges), estimate="CMLE", control=ctrl, times=c(1,2))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(form.mle(y0,y1), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
- expect_true(z.error(diss.mle(y0,y1), coef(fit)[2], vcov(fit, sources="estimation")[2,2]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], form.mle(y0,y1), vcov(fit, sources="estimation")[1,1])
+ expect_logit_ztest(coef(fit)[2], diss.mle(y0,y1), vcov(fit, sources="estimation")[2,2])
fit<-tergm(list(y0,y1) ~ edges, estimate="CMLE", control=ctrl, times=c(1,2))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(cross.mle(y0,y1), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], plain.mle(y0,y1), vcov(fit, sources="estimation")[1,1])
fit<-tergm(list(y0,y1) ~ Cross(~edges), estimate="CMLE", control=ctrl, times=c(1,2))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(cross.mle(y0,y1), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], cross.mle(y0,y1), vcov(fit, sources="estimation")[1,1])
fit<-tergm(list(y0,y1) ~ Change(~edges), estimate="CMLE", control=ctrl, times=c(1,2))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(change.mle(y0,y1), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], change.mle(y0,y1), vcov(fit, sources="estimation")[1,1])
})
}
@@ -332,21 +369,21 @@ CMLE.tools$do.run_1 <- function(dir, bip=FALSE, prop.weights="default"){
set.seed(765)
fit<-tergm(list(y0,y1m) ~ Form(~edges) + Persist(~edges), estimate="CMPLE", times=c(1,2))
- expect_true(fit$estimate=="CMPLE")
- expect_true(z.error(form.mle(y0,y1m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
- expect_true(z.error(diss.mle(y0,y1m), coef(fit)[2], vcov(fit, sources="estimation")[2,2]) <= tolerance)
+ expect_equal(fit$estimate, "CMPLE")
+ expect_logit_ztest(coef(fit)[1], form.mle(y0,y1m))
+ expect_logit_ztest(coef(fit)[2], diss.mle(y0,y1m))
fit<-tergm(list(y0,y1m) ~ edges, estimate="CMPLE", times=c(1,2))
- expect_true(fit$estimate=="CMPLE")
- expect_true(z.error(cross.mle(y0,y1m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMPLE")
+ expect_logit_ztest(coef(fit)[1], plain.mle(y0,y1m))
fit<-tergm(list(y0,y1m) ~ Cross(~edges), estimate="CMPLE", times=c(1,2))
- expect_true(fit$estimate=="CMPLE")
- expect_true(z.error(cross.mle(y0,y1m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMPLE")
+ expect_logit_ztest(coef(fit)[1], cross.mle(y0,y1m))
fit<-tergm(list(y0,y1m) ~ Change(~edges), estimate="CMPLE", times=c(1,2))
- expect_true(fit$estimate=="CMPLE")
- expect_true(z.error(change.mle(y0,y1m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMPLE")
+ expect_logit_ztest(coef(fit)[1], change.mle(y0,y1m))
})
@@ -355,21 +392,21 @@ CMLE.tools$do.run_1 <- function(dir, bip=FALSE, prop.weights="default"){
set.seed(765)
fit<-tergm(list(y0,y1m) ~ Form(~edges) + Persist(~edges), estimate="CMLE", times=c(1,2))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(form.mle(y0,y1m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
- expect_true(z.error(diss.mle(y0,y1m), coef(fit)[2], vcov(fit, sources="estimation")[2,2]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], form.mle(y0,y1m))
+ expect_logit_ztest(coef(fit)[2], diss.mle(y0,y1m))
fit<-tergm(list(y0,y1m) ~ edges, estimate="CMLE", times=c(1,2))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(cross.mle(y0,y1m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], plain.mle(y0,y1m))
fit<-tergm(list(y0,y1m) ~ Cross(~edges), estimate="CMLE", times=c(1,2))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(cross.mle(y0,y1m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], cross.mle(y0,y1m))
fit<-tergm(list(y0,y1m) ~ Change(~edges), estimate="CMLE", times=c(1,2))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(change.mle(y0,y1m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], change.mle(y0,y1m))
})
@@ -382,22 +419,22 @@ CMLE.tools$do.run_1 <- function(dir, bip=FALSE, prop.weights="default"){
set.seed(1234)
fit<-tergm(list(y0,y1m) ~ Form(~edges) + Persist(~edges), estimate="CMLE", control=ctrl, times=c(1,2))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(form.mle(y0,y1m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
- expect_true(z.error(diss.mle(y0,y1m), coef(fit)[2], vcov(fit, sources="estimation")[2,2]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], form.mle(y0,y1m), vcov(fit, sources="estimation")[1,1])
+ expect_logit_ztest(coef(fit)[2], diss.mle(y0,y1m), vcov(fit, sources="estimation")[2,2])
fit<-tergm(list(y0,y1m) ~ edges, estimate="CMLE", control=ctrl, times=c(1,2))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(cross.mle(y0,y1m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], plain.mle(y0,y1m), vcov(fit, sources="estimation")[1,1])
fit<-tergm(list(y0,y1m) ~ Cross(~edges), estimate="CMLE", control=ctrl, times=c(1,2))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(cross.mle(y0,y1m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], cross.mle(y0,y1m), vcov(fit, sources="estimation")[1,1])
fit<-tergm(list(y0,y1m) ~ Change(~edges), estimate="CMLE", control=ctrl, times=c(1,2))
- expect_true(fit$estimate=="CMLE")
- expect_true(z.error(change.mle(y0,y1m), coef(fit)[1], vcov(fit, sources="estimation")[1,1]) <= tolerance)
+ expect_equal(fit$estimate, "CMLE")
+ expect_logit_ztest(coef(fit)[1], change.mle(y0,y1m), vcov(fit, sources="estimation")[1,1])
})