Signature
P_inf = 1 - (1 - p)^k
| Inputs | Definition | Unit |
|---|---|---|
p | Probability that one contact with an infectious agent transmits infection during the step, the same for every contact, at least 0 and at most 1 | probability per contact |
k | Number of contacts the agent has with infectious agents during the step, a whole number of zero or more; contacts with agents who are not infectious are not counted | contacts per step |
P_inf | Probability that a susceptible agent is infected at least once during one model step, written P in the article | probability per step |
|---|
Function
Agent state update function of an agent-based model
Maps the state of agent i at step t, the set of agents in contact with it, the state of the environment, the intervention in force and a random input to the state of that agent at step t+1, the rule X_i(t+1) = F(X_i(t), N_i(t), E(t), A(t), U_i(t)) of the article. In an infection model the rule for a susceptible agent reduces to a per-step infection probability from its k infectious contacts, the complement of the binomial probability of no events (HE-FM-BINOM-002), followed by a comparison of the agent's own uniform random number with that probability. A per-contact probability built from a transmission rate uses the constant-rate conversion HE-FM-TP-001, and a probability observed over another interval is rescaled with HE-FM-TP-003; neither is restated here. Population outputs are averaged over independent runs, and the Monte Carlo standard error of such a mean is the standard deviation across runs divided by the square root of the number of runs, the form of HE-FM-ANTV-002 with one observation per run and the divisor of HE-FM-BSE-001. This package adds the number of runs needed for a target standard error of a mean and of a share of runs. Attack rates and the final size relation are in HE-FN-ATR-001 and HE-CF-ATR-001, the cohort simulation without interaction is HE-FN-CSIM-001, and expected onward infections and the reproduction number belong to the Basic Reproduction Number page. Notation follows the Agent-Based Model article.
Computational function
Computational function: seeded one-step agent simulation checked against the analytic infection probability
Runs a small seeded agent simulation of one step and checks it against the analytic infection probability HE-FM-ABM-001. It takes a number of susceptible agents, a per-contact transmission probability, the number of infectious contacts per agent under a comparator and under a programme, and a base seed, and returns the simulated and analytic shares infected under each, the Monte Carlo standard error of the simulated share, a pass flag and the simulated infections averted per agent. Each agent i draws one uniform number per contact from its own stream, seeded with seed + i, and is infected when any draw is below p, so the simulation works contact by contact and never uses the formula itself. The programme removes each agent's last contact and keeps the draws for the others, so the two strategies share common random numbers.
Inputs and outputs:
N_agentsis the number of susceptible agents simulated, required, a whole number above zero;pis the per-contact transmission probability, at least 0 and at most 1;k_3is the number of infectious contacts per agent under the comparator andk_2under the programme, whole numbers withk_2at mostk_3;seedis the base seed;n_3andn_2are the simulated numbers infected;P_3andP_2are the analytic probabilities from HE-FM-ABM-001;Phat_3andPhat_2are the simulated shares;MCSE_3is the binomial standard error ofPhat_3atP_3, as in HE-FM-BINOM-004;okis 1 whenPhat_3lies within three standard errors ofP_3;D_hatis the simulated share of agents whose infection the programme averts.Assumption: All agents are susceptible at the start of the step, contacts transmit independently with the same probability, and each agent's stream is used only by that agent, as in the per-agent seed of Chhatwal and He. Separate runs take base seeds at least
N_agentsapart, because with seed + i runs with base seeds 2026 and 2027 reuse 9,999 of the same 10,000 agent streams and are not independent (HE-AS-ABM-007).Worked example (Article's three and two contacts, 10,000 agents, seed 2026 in R): The R code below returns 2,675 infected agents with three contacts and 1,867 with two. The simulated share 0.2675 is 0.79 standard errors below the analytic 0.271, so the test passes, and the simulated share averted, 0.0808, is close to the analytic 0.081. Python's generator gives different draws for the same seeds, 2,784 and 1,935 infected, 1.66 standard errors above 0.271, and also passes.
N_agents = 10000; p = 0.10; k_3 = 3; k_2 = 2; n_3 = 2675; n_2 = 1867; P_3 = 0.271; P_2 = 0.19; Phat_3 = 0.2675; Phat_2 = 0.1867; MCSE_3 = 0.00444; ok = 1; D_hat = 0.0808Worked example (Single contact limiting case): With one contact under both strategies the analytic share is the per-contact probability 0.10, the R run gives 980 infected agents out of 10,000, 0.67 standard errors below it, and no infection is averted.
N_agents = 10000; p = 0.10; k_3 = 1; k_2 = 1; n_3 = 980; n_2 = 980; P_3 = 0.1; P_2 = 0.1; Phat_3 = 0.098; Phat_2 = 0.098; MCSE_3 = 0.003; ok = 1; D_hat = 0Excel: RAND cannot be seeded, so the draws are generated once and pasted as values. With one row per agent and three columns of draws in
B2:D10001,=IF(MIN(B2:D2)<ContactTransProb,1,0)filled down gives a column named InfectedThree and=IF(MIN(B2:C2)<ContactTransProb,1,0)a column named InfectedTwo that shares the first two draws.=AVERAGE(InfectedThree)and=AVERAGE(InfectedTwo)return the simulated shares and=AVERAGE(InfectedThree)-AVERAGE(InfectedTwo)the share averted.R:
abm_step <- function(N, p, k_3, k_2, seed) { x <- sapply(1:N, function(i) { set.seed(seed+i); u <- runif(k_3); c(any(u < p), any(u[1:k_2] < p)) }); P_3 <- 1-(1-p)^k_3; MCSE_3 <- sqrt(P_3*(1-P_3)/N); c(n_3 = sum(x[1, ]), n_2 = sum(x[2, ]), P_3 = P_3, MCSE_3 = MCSE_3, ok = as.numeric(abs(mean(x[1, ])-P_3) <= 3*MCSE_3), crn = sum(x[2, ] > x[1, ])) }Run asabm_step(10000, 0.10, 3, 2, 2026).Python:
def abm_step(N, p, k_3, k_2, seed): import random, math; U = [[g.random() for _ in range(k_3)] for g in (random.Random(seed+i) for i in range(1, N+1))]; x_3 = [any(u < p for u in r) for r in U]; x_2 = [any(u < p for u in r[:k_2]) for r in U]; P_3 = 1-(1-p)**k_3; MCSE_3 = math.sqrt(P_3*(1-P_3)/N); return sum(x_3), sum(x_2), P_3, MCSE_3, int(abs(sum(x_3)/N-P_3) <= 3*MCSE_3), sum(b and not a for a, b in zip(x_3, x_2))Run asabm_step(10000, 0.10, 3, 2, 2026).Test (Simulated share within three standard errors of the analytic probability): The share infected with three contacts lies within three binomial standard errors of the analytic value. Expected result TRUE. FALSE shows a simulation that infects an agent when one draw falls below k times p, which with the per-agent seeds of the R code and base seed 2026 gives a share of 0.2897, about 4.2 standard errors above 0.271. Excel check
=ABS(AVERAGE(InfectedThree)-(1-(1-ContactTransProb)^3))<=3*SQRT((1-(1-ContactTransProb)^3)*(1-ContactTransProb)^3/ROWS(InfectedThree))Test (Common random numbers across strategies): No agent is infected with two contacts and not with three. Expected result TRUE. FALSE shows that the programme column drew its own RAND values. Excel check
=SUMPRODUCT(--(InfectedTwo>InfectedThree))=0Common error (Fresh seeds for the programme): Drawing new numbers for the programme leaves the expected share averted at 0.081 but raises the variance of the per-agent difference about 4.7 fold (HE-ER-ABM-003), so for 10,000 agents the standard error of the share averted rises from about 0.0027 to about 0.0059.
Source: Britton T. Basic stochastic transmission models and their inference. arXiv preprint 1801.09594, 2018. Section 2.3, which gives the probability of infection as the complement of (1 minus p) raised to the number of infectives when contacts are independent. Chhatwal J, He T. Economic evaluations with agent-based modelling, an introduction. PharmacoEconomics. 2015;33(5):423-433. Section 3.1, which assigns a unique random seed to each agent to implement common random numbers.
P_3 = 1 - (1 - p)^k_3; P_2 = 1 - (1 - p)^k_2; Phat_3 = n_3 / N_agents; Phat_2 = n_2 / N_agents; MCSE_3 = sqrt(P_3 * (1 - P_3) / N_agents); ok = abs(Phat_3 - P_3) <= 3 * MCSE_3; D_hat = Phat_3 - Phat_2
Try this function
Implementations
Excel
Agent infection probability from named cells in Excel
With the per-contact probability in a cell named ContactTransProb and the number of infectious contacts in InfectiousContacts, the formula returns the per-step probability of infection. The tests below name the result cell InfectionProbStep.
=1-(1-ContactTransProb)^InfectiousContacts
Assumptions
Independent transmission across the contacts of one agent in a step
Each contact transmits independently of the others and with the same probability p, the condition of the discrete-time Reed-Frost chain binomial model described by Britton. Where contacts carry different risks, for example a household contact and a casual one, the same independence condition multiplies the separate escape probabilities, and a single p no longer applies.
Per-contact probability defined for the model step length
p refers to one contact within one model step. When the source reports a transmission rate per unit of contact time, the probability is formed with the constant-rate conversion HE-FM-TP-001; Britton writes the Reed-Frost contact probability in this way, as one minus the exponential of minus the contact rate to a specific individual multiplied by the infectious period. A probability measured over a different interval is rescaled with HE-FM-TP-003 before it enters the formula.
Agent susceptible at the start of the infection step
The formula applies to an agent who is susceptible at the start of the step. Infected agents follow their own rules in the same step, for example progression through a Markov chain of disease stages within each infected agent as in the case study of Chhatwal and He.
Worked examples
Article's three contacts at a 0.10 transmission probability
In the article's illustrative example a susceptible agent has three contacts with infectious agents in a day, each transmitting with probability 0.10. The chance of escaping all three is 0.9 cubed, or 0.729, so the daily probability of infection is 0.271.
p = 0.10; k = 3; P_inf = 0.271
Article's programme cutting contacts to two a day
The article's illustrative programme cuts the contacts to two a day, so the probability of infection becomes 1 minus 0.81, or 0.19. Removing one contact in three lowers the daily risk by 0.081, about 30% of 0.271, slightly less than the one third that the sum k times p would suggest.
p = 0.10; k = 2; P_inf = 0.19
Single infectious contact as a limiting case of the agent infection probability
With one infectious contact the formula returns the per-contact probability itself, here an illustrative 0.10, which checks that P_inf and p are on the same per-step basis.
p = 0.10; k = 1; P_inf = 0.1
Ten contacts at the case study's per-contact probability of 0.005
Chhatwal and He's case study uses a transmission probability per contact of 0.005. For an illustrative agent with 10 infectious contacts in one annual cycle the probability of infection is 1 minus 0.995 to the power 10, about 0.0489, close to the sum of 0.05 because each contact carries a small risk.
p = 0.005; k = 10; P_inf = 0.0489
Common errors
Adding contact risks instead of combining escape probabilities
Summing the risks gives 3 times 0.10, or 0.30, for the article's agent instead of 0.271, about 11% too high, and for 20 such contacts gives 2.0, an impossible probability, where the formula gives about 0.878.
Counting every contact rather than infectious contacts in k
If an agent meets 10 people of whom 3 are infectious and k is set to 10, the probability with p of 0.10 is about 0.651 instead of 0.271. k counts only contacts with agents who are infectious at the start of the step.
Sources
Britton on the Reed-Frost chain binomial infection probability
Britton T. Basic stochastic transmission models and their inference. arXiv preprint 1801.09594, 2018. Section 2.3, The Reed-Frost epidemic and chain-binomial models, which states that a susceptible individual escapes infection in the next generation with probability (1 minus p) raised to the number infected in the previous generation, that the probability of infection is the complementary probability, and that in the Reed-Frost epidemic an infective has independent infectious contacts with each other individual, each with probability p equal to one minus the exponential of minus beta times iota over n.
Chhatwal and He case study on transmission probability per contact
Chhatwal J, He T. Economic evaluations with agent-based modelling, an introduction. PharmacoEconomics. 2015;33(5):423-433. The caption of Figure 3, in which each infected agent can transmit the infection to other susceptible people with some probability per contact, section 5.4, in which an infected person could come into contact with several susceptible persons in the contact radius in each cycle, and Table 1 of the case study, which gives a transmission probability per contact of 0.005 and a cycle length of 1 year.
Canonical Identity
Stable URI · Machine-readable · Resolvable · CC BY 4.0
