Closed smwindecker closed 11 months ago
I found this code from Nick for a different purpose, I think adding a normalisation might be all we need?
# greta function for the probability mass function of a discretised lognormal
# distribution, truncated at max_days
discrete_lognormal_pmf <- function(days, meanlog, sdlog, max_days) {
lower <- lognormal_cdf(
q = days - 1,
meanlog = meanlog,
sdlog = sdlog
)
upper <- lognormal_cdf(
q = days,
meanlog = meanlog,
sdlog = sdlog
)
normalisation <- lognormal_cdf(
q = max_days,
meanlog = meanlog,
sdlog = sdlog
)
pmf_unnormalised <- upper - lower
pmf_unnormalised[days > max_days] <- 0
pmf <- pmf_unnormalised / normalisation
pmf
fixed in #4a6bcc0
discretised probability mass functions need to sum to 1, but sometimes don't because of rounding issues