Created
February 19, 2025 09:48
-
-
Save adamkucharski/c6f169062bee01601979a2b678437d57 to your computer and use it in GitHub Desktop.
Exposure in finalsize population
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define R0 | |
r_number <- 1.4 | |
# Final size model | |
attack_rate <- finalsize::final_size(r_number)$n_infected | |
print(attack_rate) | |
# Calculate total exposures over the whole epidemic | |
# (note: later in epidemic, now-immune people will be re-exposed) | |
expected_exposures <- attack_rate*r_number | |
# Calculate the expected proportion of the population with at least exposure | |
expected_proportion_exact <- function(X, # total exposures | |
N # total population size | |
) { | |
return(1 - (1 - 1/N)^X) | |
} | |
# Can for large N, can approximate with: | |
expected_proportion <- function(Y) { | |
return(1 - exp(-Y)) | |
} | |
# where Y = X/N | |
# Calculate proportion exposed at least once: | |
result_exact <- expected_proportion(expected_exposures) | |
# Probability exposed k times follows a binomial, but because X and N large, can use | |
# Poisson approximation with lambda = X/N | |
exposed_k_times <- 0:5 | |
probability_exposed <- dpois(exposed_k_times, lambda = expected_exposures) | |
# Plot results | |
plot(exposed_k_times, probability_exposed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment