diff --git a/tests/testthat/test_compression.R b/tests/testthat/test_compression.R index cf0b68d..e4041ab 100644 --- a/tests/testthat/test_compression.R +++ b/tests/testthat/test_compression.R @@ -1,3 +1,7 @@ +if (!identical(Sys.getenv("NOT_CRAN"), "true")) { + return() +} + library("segregation") context("test_compression") @@ -10,13 +14,11 @@ all_neighbors <- expand.grid(a = all_neighbors, b = all_neighbors) res_all <- compress(subset, "race", "school", weight = "n", neighbors = all_neighbors) test_that("result is the same with no neighbors given", { - testthat::skip_on_cran() res2 <- compress(subset, "race", "school", neighbors = "all", weight = "n") expect_equal(res_all$iterations, res2$iterations) }) test_that("compress works", { - testthat::skip_on_cran() # 9 merges expect_equal(nrow(res_all$iterations), 16) # M values is declining continously @@ -26,13 +28,11 @@ test_that("compress works", { }) test_that("print", { - testthat::skip_on_cran() expect_output(print(res_all), "17 units") expect_output(print(res_all), "Threshold 99%") }) test_that("get_crosswalk works", { - testthat::skip_on_cran() expect_error( get_crosswalk(schools00), "either n_units or percent has to be given" @@ -60,7 +60,6 @@ test_that("get_crosswalk works", { }) test_that("parts", { - testthat::skip_on_cran() # get_crosswalk res_no_parts <- get_crosswalk(res_all, percent = 0.6) res_parts <- get_crosswalk(res_all, percent = 0.6, parts = TRUE) @@ -83,13 +82,11 @@ test_that("parts", { }) test_that("compress edge case", { - testthat::skip_on_cran() res_edge <- compress(subset, "race", "school", neighbors = "all", weight = "n", max_iter = 1) expect_equal(nrow(get_crosswalk(res_edge, n_units = 16)), n_schools) }) test_that("merge_units", { - testthat::skip_on_cran() merged <- merge_units(res_all, percent = 0.8) new_units_cw <- sort(unique(get_crosswalk(res_all, percent = 0.8)$new)) new_units_merged <- sort(unique(merged$school)) @@ -97,7 +94,6 @@ test_that("merge_units", { }) test_that("percent works", { - testthat::skip_on_cran() M_full <- mutual_total(subset, "race", "school", weight = "n")[stat == "M"][["est"]] for (pct in seq(0.1, 0.9, by = 0.05)) { @@ -110,7 +106,6 @@ test_that("percent works", { }) test_that("merge_units edge case", { - testthat::skip_on_cran() res_edge <- compress(subset, "race", "school", neighbors = "all", weight = "n", max_iter = 1) merged <- merge_units(res_edge, n_units = 16) # replicate manual merge @@ -121,7 +116,6 @@ test_that("merge_units edge case", { }) test_that("scree plot", { - testthat::skip_on_cran() if (requireNamespace("ggplot2", quietly = TRUE)) { plot <- scree_plot(res_all) expect_equal(nrow(plot$data), n_schools) diff --git a/tests/testthat/test_dissimilarity.R b/tests/testthat/test_dissimilarity.R index 095e1fd..87e68a0 100644 --- a/tests/testthat/test_dissimilarity.R +++ b/tests/testthat/test_dissimilarity.R @@ -1,9 +1,11 @@ +if (!identical(Sys.getenv("NOT_CRAN"), "true")) { + return() +} + library("segregation") context("test_dissimilarity") test_that("correct calculations", { - testthat::skip_on_cran() - m0 <- matrix_to_long(matrix(c(100, 100, 100, 100, 100, 100), ncol = 2)) expect_equal(dissimilarity(m0, "group", "unit", weight = "n")$est[[1]], 0) @@ -17,8 +19,6 @@ test_that("correct calculations", { }) test_that("alternative calculation", { - testthat::skip_on_cran() - tab <- t(matrix(c(100, 60, 40, 0, 0, 40, 60, 100), ncol = 2)) div <- sweep(tab, 1, rowSums(tab), "/") d <- 1 / 2 * sum(apply(div, 2, segregation:::abs_diff)) @@ -27,7 +27,6 @@ test_that("alternative calculation", { }) test_that("SE works", { - testthat::skip_on_cran() m0 <- matrix_to_long(matrix(c(100, 60, 40, 0, 0, 40, 60, 100), ncol = 2)) d <- dissimilarity(m0, "group", "unit", weight = "n", se = TRUE) expect_equal(dim(d), c(1, 5)) @@ -36,8 +35,6 @@ test_that("SE works", { }) test_that("names of columns", { - testthat::skip_on_cran() - m0 <- matrix_to_long(matrix(c(100, 60, 40, 0, 0, 40, 60, 100), ncol = 2), group = "race", unit = "tract" ) @@ -52,15 +49,11 @@ test_that("names of columns", { test_that("bootstrapping fails when sample size is non-integer", { - testthat::skip_on_cran() - m0 <- matrix_to_long(matrix(c(100.3, 60, 40, 0, 0, 40, 60, 100), ncol = 2)) expect_error(dissimilarity(m0, "group", "unit", weight = "n", se = TRUE)) }) test_that("gives error when group > 2", { - testthat::skip_on_cran() - m0 <- matrix_to_long(matrix(c(100, 60, 40, 10, 20, 40, 60, 100, 50), ncol = 3)) expect_error(dissimilarity(m0, "group", "unit", weight = "n")) }) diff --git a/tests/testthat/test_entropy.R b/tests/testthat/test_entropy.R index e7e9b6d..e5afeeb 100644 --- a/tests/testthat/test_entropy.R +++ b/tests/testthat/test_entropy.R @@ -1,15 +1,15 @@ +if (!identical(Sys.getenv("NOT_CRAN"), "true")) { + return() +} + library("segregation") context("test_entropy") test_that("custom log function", { - testthat::skip_on_cran() - expect_equal(logf(2, exp(1)), log(2)) }) test_that("correct entropy calculation", { - testthat::skip_on_cran() - expect_equal(entropy(data.frame(x = c(1)), "x"), 0) expect_equal(entropy(data.frame(x = c(1, 2)), "x"), log(2)) expect_equal(entropy(data.frame(x = c(1, 2, 3)), "x"), log(3)) diff --git a/tests/testthat/test_exposure_isolation.R b/tests/testthat/test_exposure_isolation.R index 9f419a3..088d4ad 100644 --- a/tests/testthat/test_exposure_isolation.R +++ b/tests/testthat/test_exposure_isolation.R @@ -1,9 +1,11 @@ +if (!identical(Sys.getenv("NOT_CRAN"), "true")) { + return() +} + library("segregation") context("test_exposure_isolation") test_that("two group case", { - testthat::skip_on_cran() - two <- data.table::as.data.table(schools00) two <- two[race %in% c("white", "black")] exp <- exposure(two, "race", "school", "n") @@ -19,8 +21,6 @@ test_that("two group case", { }) test_that("exposure", { - testthat::skip_on_cran() - exp <- exposure(schools00, "race", "school", "n") expect_equal( exp[, .(sum = sum(exposure)), by = .(of)][["sum"]], @@ -29,8 +29,6 @@ test_that("exposure", { }) test_that("exposure and isolation", { - testthat::skip_on_cran() - exp <- exposure(schools00, "race", "school", "n")[of == to] iso <- isolation(schools00, "race", "school", "n") comp <- merge(exp, iso, by.x = "of", by.y = "race") diff --git a/tests/testthat/test_ipf.R b/tests/testthat/test_ipf.R index 03482de..2811b04 100644 --- a/tests/testthat/test_ipf.R +++ b/tests/testthat/test_ipf.R @@ -1,9 +1,11 @@ +if (!identical(Sys.getenv("NOT_CRAN"), "true")) { + return() +} + library("segregation") context("test_ipf") test_that("different precisions", { - testthat::skip_on_cran() - # reduce to overlap sample schools00_r <- schools00[schools00$school %in% schools05$school, ] schools05_r <- schools05[schools05$school %in% schools00$school, ] @@ -30,8 +32,6 @@ test_that("different precisions", { }) test_that("warn if iterations are too low", { - testthat::skip_on_cran() - expect_error( suppressWarnings( ipf(schools00, schools05, "race", "school", @@ -43,8 +43,6 @@ test_that("warn if iterations are too low", { }) test_that("gives sames results as mutual_difference", { - testthat::skip_on_cran() - diff <- mutual_difference(schools00, schools05, group = "race", unit = "school", weight = "n", method = "km", precision = 0.000001 @@ -72,8 +70,6 @@ test_that("gives sames results as mutual_difference", { }) test_that("example from Karmel & Maclachlan 1988", { - testthat::skip_on_cran() - source <- data.frame( occ = rep(c(1, 2, 3), 2), gender = c(rep("male", 3), rep("female", 3)), @@ -108,15 +104,11 @@ test_that("example from Karmel & Maclachlan 1988", { }) test_that("warning about units and groups being dropped", { - testthat::skip_on_cran() - expect_warning(ipfd <- ipf(schools00, schools05, "race", "school", weight = "n")) expect_equal(sum(ipfd$n), sum(ipfd$n_source)) }) test_that("returns same number of observations as before", { - testthat::skip_on_cran() - # schools are dropped here suppressWarnings(ipfd <- ipf(schools00, schools05, "race", "school", weight = "n")) expect_equal(sum(ipfd$n), sum(ipfd$n_source)) diff --git a/tests/testthat/test_matrix_to_long.R b/tests/testthat/test_matrix_to_long.R index b5e006d..6060d9b 100644 --- a/tests/testthat/test_matrix_to_long.R +++ b/tests/testthat/test_matrix_to_long.R @@ -1,16 +1,16 @@ +if (!identical(Sys.getenv("NOT_CRAN"), "true")) { + return() +} + library("segregation") context("test_matrix_to_long") test_that("accept only matrix", { - testthat::skip_on_cran() - a <- data.frame() expect_error(matrix_to_long(a)) }) test_that("no names", { - testthat::skip_on_cran() - m <- matrix(c(10, 20, 30, 30, 20, 10), nrow = 3) long <- matrix_to_long(m) expect_equal(names(long), c("unit", "group", "n")) @@ -19,8 +19,6 @@ test_that("no names", { }) test_that("rownames only", { - testthat::skip_on_cran() - m <- matrix(c(10, 20, 30, 30, 20, 10), nrow = 3) colnames(m) <- c("A", "B") long <- matrix_to_long(m) @@ -30,8 +28,6 @@ test_that("rownames only", { }) test_that("colnames only", { - testthat::skip_on_cran() - m <- matrix(c(10, 20, 30, 30, 20, 10), nrow = 3) rownames(m) <- c("S1", "S2", "S3") long <- matrix_to_long(m) @@ -41,8 +37,6 @@ test_that("colnames only", { }) test_that("rownames + colnames", { - testthat::skip_on_cran() - m <- matrix(c(10, 20, 30, 30, 20, 10), nrow = 3) colnames(m) <- c("A", "B") rownames(m) <- c("S1", "S2", "S3") @@ -53,8 +47,6 @@ test_that("rownames + colnames", { }) test_that("arguments", { - testthat::skip_on_cran() - # drop zero m <- matrix(c(10, 20, 30, 0, 20, 0), nrow = 3) long1 <- matrix_to_long(m) diff --git a/tests/testthat/test_mutual_difference.R b/tests/testthat/test_mutual_difference.R index 8a9092b..1397a92 100644 --- a/tests/testthat/test_mutual_difference.R +++ b/tests/testthat/test_mutual_difference.R @@ -1,3 +1,7 @@ +if (!identical(Sys.getenv("NOT_CRAN"), "true")) { + return() +} + library("segregation") context("test_mutual_diff") @@ -13,12 +17,10 @@ test_data2 <- data.frame( ) test_that("mutual_difference method not defined error", { - testthat::skip_on_cran() expect_error(mutual_difference(test_data1, test_data2, "g", "u", weight = "n", method = "X")) }) test_that("mutual_difference SHAPLEY", { - testthat::skip_on_cran() sh1 <- mutual_difference(test_data1, test_data2, "g", "u", weight = "n", method = "shapley") sh2 <- mutual_difference(test_data1, test_data2, "u", "g", weight = "n", method = "shapley") sh3 <- mutual_difference(test_data2, test_data1, "g", "u", weight = "n", method = "shapley") @@ -100,7 +102,6 @@ test_that("mutual_difference SHAPLEY", { }) test_that("mutual_difference KM", { - testthat::skip_on_cran() ret1 <- mutual_difference(test_data1, test_data2, "g", "u", weight = "n", method = "km", precision = .0001 @@ -156,7 +157,6 @@ test_that("mutual_difference KM", { test_that("mutual_difference MRC", { - testthat::skip_on_cran() ret <- mutual_difference(test_data1, test_data2, "g", "u", weight = "n", method = "mrc" @@ -198,7 +198,6 @@ test_that("mutual_difference MRC", { test_that("mutual_difference SE", { - testthat::skip_on_cran() ret <- mutual_difference(test_data1, test_data2, "g", "u", weight = "n", method = "shapley", se = TRUE, n_bootstrap = 5 @@ -228,7 +227,6 @@ test_that("mutual_difference SE", { }) test_that("mutual_difference shapley_detailed structural", { - testthat::skip_on_cran() diff_simple <- mutual_difference(schools05, schools00, group = "school", unit = "race", weight = "n", method = "shapley", precision = .000001 @@ -273,7 +271,6 @@ test_that("mutual_difference shapley_detailed structural", { }) test_that("mutual_difference shapley_detailed marginal", { - testthat::skip_on_cran() diff_simple <- mutual_difference(schools05, schools00, group = "school", unit = "race", weight = "n", method = "shapley", precision = .000001 @@ -314,7 +311,6 @@ test_that("mutual_difference shapley_detailed marginal", { test_that("mutual_difference shapley_detailed with SE", { - testthat::skip_on_cran() diff <- mutual_difference(schools05, schools00, group = "school", unit = "race", weight = "n", method = "shapley_detailed", precision = .1, se = TRUE, n_bootstrap = 2 @@ -326,8 +322,6 @@ test_that("mutual_difference shapley_detailed with SE", { test_that("mutual_difference log base", { - testthat::skip_on_cran() - ret <- mutual_difference(test_data1, test_data2, "g", "u", weight = "n", method = "shapley", base = 2 ) @@ -352,7 +346,6 @@ test_that("mutual_difference log base", { test_that("difference same as mutual_total (zero weights)", { - testthat::skip_on_cran() # test with zero weights test_data1 <- data.frame( u = c(rep("a", 4), rep("b", 4), rep("c", 4)), @@ -402,7 +395,6 @@ test_that("difference same as mutual_total (zero weights)", { test_that("correctly identifies marginal/structural changes", { - testthat::skip_on_cran() test_data <- data.frame( u = c(rep("a", 2), rep("b", 2), rep("c", 2)), g = rep(c(1, 2), 3), @@ -442,7 +434,6 @@ test_that("correctly identifies marginal/structural changes", { test_that("errors", { - testthat::skip_on_cran() schools00 <- as.data.table(schools00) schools05 <- as.data.table(schools05) expect_error(mutual_difference( diff --git a/tests/testthat/test_mutual_expected.R b/tests/testthat/test_mutual_expected.R index 32b1ec2..c74ade8 100644 --- a/tests/testthat/test_mutual_expected.R +++ b/tests/testthat/test_mutual_expected.R @@ -1,3 +1,7 @@ +if (!identical(Sys.getenv("NOT_CRAN"), "true")) { + return() +} + library("segregation") context("test_mutual_expected") @@ -16,8 +20,6 @@ data2 <- data.frame( ) test_that("works both ways around", { - testthat::skip_on_cran() - expect_equal( mutual_expected(data1, "u", "g", weight = "n")[stat == "M under 0", est], mutual_expected(data1, "g", "u", weight = "n")[stat == "M under 0", est], @@ -32,8 +34,6 @@ test_that("works both ways around", { }) test_that("fixed margins = FALSE", { - testthat::skip_on_cran() - expect_equal( mutual_expected(data1, "u", "g", weight = "n", fixed_margins = FALSE)[stat == "M under 0", est], mutual_expected(data1, "g", "u", weight = "n", fixed_margins = FALSE)[stat == "M under 0", est], @@ -42,8 +42,6 @@ test_that("fixed margins = FALSE", { }) test_that("within argument", { - testthat::skip_on_cran() - within <- mutual_expected(school_ses, "ethnic_group", "school_id", within = "ses_quintile") # manually d <- data.table::as.data.table(school_ses) @@ -57,8 +55,6 @@ test_that("within argument", { test_that("dissimilarity", { - testthat::skip_on_cran() - expect_error(dissimilarity_expected(data1, "u", "g", weight = "n")) expect_equal(dissimilarity_expected(data1, "g", "u", n_bootstrap = 500, weight = "n")$est, 0.098, @@ -75,8 +71,6 @@ test_that("dissimilarity", { }) test_that("dissimilarity - Winship 1977", { - testthat::skip_on_cran() - # see table 2 mat <- matrix(c(rep(1, 1000), rep(9, 1000)), ncol = 2) d <- matrix_to_long(mat) @@ -104,8 +98,6 @@ test_that("dissimilarity - Winship 1977", { }) test_that("errors", { - testthat::skip_on_cran() - dat <- data.frame( u = rep(c(1, 2, 3, 4), 2), g = c(rep("a", 4), rep("b", 4)), diff --git a/tests/testthat/test_mutual_local.R b/tests/testthat/test_mutual_local.R index 0f58682..82eae95 100644 --- a/tests/testthat/test_mutual_local.R +++ b/tests/testthat/test_mutual_local.R @@ -1,3 +1,7 @@ +if (!identical(Sys.getenv("NOT_CRAN"), "true")) { + return() +} + library("segregation") context("test_mutual_local") @@ -13,8 +17,6 @@ localse <- mutual_local(test_data, "u", "g", weight = "n", se = TRUE, n_bootstra localbase2 <- mutual_local(test_data, "g", "u", weight = "n", base = 2) test_that("local calculation works", { - testthat::skip_on_cran() - expect_equal(sum(local[stat == "p", est]), 1) expect_equal(sum(local2[local2$stat == "p", est]), 1) expect_equal(sum(localse[localse$stat == "p", est]), 1) @@ -34,28 +36,20 @@ test_that("local calculation works", { }) test_that("return works", { - testthat::skip_on_cran() - expect_equal(nrow(local), 8) expect_equal(ncol(local), 3) }) test_that("bootstrapping works", { - testthat::skip_on_cran() - expect_equal(nrow(localse), 8) expect_equal(ncol(localse), 6) }) test_that("bootstrap attributes exists", { - testthat::skip_on_cran() - expect_equal(dim(attr(localse, "bootstrap")), c(10 * length(unique(test_data$g)) * 2, 3)) }) test_that("bootstrapping fails when sample size is non-integer", { - testthat::skip_on_cran() - test_data <- data.frame( u = c(rep("a", 4), rep("b", 4)), g = rep(c(1, 2, 3, 4), 2), @@ -70,8 +64,6 @@ test_that("bootstrapping fails when sample size is non-integer", { }) test_that("option wide works", { - testthat::skip_on_cran() - nowide <- mutual_local(test_data, "u", "g", weight = "n") nowide_se <- mutual_local(test_data, "u", "g", weight = "n", diff --git a/tests/testthat/test_mutual_total.R b/tests/testthat/test_mutual_total.R index d1d8450..3c461aa 100644 --- a/tests/testthat/test_mutual_total.R +++ b/tests/testthat/test_mutual_total.R @@ -1,3 +1,7 @@ +if (!identical(Sys.getenv("NOT_CRAN"), "true")) { + return() +} + library("segregation") context("test_mutual_total") @@ -10,8 +14,6 @@ test_data <- data.frame( ) test_that("mutual M works both ways around", { - testthat::skip_on_cran() - expect_equal( mutual_total(test_data, "u", "g", weight = "n")[stat == "M", est], mutual_total(test_data, "g", "u", weight = "n")[stat == "M", est] @@ -45,8 +47,6 @@ test_that("mutual M works both ways around", { }) test_that("between + within = total", { - testthat::skip_on_cran() - expect_equal( mutual_total(test_data, "u", "g", weight = "n")[stat == "M", est], mutual_total(test_data, "u", "supergroup", weight = "n")[stat == "M", est] + @@ -62,8 +62,6 @@ test_that("between + within = total", { p_12 <- sum(test_data[test_data$supergroup == 12, "n"]) / sum(test_data$n) p_34 <- sum(test_data[test_data$supergroup == 34, "n"]) / sum(test_data$n) test_that("within estimations are correct", { - testthat::skip_on_cran() - d_12 <- test_data[test_data$supergroup == 12, ] d_34 <- test_data[test_data$supergroup == 34, ] expect_equal( @@ -75,15 +73,11 @@ test_that("within estimations are correct", { }) test_that("H is correct", { - testthat::skip_on_cran() - ret <- mutual_total(test_data, "u", "g", weight = "n") expect_equal(ret[stat == "H", est] >= 0 & ret[stat == "H", est] <= 1, TRUE) }) test_that("bootstrapping works", { - testthat::skip_on_cran() - ret <- mutual_total(test_data, "u", "g", weight = "n", se = TRUE, n_bootstrap = 10) expect_equal(dim(ret), c(2, 5)) expect_equal(all(ret$se > 0), TRUE) @@ -97,15 +91,11 @@ test_that("bootstrapping works", { }) test_that("bootstrap attributes exists", { - testthat::skip_on_cran() - ret <- mutual_total(test_data, "u", "g", weight = "n", se = TRUE, n_bootstrap = 10) expect_equal(dim(attr(ret, "bootstrap")), c(2 * 10, 2)) }) test_that("bootstrapping fails when sample size is non-integer", { - testthat::skip_on_cran() - test_data <- data.frame( u = c(rep("a", 4), rep("b", 4)), g = rep(c(1, 2, 3, 4), 2), @@ -129,8 +119,6 @@ test_data <- data.frame( ) test_that("zero weights no problem", { - testthat::skip_on_cran() - expect_equal(dim(mutual_total(test_data, "u", "g", weight = "n", se = TRUE, n_bootstrap = 10 @@ -148,8 +136,6 @@ test_that("zero weights no problem", { }) test_that("gives errors", { - testthat::skip_on_cran() - expect_error(mutual_total("test_data", "u", "g", weight = "n"), "not a data.frame") expect_error( mutual_total(test_data[test_data$u == "c", ], "u", "g", weight = "n"), @@ -167,8 +153,6 @@ test_that("gives errors", { }) test_that("debiasing works correctly", { - testthat::skip_on_cran() - nose <- mutual_total(test_data, "u", "g", weight = "n") withse <- mutual_total(test_data, "u", "g", weight = "n", se = TRUE) expect_equal(nose$est, withse$est + withse$bias) diff --git a/tests/testthat/test_mutual_total_nested.R b/tests/testthat/test_mutual_total_nested.R index ffe2188..099c419 100644 --- a/tests/testthat/test_mutual_total_nested.R +++ b/tests/testthat/test_mutual_total_nested.R @@ -1,9 +1,11 @@ +if (!identical(Sys.getenv("NOT_CRAN"), "true")) { + return() +} + library("segregation") context("test_mutual_total_nested") test_that("works both ways around", { - testthat::skip_on_cran() - decomp <- mutual_total_nested(schools00, "race", c("state", "district", "school"), weight = "n" diff --git a/tests/testthat/test_mutual_within.R b/tests/testthat/test_mutual_within.R index 05dd4ca..fefc432 100644 --- a/tests/testthat/test_mutual_within.R +++ b/tests/testthat/test_mutual_within.R @@ -1,3 +1,7 @@ +if (!identical(Sys.getenv("NOT_CRAN"), "true")) { + return() +} + library("segregation") context("test_mutual_within") @@ -10,8 +14,6 @@ test_data <- data.frame( ) test_that("dimensions and bootstrapping", { - testthat::skip_on_cran() - within <- mutual_within(test_data, "u", "g", within = "supergroup", weight = "n" ) @@ -24,8 +26,6 @@ test_that("dimensions and bootstrapping", { }) test_that("bootstrap attributes exists", { - testthat::skip_on_cran() - within_se <- mutual_within(test_data, "u", "g", within = "supergroup", weight = "n", se = TRUE, n_bootstrap = 10 ) @@ -34,8 +34,6 @@ test_that("bootstrap attributes exists", { }) test_that("bootstrapping fails when sample size is non-integer", { - testthat::skip_on_cran() - test_data <- data.frame( u = c(rep("a", 4), rep("b", 4)), g = rep(c(1, 2, 3, 4), 2), @@ -56,8 +54,6 @@ test_that("bootstrapping fails when sample size is non-integer", { }) test_that("between + within = total", { - testthat::skip_on_cran() - total <- mutual_total(test_data, "u", "g", within = "supergroup", weight = "n") m <- total[stat == "M", est] h <- total[stat == "H", est] @@ -84,8 +80,6 @@ test_that("between + within = total", { }) test_that("option wide works", { - testthat::skip_on_cran() - nowide <- mutual_within(test_data, "u", "g", within = "supergroup", weight = "n" ) diff --git a/tests/testthat/test_plots.R b/tests/testthat/test_plots.R index 63a360f..08bd34d 100644 --- a/tests/testthat/test_plots.R +++ b/tests/testthat/test_plots.R @@ -1,3 +1,7 @@ +if (!identical(Sys.getenv("NOT_CRAN"), "true")) { + return() +} + library("segregation") context("plots") @@ -12,16 +16,12 @@ plot_entropy <- segplot(schools00, "race", "school", ) test_that("dimensions", { - testthat::skip_on_cran() - expect_equal(nrow(plot_majority$data), nrow(plot_seg$data)) expect_equal(nrow(plot_majority$data), nrow(plot_entropy$data)) expect_equal(nrow(plot_majority$data), nrow(plot_majority_fixed$data)) }) test_that("reference", { - testthat::skip_on_cran() - reference <- data.table::as.data.table(schools00) reference <- reference[, .(N = sum(n)), by = .(race)] reference[, p := N / sum(N)] @@ -51,8 +51,6 @@ test_that("reference", { }) test_that("axis_labels", { - testthat::skip_on_cran() - left <- segplot(schools00, "race", "school", weight = "n", axis_labels = "left") right <- segplot(schools00, "race", "school", weight = "n", axis_labels = "right") both <- segplot(schools00, "race", "school", weight = "n", axis_labels = "both") @@ -61,8 +59,6 @@ test_that("axis_labels", { }) test_that("segcurve", { - testthat::skip_on_cran() - expect_error(segcurve(schools00, "race", "school", weight = "n")) p1 <- segcurve(subset(schools00, race %in% c("white", "black")), diff --git a/vignettes/segregation.Rmd b/vignettes/segregation.Rmd index 3d42a46..72da5ed 100644 --- a/vignettes/segregation.Rmd +++ b/vignettes/segregation.Rmd @@ -98,10 +98,9 @@ Therefore, if the H index is used, it is important to specify the groups and uni For inference (discussed in more detail [below](#inference)), we can use bootstrapping to obtain standard errors and confidence intervals: ```{r} -# setting n_bootstrap = 100 here to speed up - more iterations are recommended in practice mutual_total(schools00, "race", "school", weight = "n", - se = TRUE, CI = .95, n_bootstrap = 100 + se = TRUE, CI = .95, n_bootstrap = 500 ) ``` @@ -201,10 +200,9 @@ mutual_local(schools00, "race", "school", weight = "n", wide = TRUE) Local segregation scores are based on much less data than the full M index, so it often makes sense to obtain confidence intervals. The following code plots the length of the 95% confidence interval in relation to the size of each school: ```{r} -# setting n_bootstrap = 100 here to speed up localse <- mutual_local(schools00, "race", "school", weight = "n", - se = TRUE, wide = TRUE, n_bootstrap = 100 + se = TRUE, wide = TRUE, n_bootstrap = 500 ) localse$lengthCI <- sapply(localse$ls_CI, base::diff) with(localse, plot(x = p, y = lengthCI, pch = 16, cex = 0.3)) @@ -233,10 +231,9 @@ The four main functions of the packages, `mutual_total()`, `mutual_within()`, `m To estimate standard errors and confidence intervals, use `se = TRUE`. The coverage of the confidence interval can be specified in the `CI` argument. The number of bootstrap iterations can be specified as well: ```{r} -# setting n_bootstrap = 100 here to speed up (se <- mutual_total(schools00, "race", "school", weight = "n", - se = TRUE, CI = .95, n_bootstrap = 100 + se = TRUE, CI = .95, n_bootstrap = 500 )) ``` The confidence intervals are based on the percentiles from the bootstrap distribution, and hence require a large number of bootstrap iterations for valid interpretation. The estimate `est` that is reported in the results has already been "debiased", i.e. the bias that has been estimated from the bootstrap distribution (which is reported in `bias`) has been subtracted from the usual maximum-likelihood estimate that we would obtain from `mutual_total` with `se = FALSE`. The confidence interval is centered around the debiased estimate. @@ -254,10 +251,9 @@ provide effectively the same coverage as the confidence intervals obtained from Whenever the bootstrap is used, the bootstrap distributions for each parameter are reported in an attribute `bootstrap` of the returned object. This can be used, for instance, to check whether the bootstrap distribution is skewed. The following code computes local segregation scores for all schools, and then shows a histogram of the bootstrap distribution for school C137_9, which has a very low local segregation score: ```{r} -# setting n_bootstrap = 100 here to speed up local <- mutual_local(schools00, "race", "school", weight = "n", - se = TRUE, CI = .95, n_bootstrap = 100 + se = TRUE, CI = .95, n_bootstrap = 500 ) # pick bootstrap distribution of local segregation scores for school C137_9 ls_school <- attr(local, "bootstrap")[school == "C137_9" & stat == "ls", boot_est] @@ -271,8 +267,7 @@ the package also provides a function `mutual_expected()` that simulates random c from the marginal distributions of your table. For the `schools00` dataset: ```{r} -# setting n_bootstrap = 100 here to speed up -mutual_expected(schools00, "race", "school", weight = "n", n_bootstrap = 100) +mutual_expected(schools00, "race", "school", weight = "n", n_bootstrap = 500) ``` Here, there is no concern about bias due to a small sample size.