Skip to content

Commit

Permalink
BUG FIX: correct classification of "super" endemic areas
Browse files Browse the repository at this point in the history
need **both** pe_obs_p and pe_alt_obs_p to be highly significant (> 0.99)
  • Loading branch information
joelnitta committed Oct 13, 2021
1 parent 09642ee commit 2f3318c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/cpr_classify_endem.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ cpr_classify_endem <- function(df) {
# (PE_orig is consistently higher than PE_alt across the random realisations)
# b) Else if RPE is significantly low then we have neo-endemism
# (PE_orig is consistently lower than PE_alt across the random realisations)
# c) Else we have mixed age endemism in which case
# c) Else we have mixed age endemism in which case
# i) If both PE_orig and PE_alt are highly significant (p<0.01) then we
# have super endemism (high in both palaeo and neo)
# ii) Else we have mixed (some mixture of palaeo, neo and non endemic)
Expand All @@ -61,7 +61,7 @@ cpr_classify_endem <- function(df) {
endem_type = dplyr::case_when(
(pe_obs_p_upper %greater% 0.95 | pe_alt_obs_p_upper %greater% 0.95) & rpe_obs_p_upper %greater% 0.975 ~ "paleo",
(pe_obs_p_upper %greater% 0.95 | pe_alt_obs_p_upper %greater% 0.95) & rpe_obs_p_lower %greater% 0.975 ~ "neo",
pe_obs_p_upper %greater% 0.99 | pe_alt_obs_p_upper %greater% 0.99 ~ "super",
pe_obs_p_upper %greater% 0.99 & pe_alt_obs_p_upper %greater% 0.99 ~ "super",
pe_obs_p_upper %greater% 0.95 | pe_alt_obs_p_upper %greater% 0.95 ~ "mixed",
TRUE ~ "not significant"
)
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-cpr_classify_endem.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ test_that("Input is valid", {
)
})

#' @srrstats {G5.4a} Correctness tests on trivial examples for new implementations
test_that("Calculations work", {
dummy_res <- data.frame(
pe_obs_p_upper = c(0.99, 0.10, 0.999, 0.999, 0.10, 0.10),
pe_alt_obs_p_upper = c(0.10, 0.99, 0.999, 0.10, 0.10, 0.10),
rpe_obs_p_upper = c(0.99, 0.10, 0.10, 0.10, 0.10, 0.99),
rpe_obs_p_lower = c(0.10, 0.99, 0.10, 0.10, 0.10, 0.10)
) %>% cpr_classify_endem()
expect_equal(dummy_res$endem_type[[1]], "paleo")
expect_equal(dummy_res$endem_type[[2]], "neo")
expect_equal(dummy_res$endem_type[[3]], "super")
expect_equal(dummy_res$endem_type[[4]], "mixed")
expect_equal(dummy_res$endem_type[[5]], "not significant")
expect_equal(dummy_res$endem_type[[6]], "not significant")
})

test_that("Output is formatted as expected", {
expect_s3_class(
cpr_classify_endem(rand_test),
Expand Down

0 comments on commit 2f3318c

Please sign in to comment.