Public
Edited
Feb 7, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof rp_model = cell(`chicken_years_affected_per_dollar_rp = {
chickens_affected_every_year = 240M to 390M
follow_through_rate = 0.48 to 0.84
mean_years_of_impact = 4 to 36
costs = 36M to 84M
chickens_affected_per_dollar = chickens_affected_every_year * follow_through_rate * mean_years_of_impact / costs
average_lifespan_of_chicken = 1.1 to 1.5
average_lifespan_of_chicken * chickens_affected_per_dollar
}
chicken_years_affected_per_dollar_rp`, [], {distributionChartSettings: {showSummary: true}})
Insert cell
Insert cell
viewof malaria_consortium = cell(`malaria_consortium = ${await importSampleSetDist(FileAttachment("malaria_consortium-4.csv"))} * 0.4
malaria_consortium`, [], {distributionChartSettings: {showSummary: true}})
Insert cell
Insert cell
viewof benefit_from_saved_chicken = cell(`benefit_from_saved_chicken = beta(0.5, 1.3)`, [], {distributionChartSettings: {showSummary: true}})

Insert cell
viewof cost_effectiveness_humane_league_daly = cell(`cost_effectiveness_humane_league_daly = chicken_years_affected_per_dollar_rp * benefit_from_saved_chicken
Plot.dists({dists: [{name: "Malaria Consortium", value: malaria_consortium}, {name: "The Humane League", value: cost_effectiveness_humane_league_daly}]})`, [rp_model, malaria_consortium, benefit_from_saved_chicken], {distributionChartSettings: {showSummary: true}})
Insert cell
viewof chance_humane_league_is_better = cell(`chance_humane_league_is_better = mean(SampleSet.map2(malaria_consortium, cost_effectiveness_humane_league_daly, {|x, y| x < y ? 1 : 0}))`, [malaria_consortium, benefit_from_saved_chicken, cost_effectiveness_humane_league_daly])
Insert cell
Insert cell
Insert cell
Insert cell
viewof value_of_information_functions = cell(`voi(c) = mean(SampleSet.mapN(c, {|xs| max(xs)}))
vou(c) = max(map(c, {|x| mean(x)}))
vpi(x) = voi(x) - vou(x)
vpi_cost(x) = {
my_voi = voi(x)
cost_ratio = (my_voi - vou(x)) / my_voi
cost_ratio
}
0`)
Insert cell
Insert cell
viewof individual_vpi = cell(`degen(x) = SampleSet.fromDist(mx(mean(x)))
cost_ratio = vpi_cost([${to_research.includes("Malaria Consortium") ? "malaria_consortium" : "degen(malaria_consortium)"}, ${to_research.includes("The Humane League") ? "cost_effectiveness_humane_league_daly" : "degen(cost_effectiveness_humane_league_daly)"}])
cost_ratio`,[value_of_information_functions, cost_effectiveness_humane_league_daly, malaria_consortium])
Insert cell
Insert cell
Insert cell
viewof fistulaVPIAnalysis = cell(`params = {
chickens_affected_every_year: 240M to 390M,
follow_through_rate: 0.48 to 0.84,
mean_years_of_impact: 4 to 36,
costs: 36M to 84M,
average_lifespan_of_chicken: 1.1 to 1.5,
benefit_from_saved_chicken: beta(0.5, 1.3)
}

chicken_years_affected_per_dollar_rp(x) = {
chickens_affected_per_dollar = x.chickens_affected_every_year * x.follow_through_rate * x.mean_years_of_impact / x.costs
SampleSet.fromDist(x.average_lifespan_of_chicken * chickens_affected_per_dollar * x.benefit_from_saved_chicken)
}
mapDict(x, f) = Dict.fromList(map(Dict.keys(x), {|key| [key, f(x[key])]}))
mapSet(x, key, value) = Dict.merge(x, Dict.fromList([[key, value]]))
to_mean(x) = mapDict(x, mean)
vpi_analysis(f, params, other) = {
mean_params = to_mean(params)
Dict.fromList(map(Dict.keys(params), {|key| [key, {
possible_results = f(mapSet(mean_params, key, params[key]))
vou = max([mean(possible_results), other])
possible_decisions = SampleSet.map(possible_results, {|s| max([s, other])})
voi = mean(possible_decisions)
vpi = voi - vou
vpi / voi * 93000000
}]}))
}
vpi_analysis(chicken_years_affected_per_dollar_rp, params, mean(malaria_consortium))`, [malaria_consortium])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
formatCurrency =number => new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(number)
Insert cell
formatFloat = x => new Intl.NumberFormat('en-US', {maximumSignificantDigits: 3}).format(x)
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more