Skip to content

Commit

Permalink
- Only implement non-parametric bootstrap for censored data.
Browse files Browse the repository at this point in the history
  • Loading branch information
joethorley committed Sep 23, 2024
1 parent 763fa04 commit d187237
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions R/hcp.R
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ hcp_weighted <- function(hcp, level, samples, min_pboot) {
weighted <- .weighted_fitdists(x)
unequal <- .unequal_fitdists(x)
estimates <- .list_estimates(x, all_estimates = FALSE)

if (parametric && ci && identical(censoring, c(NA_real_, NA_real_))) {
wrn("Parametric CIs cannot be calculated for inconsistently censored data.")
if (parametric && ci && !identical(censoring, c(0, Inf))) {
wrn("Parametric CIs cannot be calculated for censored data.")
ci <- FALSE
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/hc/fullyleft.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dist,proportion,est,se,lcl,ucl,wt,method,nboot,pboot,samples
average,0.05,0.0276014,0,0.0457722,0.0457722,1,parametric,10,1,numeric(0)
average,0.05,0.0276014,NA,NA,NA,1,parametric,0,NA,numeric(0)
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/hc/partialeftfull.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dist,proportion,est,se,lcl,ucl,wt,method,nboot,pboot,samples
lnorm,0.05,1.83148,0.798458,0.945173,3.2476,1,parametric,10,1,numeric(0)
lnorm,0.05,1.83148,NA,NA,NA,1,parametric,0,NA,numeric(0)
12 changes: 6 additions & 6 deletions tests/testthat/test-hc.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ test_that("ssd_hc doesn't calculate cis with inconsistent censoring", {
set.seed(10)
expect_warning(
hc <- ssd_hc(fits, ci = TRUE, nboot = 10),
"^Parametric CIs cannot be calculated for inconsistently censored data[.]$"
"^Parametric CIs cannot be calculated for censored data[.]$"
)
expect_identical(hc$se, NA_real_)
})
Expand All @@ -276,7 +276,8 @@ test_that("ssd_hc works with fully left censored data", {
data$Conc <- 0
fits <- ssd_fit_dists(data, right = "Conc2", dists = c("lnorm", "llogis"))
set.seed(10)
hc <- ssd_hc(fits, ci = TRUE, nboot = 10, ci_method = "weighted_arithmetic")
expect_warning(hc <- ssd_hc(fits, ci = TRUE, nboot = 10, ci_method = "weighted_arithmetic"),
"^Parametric CIs cannot be calculated for censored data[.]$")
expect_snapshot_data(hc, "fullyleft")
})

Expand All @@ -288,7 +289,7 @@ test_that("ssd_hc warns with partially left censored data", {
set.seed(100)
fits <- ssd_fit_dists(data, dists = "lnorm", right = "right")
expect_warning(hc <- ssd_hc(fits, ci = TRUE, nboot = 10, average = FALSE),
"Parametric CIs cannot be calculated for inconsistently censored data\\.")
"Parametric CIs cannot be calculated for censored data\\.")
expect_snapshot_data(hc, "partialeft")
})

Expand All @@ -302,7 +303,6 @@ test_that("ssd_hc works with fully left censored data", {
fits <- ssd_fit_dists(data, dists = "lnorm", right = "right")
hc <- ssd_hc(fits, ci = TRUE, nboot = 10, average = FALSE)
expect_snapshot_data(hc, "partialeftfull")
expect_gt(hc$ucl, hc$est)
})

test_that("ssd_hc works with partially left censored data non-parametric", {
Expand All @@ -325,7 +325,7 @@ test_that("ssd_hc not work partially censored even if all same left", {
set.seed(10)
expect_warning(
hc <- ssd_hc(fits, ci = TRUE, nboot = 10),
"^Parametric CIs cannot be calculated for inconsistently censored data[.]$"
"^Parametric CIs cannot be calculated for censored data[.]$"
)
})

Expand All @@ -338,7 +338,7 @@ test_that("ssd_hc doesn't works with inconsisently censored data", {
set.seed(10)
expect_warning(
hc <- ssd_hc(fits, ci = TRUE, nboot = 10),
"^Parametric CIs cannot be calculated for inconsistently censored data[.]$"
"^Parametric CIs cannot be calculated for censored data[.]$"
)
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-hp.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ test_that("ssd_hp doesn't calculate cis with inconsistent censoring", {
set.seed(10)
expect_warning(
hp <- ssd_hp(fits, 1, ci = TRUE, nboot = 10),
"^Parametric CIs cannot be calculated for inconsistently censored data[.]$"
"^Parametric CIs cannot be calculated for censored data[.]$"
)
expect_identical(hp$se, NA_real_)
})
Expand Down

0 comments on commit d187237

Please sign in to comment.