From 79a12aa1dec73ea09772334f4ba3b0bbd2881d53 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 8 Oct 2024 13:33:49 +0100 Subject: [PATCH] add t > 0 enforcement for lower incomplete gamma --- R/primary_censored_dist.R | 4 +--- tests/testthat/test-primary_censored_dist.R | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/R/primary_censored_dist.R b/R/primary_censored_dist.R index 299499b..98fdb92 100644 --- a/R/primary_censored_dist.R +++ b/R/primary_censored_dist.R @@ -283,11 +283,9 @@ primary_censored_cdf.pcens_pweibull_dunif <- function( g <- function(t) { # Use the lower incomplete gamma function + t <- pmax(t, 0) scaled_t <- (t * inv_scale)^shape vapply(scaled_t, function(x) { - if (x <= 0) { - return(0) - } pracma::gammainc(x, 1 + inv_shape)["lowinc"] }, numeric(1)) } diff --git a/tests/testthat/test-primary_censored_dist.R b/tests/testthat/test-primary_censored_dist.R index f6717aa..7f022f1 100644 --- a/tests/testthat/test-primary_censored_dist.R +++ b/tests/testthat/test-primary_censored_dist.R @@ -258,8 +258,8 @@ test_that( dprimary <- dunif shapes <- c(0.5, 1, 2, 3) - scales <- c(0.5, 1, 2, 5) - pwindows <- c(1, 2, 5, 10) + scales <- c(0.5, 1, 2) + pwindows <- c(1, 2, 5) for (shape in shapes) { for (scale in scales) {