Skip to content

Commit

Permalink
update with @SamuelBrand1 don't get confused feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
seabbs committed Oct 8, 2024
1 parent 6d92a2d commit 2d073eb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
9 changes: 3 additions & 6 deletions R/primary_censored_dist.R
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,9 @@ primary_censored_cdf.pcens_pweibull_dunif <- function(
# Use the lower incomplete gamma function
scaled_t <- (t * inv_scale)^shape
gamma_1k <- vapply(scaled_t, function(x) {
if (x <= 0) {
return(0)
}
pracma::gammainc(1 + inv_shape, x)["lowinc"]
}, numeric(1)) * inv_shape
scale * gamma_1k
}, numeric(1))
return(gamma_1k)
}

# Adjust q so that we have [q-pwindow, q]
Expand All @@ -311,7 +308,7 @@ primary_censored_cdf.pcens_pweibull_dunif <- function(
g_q_pwindow <- g(non_zero_q + pwindow)

Q_T <- 1 - pweibull_q_pwindow
Delta_g <- g_q_pwindow - g_q
Delta_g <- scale * (g_q_pwindow - g_q)
Delta_F_T <- pweibull_q_pwindow - pweibull_q

# Calculate Q_Splus using the analytical formula
Expand Down
5 changes: 2 additions & 3 deletions inst/stan/functions/primary_censored_dist_analytical_cdf.stan
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,11 @@ real primary_censored_lognormal_uniform_lcdf(data real d, real q, array[] real p
* @param shape Shape parameter (k) of the Weibull distribution
* @param scale Scale parameter (λ) of the Weibull distribution
*
* @return Log of g(t; λ, k) = γ(1 + 1/k, (t/λ)^k) / k - (t/λ) * exp(-(t/λ)^k)
* @return Log of g(t; λ, k) = γ(1 + 1/k, (t/λ)^k)
*/
real log_weibull_g(real t, real shape, real scale) {
real x = pow(t / scale, shape);
real log_gamma_term = log(gamma_p(1 + inv(shape), x)) - log(shape);
return log_gamma_term;
return log(gamma_p(1 + inv(shape), x));
}

/**
Expand Down

0 comments on commit 2d073eb

Please sign in to comment.