-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed the wrong categories being selected for COLLAPSE_SMALLEST() and…
… added lexicographic tie breaking with warnings for when categories passed to LARGEST, SMALLEST, and COLLAPSE_SMALLEST have equal sizes. fixes #544, #545
- Loading branch information
Showing
4 changed files
with
149 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: ergm | ||
Version: 4.6-7286 | ||
Date: 2023-12-17 | ||
Version: 4.6-7289 | ||
Date: 2024-01-02 | ||
Title: Fit, Simulate and Diagnose Exponential-Family Models for Networks | ||
Authors@R: c( | ||
person(c("Mark", "S."), "Handcock", role=c("aut"), email="[email protected]"), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
o <- options(useFancyQuotes=FALSE) | ||
|
||
set.seed(123) # Need stable randomization. | ||
data(florentine) | ||
flomarriage %v% "x" <- sample(c(1,11,2,3), 16, replace=TRUE) ## 11 tests for numeric rather than alphabetical sorting. | ||
|
||
test_that("Nodal attribute level initialization and sorting", { | ||
expect_equal(summary(flomarriage ~ nodefactor("x", levels=TRUE)), | ||
c(nodefactor.x.1 = 3, nodefactor.x.2 = 18, nodefactor.x.3 = 3, nodefactor.x.11 = 16)) | ||
}) | ||
|
||
test_that("Selecting the smallest and largest categories", { | ||
expect_equal(summary(flomarriage ~ nodefactor("x", levels=SMALLEST)), | ||
c(nodefactor.x.3 = 3)) | ||
|
||
expect_equal(summary(flomarriage ~ nodefactor("x", levels=SMALLEST(2))), | ||
c(nodefactor.x.1 = 3, nodefactor.x.3 = 3)) | ||
|
||
expect_equal(summary(flomarriage ~ nodefactor("x", levels=LARGEST)), | ||
c(nodefactor.x.11 = 16)) | ||
|
||
expect_equal(summary(flomarriage ~ nodefactor("x", levels=LARGEST(2))), | ||
c(nodefactor.x.2 = 18, nodefactor.x.11 = 16)) | ||
}) | ||
|
||
|
||
test_that("Selector negation", { | ||
expect_equal(summary(flomarriage ~ nodefactor("x", levels=-SMALLEST)), | ||
c(nodefactor.x.1 = 3, nodefactor.x.2 = 18, nodefactor.x.11 = 16)) | ||
|
||
expect_equal(summary(flomarriage ~ nodefactor("x", levels=-SMALLEST(2))), | ||
c(nodefactor.x.2 = 18, nodefactor.x.11 = 16)) | ||
|
||
expect_equal(summary(flomarriage ~ nodefactor("x", levels=-LARGEST)), | ||
c(nodefactor.x.1 = 3, nodefactor.x.2 = 18, nodefactor.x.3 = 3)) | ||
|
||
expect_equal(summary(flomarriage ~ nodefactor("x", levels=-LARGEST(2))), | ||
c(nodefactor.x.1 = 3, nodefactor.x.3 = 3)) | ||
}) | ||
|
||
test_that("Collapsing categories", { | ||
expect_equal(summary(flomarriage ~ nodefactor("x" %>% COLLAPSE_SMALLEST(2, 5), levels=TRUE)), | ||
c(nodefactor.x.2 = 18, nodefactor.x.5 = 6, nodefactor.x.11 = 16)) | ||
|
||
expect_equal(summary(flomarriage ~ nodefactor("x" %>% COLLAPSE_SMALLEST(3, 5), levels=TRUE)), | ||
c(nodefactor.x.5 = 24, nodefactor.x.11 = 16)) | ||
|
||
expect_equal(summary(flomarriage ~ nodefactor("x" %>% COLLAPSE_SMALLEST(2, 5), levels=SMALLEST(2))), | ||
c(nodefactor.x.2 = 18, nodefactor.x.5 = 6)) | ||
}) | ||
|
||
## Tied categories | ||
|
||
set.seed(789) # Need stable randomization. | ||
data(florentine) | ||
flomarriage %v% "x" <- sample(c(1,11,2,3), 16, replace=TRUE) ## 11 tests for numeric rather than alphabetical sorting. | ||
|
||
test_that("Tied categories nodal attribute level initialization and sorting", { | ||
expect_equal(summary(flomarriage ~ nodefactor("x", levels=TRUE)), | ||
c(nodefactor.x.1 = 2, nodefactor.x.2 = 11, nodefactor.x.3 = 15, nodefactor.x.11 = 12)) | ||
}) | ||
|
||
test_that("Tied categories selecting the smallest and largest", { | ||
expect_no_warning(expect_equal(summary(flomarriage ~ nodefactor("x", levels=SMALLEST(1))), | ||
c(nodefactor.x.1 = 2))) | ||
|
||
expect_warning(expect_equal(summary(flomarriage ~ nodefactor("x", levels=SMALLEST(2))), | ||
c(nodefactor.x.1 = 2, nodefactor.x.2 = 11)), | ||
"In term 'nodefactor' in package 'ergm': Levels '2' and '11' are tied. Using the order given.") | ||
|
||
expect_no_warning(expect_equal(summary(flomarriage ~ nodefactor("x", levels=SMALLEST(3))), | ||
c(nodefactor.x.1 = 2, nodefactor.x.2 = 11, nodefactor.x.11 = 12))) | ||
|
||
expect_equal(summary(flomarriage ~ nodefactor("x", levels=LARGEST)), | ||
c(nodefactor.x.3 = 15)) | ||
|
||
expect_warning(expect_equal(summary(flomarriage ~ nodefactor("x", levels=LARGEST(2))), | ||
c(nodefactor.x.3 = 15, nodefactor.x.11 = 12)), | ||
"In term 'nodefactor' in package 'ergm': Levels '2' and '11' are tied. Using the order given.") | ||
}) | ||
|
||
|
||
test_that("Collapsing categories", { | ||
expect_warning(expect_equal(summary(flomarriage ~ nodefactor("x" %>% COLLAPSE_SMALLEST(2, 5), levels=TRUE)), | ||
c(nodefactor.x.3 = 15, nodefactor.x.5 = 13, nodefactor.x.11 = 12)), | ||
"In term 'nodefactor' in package 'ergm': Levels '2' and '11' are tied. Using the order given.") | ||
|
||
expect_no_warning(expect_equal(summary(flomarriage ~ nodefactor("x" %>% COLLAPSE_SMALLEST(3, 5), levels=TRUE)), | ||
c(nodefactor.x.3 = 15, nodefactor.x.5 = 25))) | ||
|
||
expect_warning(expect_warning(expect_equal(summary(flomarriage ~ nodefactor("x" %>% COLLAPSE_SMALLEST(2, 5), levels=SMALLEST(2))), | ||
c(nodefactor.x.3 = 15, nodefactor.x.11 = 12)), | ||
"In term 'nodefactor' in package 'ergm': Levels '2' and '11' are tied. Using the order given."), | ||
"In term 'nodefactor' in package 'ergm': Levels '3' and '5' are tied. Using the order given.") | ||
}) | ||
|
||
options(o) |