Nothing
test_that("grouped ERRI returns finite scores", {
dat <- erri_example_data()
fit <- erri(dat, "year", "income", 2020, "region")
expect_s3_class(fit, "erri")
expect_equal(nrow(fit$results), 3L)
expect_true(all(is.finite(fit$results$ERRI)))
expect_true(all(fit$results$ERRI >= 0 & fit$results$ERRI <= 100))
expect_equal(sum(fit$weights), 1)
})
test_that("single-series analysis works", {
dat <- subset(erri_example_data(), region == "North")
fit <- erri(dat, "year", "income", 2020)
expect_equal(nrow(fit$results), 1L)
expect_true(is.finite(fit$results$ERRI))
})
test_that("all counterfactual methods work", {
dat <- subset(erri_example_data(), region == "North")
for (method in c("trend", "mean", "ar1")) {
expect_warning(
fit <- erri(dat, "year", "income", 2020, method = method),
NA
)
expect_s3_class(fit, "erri")
expect_equal(length(fit$trajectories$All$counterfactual), nrow(dat))
expect_true(all(is.finite(fit$trajectories$All$lower)))
expect_true(all(is.finite(fit$trajectories$All$upper)))
}
})
test_that("custom weights are normalized", {
dat <- erri_example_data()
w <- c(resistance = 2, loss = 1, recovery = 1,
strength = 1, stability = 1, transformation = 0)
fit <- erri(dat, "year", "income", 2020, "region", weights = w)
expect_equal(sum(fit$weights), 1)
expect_equal(unname(fit$weights["resistance"]), 1 / 3)
})
test_that("bootstrap and rank probabilities have expected structure", {
fit <- erri(erri_example_data(), "year", "income", 2020, "region")
boot <- erri_bootstrap(fit, R = 20, seed = 4)
expect_s3_class(boot, "erri_bootstrap")
expect_equal(nrow(boot$replicates), 60L)
p <- rank_probability(boot)
expect_equal(dim(p), c(3L, 3L))
expect_equal(unname(diag(p)), rep(0.5, 3L))
})
test_that("sensitivity weights sum to one", {
fit <- erri(erri_example_data(), "year", "income", 2020, "region")
sens <- erri_sensitivity(fit, R = 5, seed = 5)
wcols <- grep("^w_", names(sens), value = TRUE)
totals <- rowSums(sens[wcols])
expect_equal(totals, rep(1, length(totals)), tolerance = 1e-12)
})
test_that("shock screening returns ordered scores", {
dat <- subset(erri_example_data(), region == "Central")
out <- detect_shocks(dat, "year", "income", min_segment = 5)
expect_true(nrow(out) > 0)
expect_true(all(diff(out$score) <= 0))
})
test_that("input errors are informative", {
dat <- erri_example_data()
expect_error(erri(dat, "bad", "income", 2020), "not found")
expect_error(erri(dat, "year", "region", 2020), "numeric")
one_region <- subset(dat, region == "North")
expect_error(erri(one_region, "year", "income", 2011), "five pre-shock")
})
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.