Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions R/cfr_rolling.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ cfr_rolling <- function(data,
# guaranteed in the early stages of an outbreak due to poor data
p_mid_values <- cumulative_deaths / round(cumulative_outcomes)

# Handle edge cases where p_mid might be NA or Inf
p_mid_values[is.na(p_mid_values) | is.infinite(p_mid_values)] <- 0

if (any(is.infinite(p_mid_values) | p_mid_values < 1e-4)) {
message(
"Some daily ratios of total deaths to total cases with known outcome",
Expand Down
17 changes: 8 additions & 9 deletions R/estimate_severity.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,16 @@
.select_func_likelihood <- function(total_cases, poisson_threshold, p_mid) {
# NOTE: internal function is not input checked
# switch likelihood function based on total cases and p_mid
# Binomial approx
if (total_cases < poisson_threshold || (p_mid >= 0.05)) {
func_likelihood <- function(total_outcomes, total_deaths, pp) {
lchoose(round(total_outcomes), total_deaths) +
(total_deaths * log(pp)) +
(((total_outcomes) - total_deaths) * log(1.0 - pp))
}

# Default to binomial likelihood
func_likelihood <- function(total_outcomes, total_deaths, pp) {
lchoose(round(total_outcomes), total_deaths) +
(total_deaths * log(pp)) +
(((total_outcomes) - total_deaths) * log(1.0 - pp))
}

# Poisson approx
if ((total_cases >= poisson_threshold) && (p_mid < 0.05)) {
# Poisson approx - only switch to Poisson if conditions are met
if ((total_cases >= poisson_threshold) && (!is.na(p_mid)) && (p_mid < 0.05)) {
func_likelihood <- function(total_outcomes, total_deaths, pp) {
stats::dpois(
total_deaths, pp * round(total_outcomes),
Expand Down