Join Nostr
2026-12-03 16:31:28 UTC

Executable Cameroon workbook replay

"""Replay GiveWell's November 2026 Cameroon column with fixed purchased doses.

Run: python replay.py grant.xlsx
Requires Python 3 and openpyxl. Source workbook and scenario definitions are in the report.
The paired local scenario uses both measured transitions in the same 67 starters.
"""
import argparse
import csv
import math
import sys

import openpyxl


def columns(workbook, name):
"""Read the common assumptions in H and the Cameroon column in M."""
rows = workbook[name].iter_rows(min_row=1, max_row=203, min_col=8,
max_col=13, values_only=True)
common, cameroon = {}, {}
for number, row in enumerate(rows, 1):
common[number], cameroon[number] = row[0], row[-1]
return common, cameroon


def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("workbook")
args = parser.parse_args()
book = openpyxl.load_workbook(args.workbook, read_only=True, data_only=True)
_, inputs = columns(book, "Inputs")
_, children = columns(book, "Children vaccinated")
efficacy_h, efficacy = columns(book, "Vaccine efficacy")
income_h, income = columns(book, "Income increases")
cea_h, cea = columns(book, "CEA")
funding_h, funding = columns(book, "LeverageFunging")
_, simple = columns(book, "Simple CEA")
book.close()
assert inputs[2] == "Cameroon" and inputs[28] == 1
assert inputs[29] == inputs[30] == 0

# Children vaccinated M39:40 and M52, M55. Penta estimates in Inputs M9:M11.
p2 = inputs[10] / inputs[9] * (1 + inputs[36])
conditional3 = inputs[11] / inputs[10] * (1 + inputs[37])
model_p3 = p2 * conditional3
model_conditional4 = conditional3 * (1 + inputs[38])
delivered = inputs[44] * (1 - inputs[45])
budget = inputs[61] # Includes research and indirect costs.
grant = inputs[59] # Excludes research.
risk = cea[31] # Under-five malaria mortality risk.
uptake = inputs[68]

# Effect per exact-dose group (one through four), Vaccine efficacy M90:M93
# and M101. Keep vaccine efficacy, timing and underlying malaria risk fixed.
periods = [6, 6, 12, 12, 12, 12]
mort_effect = [efficacy[i] for i in (93, 92, 91, 90)]
case_effect = [0.0] + [
sum(efficacy[start+i] * months for i, months in enumerate(periods)) / 60
for start in (63, 55, 47)
]
validity = (1 + efficacy_h[97]) * (1 + efficacy_h[98])
assert income[25] == 0 and funding[18] == 0

def scenario(name, second, third, fourth_given_third):
assert 0 < third <= second <= 1 and 0 <= fourth_given_third <= 1
fourth = third * fourth_given_third
cumulative = [1.0, second, third, fourth]
exact = [a-b for a, b in zip(cumulative, cumulative[1:] + [0.0])]
starters = delivered / sum(cumulative)
dose_counts = [starters * x for x in cumulative]
assert math.isclose(sum(dose_counts), delivered, rel_tol=1e-12)
mortality_reduction = sum(a*b for a, b in zip(exact, mort_effect)) * validity * efficacy_h[99]
incidence_reduction = sum(a*b for a, b in zip(exact, case_effect)) * validity
deaths = starters * risk * mortality_reduction # CEA M33
cases = starters * income[16] * incidence_reduction * 5 # Income increases M24
income_value = cases * income_h[36] * income_h[40]
mortality_value = deaths * cea_h[34]
benefit_per_dollar = (income_value + mortality_value) / budget
before_funding = benefit_per_dollar * (1 + funding_h[49]) * (1 + funding_h[50])

# LeverageFunging M30:M33, M62:M67. At fixed supply, total co-financing and
# delivery costs are fixed. The value displaced changes with program benefits.
domestic = inputs[44] * inputs[54] + delivered * inputs[48]
other = inputs[44] * inputs[47]
displacement = (
-grant * (budget / grant * before_funding - funding_h[54]) * funding[38]
-grant * (budget / grant * before_funding - funding_h[55]) * funding[39]
-grant * (before_funding - funding_h[57]) * funding[40]
-(domestic * funding_h[54] + other * funding_h[56]) * funding[41]
)
funding_adjustment = displacement / (budget * before_funding)
final_multiple = (benefit_per_dollar / cea_h[40] * (1 + cea_h[53])
* (1 + cea_h[54]) * (1 + funding_adjustment))
cost_per_equivalent = budget / deaths / (
(1 + cea_h[53]) * (1 + cea_h[60]) * (1 + funding_adjustment)
)
return dict(scenario=name, p2=second, p3=third, p4_given_3=fourth_given_third,
doses_per_starter=sum(cumulative), d1=starters, d2=dose_counts[1],
d3=dose_counts[2], d4=dose_counts[3], administered=sum(dose_counts),
mortality_reduction=mortality_reduction, cases_averted=cases,
u5_deaths_averted=deaths, expected_u5_deaths=deaths*uptake,
usd_per_u5_death=budget/deaths, funding_adjustment=funding_adjustment,
benchmark_multiple=final_multiple, usd_per_life_equivalent=cost_per_equivalent)

baseline = scenario("workbook", p2, model_p3, model_conditional4)
targets = dict(p2=children[52], p3=children[80], p4_given_3=children[56],
doses_per_starter=children[57], d1=children[82], d2=children[83],
d3=children[84], d4=children[85], administered=children[86],
mortality_reduction=cea[32], cases_averted=income[24],
u5_deaths_averted=cea[33], expected_u5_deaths=simple[37],
usd_per_u5_death=cea[38], funding_adjustment=funding[67],
benchmark_multiple=cea[58], usd_per_life_equivalent=cea[61])
for field, target in targets.items():
assert math.isclose(baseline[field], target, rel_tol=1e-8), (field, baseline[field], target)

writer = csv.DictWriter(sys.stdout, fieldnames=baseline)
writer.writeheader()
writer.writerow(baseline)
for name, third in [("published_lower", .4461), ("published_point", .5649),
("published_upper", .6837), ("raw_count", 39/67)]:
# Make Children vaccinated M55 = third / M52. Retain the M56 formula.
writer.writerow(scenario(name, p2, third, third/p2*(1 + inputs[38])))
for name, third in [("post_launch_d1", 1082.670/1964.210),
("post_launch_ordered_dates", 951.143/1964.210)]:
writer.writerow(scenario(name, p2, third, third/p2*(1 + inputs[38])))
for name, third in [("lower", .4461), ("point", .5649), ("upper", .6837)]:
writer.writerow(scenario("fixed_conditional4_" + name, p2, third, model_conditional4))
# S1 data, same 67 card starters aged 12–24 months. The two local
# transitions use unrounded survey weights for both D2 and D3.
local_second = 0.7794984127
local_third = 0.5647499490
writer.writerow(scenario("matched_local_d2_d3", local_second, local_third,
local_third/local_second*(1 + inputs[38])))


if __name__ == "__main__":
main()