Public
Edited
Mar 15, 2023
Insert cell
Insert cell
Insert cell
Insert cell
import {cea_functions,cell,stylesheet} from "@falk-lieder/cea_library"
Insert cell
stylesheet
Insert cell
Insert cell
import {cost_effectiveness_of_intervention_bs,cost_effectiveness_of_intervention_bs_WELLBY,ce_of_previous_interventions} from "@falk-lieder/cea-baumsteiger"
Insert cell
Insert cell
viewof uncertainty = cell(`

ce_new_bs_WELLBYs_per_1000USD


`,[cost_effectiveness_of_intervention_bs_WELLBY,ce_of_previous_interventions,cea_functions],{distributionChartSettings: {showSummary: true, title:"Figure 1: Probability distribution of the cost-effectiveness of promoting prosocial behavior prior to running an RCT"}})
Insert cell
Insert cell
viewof value_of_perfect_information = cell(`

max_ce_in_current_situation = max([mean(ce_StrongMinds_WELLBYs),mean(ce_new_bs_WELLBYs_per_1000USD)])
expected_max_ce_in_new_situation = mean(max(ce_new_bs_WELLBYs_per_1000USD->SampleSet.fromDist,mean(ce_StrongMinds_WELLBYs)))
expected_gain_in_ce = expected_max_ce_in_new_situation - max_ce_in_current_situation

`, [cost_effectiveness_of_intervention_bs_WELLBY,ce_of_previous_interventions],{distributionChartSettings: {showSummary: true}})
Insert cell
Insert cell
viewof more_good = cell(`

budget = 10M to 1B

value_of_perfect_information = budget/1000 * expected_gain_in_ce

`, [value_of_perfect_information],{distributionChartSettings: {showSummary: true}})
Insert cell
Insert cell
viewof willingness_to_pay = cell(`

// How much money is that worth, given how much it costs to create that many WELLBYs with the current best intervention?
value_of_information_in_usd = value_of_perfect_information/max_ce_in_current_situation*1000 //12.7M USD

`, [more_good,value_of_perfect_information],{distributionChartSettings: {showSummary: true}})
Insert cell
Insert cell
viewof relative_willingness_to_pay = cell(`

value_of_information_per_dollar_in_budget = value_of_information_in_usd / budget //34 cents per dollar in the budget

`, [willingness_to_pay,more_good,value_of_perfect_information],{distributionChartSettings: {showSummary: true}})
Insert cell
Insert cell
viewof posterior = cell(`

prior_ce_new = ce_new_bs_WELLBYs_per_1000USD
ce_RCT = 30
sigma_obs = [10,1,0.1,0.05]

posterior(prior, obs, sigma_obs) ={
mu_sigma_prior = fit_logNormal(prior_ce_new)
posterior_mu_sigma = posterior_log_normal(mu_sigma_prior[0],mu_sigma_prior[1],ce_RCT,sigma_obs)
lognormal(posterior_mu_sigma[0],posterior_mu_sigma[1])
}

{distributions: [{name:"prior", distribution:prior_ce_new},{name:"RCT with SE=10", distribution: posterior(prior_ce_new,ce_RCT,sigma_obs[0])},{name:"RCT with SE=1", distribution: posterior(prior_ce_new,ce_RCT,sigma_obs[1])}, {name:"RCT with SE=0.1", distribution: posterior(prior_ce_new,ce_RCT,sigma_obs[2])}, {name:"RCT with SE=0.05", distribution: posterior(prior_ce_new,ce_RCT,sigma_obs[3])}]}


`,[cost_effectiveness_of_intervention_bs_WELLBY,cea_functions,ce_of_previous_interventions],{distributionChartSettings: {showSummary: true}})
Insert cell
Insert cell
viewof value_of_imperfect_information = cell(`

/* Calculate the value of the partial information conveyed by the measurement observed_ce, given the log-normal prior and (LogN(mu_prior,sigma_prior)) and the log-normal likelihood function LogN(observed_ce,sigma_obs)
*/

value_of_partial_information_lognormal(mu_prior,sigma_prior,observed_ce,sigma_obs,budget,previous_best) = {

posterior_mu_sigma = posterior_log_normal(mu_prior,sigma_prior,observed_ce,sigma_obs)
ev_ce_new_posterior = exp(posterior_mu_sigma[0]+1/2*posterior_mu_sigma[1]^2)
max_ce_new = max(ev_ce_new_posterior->SampleSet.fromDist,mean(previous_best))
max_ce_prev = max([mu_prior,mean(previous_best)])
(max_ce_new-max_ce_prev) * budget
}


`,[cost_effectiveness_of_intervention_bs,cea_functions,ce_of_previous_interventions],{distributionChartSettings: {showSummary: true}})
Insert cell
Insert cell
viewof expected_value_of_imperfect_information = cell(`

/* Calculate the expected value of conducting a randomized controlled trial that measures the cost-effectiveness to a given level of accuracy (i.e., up to a standard error of plus/minus sigma_obs).
This function assumes that the observed cost-effectiveness estimate will be drawn from a log-normal distribution whose expected value is the true value and whose standard deviation is sigma_obs. It integrates the value of observing a sample from that distribution across the possible noisy measurements of a given true value and across possible true values. To integrate across possible true values it uses our probabilistic prediction of the expected cost-effectiveness as a prior on the true cost-effectiveness.
*/

expected_value_of_partial_information_lognormal(prior,std_obs,budget,previous_best) = {
mu_sigma_prior = fit_logNormal(prior)
true_value = max(lognormal(mu_sigma_prior[0],mu_sigma_prior[1])->SampleSet.fromDist,0.0001)
observed_ce = max(lognormal_from_mean_and_std(true_value,std_obs),0.0001)

sigma_obs = sqrt(log(std_obs^2/mean(prior)^2 +1 ))
value_of_partial_information_lognormal(mu_sigma_prior[0],mu_sigma_prior[1],observed_ce,sigma_obs,budget,previous_best)
}

//How many dollars would it be worth to obtain this information?
expected_value_of_partial_information_lognormal_in_usd(prior,std_obs,budget,previous_best)={
expected_value_of_partial_information_lognormal(prior,std_obs,budget,previous_best)/previous_best

}

//How much money is it worth to obtain this information per dollar that will be spent on the interventions?
ev_partial_information_lognormal_per_usd(prior,std_obs,previous_best)={
expected_value_of_partial_information_lognormal_in_usd(prior,std_obs,1,previous_best)
}


`, [cea_functions,value_of_imperfect_information])
Insert cell
Insert cell
viewof evii_by_precision = cell(`

prior = ce_new_bs_WELLBYs_per_1000USD/1000 //cost-effectiveness in WELLBYs/$

evii_of_informational_precision(precision)={
std_obs = pow(precision,-1/2)
previous_best = ce_StrongMinds_WELLBYs/1000 //cost-effectiveness in WELLBYs/$
ev_partial_information_lognormal_per_usd(prior,std_obs,previous_best)
}

se_prior = sqrt(variance(prior)) // WELLBYs per dollar
uncertainty_reduction_factor = [1,1.5,2,3,4,5,6,7,8,9,10]
se_values = map(uncertainty_reduction_factor, {|x| se_prior/x})
precision_values = map( se_values, { |x| pow(x,-2)})
values_of_RCT_per_million_USD_spent = map(precision_values,{|x| mean(1M*evii_of_informational_precision(x))})

`,[cost_effectiveness_of_intervention_bs_WELLBY,cea_functions,ce_of_previous_interventions,expected_value_of_imperfect_information],{distributionChartSettings: {showSummary: true}})
Insert cell
Insert cell
viewof required_nr_of_participants = cell(`

n_experimental = 43
n_control = 32
n_Baumsteiger = n_control+n_experimental

n_required(uncertainty_reduction_factor)={
n_Baumsteiger * uncertainty_reduction_factor^2
}

nr_participants = map(uncertainty_reduction_factor,n_required)

`, [evii_by_precision,cea_functions], {distributionChartSettings: {showSummary: true}})
Insert cell
Insert cell
viewof cost_effectiveness_of_RCT = cell(`

// assumption: measurement costs a base pay of about $20 plus about $2 per day x 100 days
cost_of_measurement_per_participant = 20 + 2 * 100
cost_per_participant = cost_of_online_intervention_per_person_reached() + cost_of_measurement_per_participant
participant_costs = map(nr_participants, {|x| x*cost_per_participant})
personnel_costs = 65000 //generous estimate: one postdoc for one year

total_cost = map(participant_costs, { |x| x+personnel_costs})

budget_in_M = 10 to 1000

total_benefit = budget_in_M*values_of_RCT_per_million_USD_spent[4]

cost_effectiveness_relative_to_best_intervention = total_benefit/total_cost[4]

cost_effectiveness_in_WELLBYs_per_1000USD = cost_effectiveness_relative_to_best_intervention * ce_StrongMinds_WELLBYs



[{distributions: [{name:"cost of RCT in USD",distribution:total_cost[4]},{name:"Value of RCT in USD", distribution:total_benefit}]},cost_effectiveness_relative_to_best_intervention,cost_effectiveness_in_WELLBYs_per_1000USD]

`, [cea_functions,required_nr_of_participants,evii_by_precision,ce_of_previous_interventions],{distributionChartSettings: {showSummary: true}})
Insert cell
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