def income_increase_under_15( person_yrs_of_coverage_for_under_5s, person_yrs_of_coverage_for_5_to_14s, reduction_in_prob_of_covered_child_being_infected_under_5, reduction_in_prob_of_covered_child_being_infected_5_to_14, increase_in_income_from_eliminating_prob_of_malaria_infection_in_youth, replicability_adjustment_for_malaria_vs_income, num_yrs_between_anti_malaria_program_and_long_term_benefits, discount_rate, duration_of_long_term_benefits, multiplier_for_sharing_win_households, value_of_increasing_ln_consumption_per_capita_per_annum, ): reduction_in_num_people_infected_at_point_in_time_in_cohort_under_5 = ( person_yrs_of_coverage_for_under_5s * reduction_in_prob_of_covered_child_being_infected_under_5) reduction_in_num_people_infected_at_point_in_time_in_cohort_5_to_14 = ( person_yrs_of_coverage_for_5_to_14s * reduction_in_prob_of_covered_child_being_infected_5_to_14) adjusted_increase_in_ln_income_from_reducing_point_in_time_probability_of_malaria_infection_from_100_to_0_for_an_invidiual_between_the_ages_of_0_and_14 = ( (log( 1 + increase_in_income_from_eliminating_prob_of_malaria_infection_in_youth ) - log(1)) * replicability_adjustment_for_malaria_vs_income) benefit_on_one_years_income = ( adjusted_increase_in_ln_income_from_reducing_point_in_time_probability_of_malaria_infection_from_100_to_0_for_an_invidiual_between_the_ages_of_0_and_14 / (1 + discount_rate)** num_yrs_between_anti_malaria_program_and_long_term_benefits) present_value_of_lifetime_benefits_from_reducing_prevalence_from_1_to_0_for_an_individual_for_one_year_between_ages_of_0_and_14 = present_value_of_annuity( discount_rate, duration_of_long_term_benefits, benefit_on_one_years_income) # TODO: end of period present_value_of_benefits_from_reducing_point_in_time_probability_of_malaria_infection_from_100_to_0_for_individual_for_one_year_between_ages_of_0_and_14 = ( present_value_of_lifetime_benefits_from_reducing_prevalence_from_1_to_0_for_an_individual_for_one_year_between_ages_of_0_and_14 * multiplier_for_sharing_win_households) total_increase_in_ln_income_under_5 = ( present_value_of_benefits_from_reducing_point_in_time_probability_of_malaria_infection_from_100_to_0_for_individual_for_one_year_between_ages_of_0_and_14 * reduction_in_num_people_infected_at_point_in_time_in_cohort_under_5) total_increase_in_ln_income_5_to_14 = ( present_value_of_benefits_from_reducing_point_in_time_probability_of_malaria_infection_from_100_to_0_for_individual_for_one_year_between_ages_of_0_and_14 * reduction_in_num_people_infected_at_point_in_time_in_cohort_5_to_14) value_from_development_benefits_per_million_donated = ( value_of_increasing_ln_consumption_per_capita_per_annum * (total_increase_in_ln_income_5_to_14 + total_increase_in_ln_income_under_5)) value_from_development_benefits_per_dollar_wout_levfun = ( value_from_development_benefits_per_million_donated / arbitrary_donation_size) return { "AMF: value from development benefits per dollar w/out lev/fun": value_from_development_benefits_per_dollar_wout_levfun }
def Mhat(G): #estimate mean given G pM = np.array([-2.42043861e-05,7.07715287e-04,-8.72589408e-03,5.78173631e-02,-2.12287390e-01,3.65070722e-01,2.39311397e-02,2.39178197e-01]) tot = 0 for i in range(8): tot += pM[i]*log(G)**(7-i) return tot
def Vhat(G): #estimate variance given G pV = np.array([-2.33501964e-06,8.10258820e-05,-1.21332152e-03,1.01946967e-02,-5.21336282e-02,1.63404382e-01,-2.95110778e-01,2.50969395e-01,-3.73368931e-02]) tot = 0 for i in range(9): tot += pV[i]*log(G)**(8-i) return tot
def fit(self, X, B, T): n, k = X.shape with pymc3.Model() as m: beta_sd = pymc3.Exponential( 'beta_sd', 1.0) # Weak prior for the regression coefficients beta = pymc3.Normal('beta', mu=0, sd=beta_sd, shape=(k, )) # Regression coefficients c = sigmoid(dot(X, beta)) # Conversion rates for each example k = pymc3.Lognormal('k', mu=0, sd=1.0) # Weak prior around k=1 lambd = pymc3.Exponential('lambd', 0.1) # Weak prior # PDF of Weibull: k * lambda * (x * lambda)^(k-1) * exp(-(t * lambda)^k) LL_observed = log(c) + log(k) + log( lambd) + (k - 1) * (log(T) + log(lambd)) - (T * lambd)**k # CDF of Weibull: 1 - exp(-(t * lambda)^k) LL_censored = log((1 - c) + c * exp(-(T * lambd)**k)) # We need to implement the likelihood using pymc3.Potential (custom likelihood) # https://github.com/pymc-devs/pymc3/issues/826 logp = B * LL_observed + (1 - B) * LL_censored logpvar = pymc3.Potential('logpvar', logp.sum()) self.trace = pymc3.sample(n_simulations=500, tune=500, discard_tuned_samples=True, njobs=1) print('done') print('done 2')
def cash_transfers( average_household_size, percent_of_transfers_invested, return_on_investment, baseline_consumption_per_capita, discount_rate, duration_of_investment_benefits, percent_of_investment_returned_when_benefits_end, discount_from_negative_spillover, value_of_increasing_ln_consumption_per_capita_per_annum, transfer_as_percent_of_total_cost, ): total_size_of_transfer = 1000 size_of_transfer_per_person = total_size_of_transfer / average_household_size amount_invested = size_of_transfer_per_person * percent_of_transfers_invested total_increase_in_consumption_due_to_funds_transferred = ( 1 - percent_of_transfers_invested ) * size_of_transfer_per_person annual_increase_in_consumption_due_to_investment_returns = ( amount_invested * return_on_investment ) total_increase_in_ln_consumption_due_to_funds_transferred = log( baseline_consumption_per_capita + total_increase_in_consumption_due_to_funds_transferred ) - log(baseline_consumption_per_capita) future_annual_increase_in_ln_consumption_from_return_on_investments = log( baseline_consumption_per_capita + annual_increase_in_consumption_due_to_investment_returns ) - log(baseline_consumption_per_capita) present_value_of_future_increases_in_ln_consumption_excluding_final_year = present_value_of_annuity( discount_rate, duration_of_investment_benefits - 1, future_annual_increase_in_ln_consumption_from_return_on_investments, ) _additional_consumption_in_final_year = ( amount_invested * return_on_investment + amount_invested * percent_of_investment_returned_when_benefits_end ) present_value_of_ln_consumption_increase_in_final_year = ( log(baseline_consumption_per_capita + _additional_consumption_in_final_year) - log(baseline_consumption_per_capita) ) / (1 + discount_rate) ** duration_of_investment_benefits present_value_of_all_future_increases_in_ln_consumption = ( present_value_of_ln_consumption_increase_in_final_year + present_value_of_future_increases_in_ln_consumption_excluding_final_year ) total_present_value_of_cash_transfer = ( present_value_of_all_future_increases_in_ln_consumption + total_increase_in_ln_consumption_due_to_funds_transferred ) total_present_value_of_cash_transfer_accounting_for_spillovers = ( 1 - discount_from_negative_spillover ) * total_present_value_of_cash_transfer increase_in_ln_consumption_for_each_dollar_donated = ( total_present_value_of_cash_transfer_accounting_for_spillovers * transfer_as_percent_of_total_cost ) / size_of_transfer_per_person value_per_dollar = ( increase_in_ln_consumption_for_each_dollar_donated * value_of_increasing_ln_consumption_per_capita_per_annum ) return {"Cash: value per dollar": value_per_dollar}
def income_increases_age_14_and_under( malaria_prevalance_young, malaria_prevalence_old, direct_mortality_in_high_transmission_season, reduction_in_malaria_after_adjustments, internal_validity_adjustment, external_validity_adjustment, reduction_in_untreated_pop_per_reduction_in_treated_pop, adjustment_for_higher_percent_covered_in_trial_than_ACCESS, increase_in_income_from_eliminating_prob_of_malaria_infection_in_youth, replicability_adjustment_for_malaria_vs_income, num_yrs_between_anti_malaria_program_and_long_term_benefits, discount_rate, duration_of_long_term_benefits, multiplier_for_sharing_win_households, value_of_increasing_ln_consumption_per_capita_per_annum, cost_per_child_targeted, ): percentage_reduction_in_malaria_prevalance_in_treated_population_after_adherence_and_coverage_adjustments_young = ( malaria_prevalance_young * direct_mortality_in_high_transmission_season * reduction_in_malaria_after_adjustments * internal_validity_adjustment * external_validity_adjustment) percentage_reduction_in_malaria_prevalance_in_untreated_population_after_adherence_and_coverage_adjustments_old = ( malaria_prevalence_old * direct_mortality_in_high_transmission_season * reduction_in_malaria_after_adjustments * internal_validity_adjustment * external_validity_adjustment * reduction_in_untreated_pop_per_reduction_in_treated_pop * adjustment_for_higher_percent_covered_in_trial_than_ACCESS) reduction_in_number_of_people_infected_with_malaria_at_point_in_time_per_1000_under_5s_targeted_young = ( percentage_reduction_in_malaria_prevalance_in_treated_population_after_adherence_and_coverage_adjustments_young * 1000) reduction_in_number_of_people_infected_with_malaria_at_point_in_time_per_1000_under_5s_targeted_old = ( percentage_reduction_in_malaria_prevalance_in_untreated_population_after_adherence_and_coverage_adjustments_old * 1000) increase_in_ln_income_from_reducing_point_in_time_probability_of_malaria_infection_from_100_to_0_for_individual_for_one_year_between_ages_of_0_and_14 = ( (log( 1 + increase_in_income_from_eliminating_prob_of_malaria_infection_in_youth ) - log(1)) * replicability_adjustment_for_malaria_vs_income) benefit_on_one_years_income = ( increase_in_ln_income_from_reducing_point_in_time_probability_of_malaria_infection_from_100_to_0_for_individual_for_one_year_between_ages_of_0_and_14 / (1 + discount_rate)** num_yrs_between_anti_malaria_program_and_long_term_benefits) present_value_of_lifetime_benefits_from_reducing_prevalence_from_1_to_0_for_an_individual_for_one_year_between_ages_of_0_and_14 = present_value_of_annuity( discount_rate, duration_of_long_term_benefits, benefit_on_one_years_income) # TODO: end of period present_value_of_benefits_from_reducing_point_in_time_probability_of_malaria_infection_from_100_to_0_for_individual_for_one_year_between_ages_of_0_and_14 = ( present_value_of_lifetime_benefits_from_reducing_prevalence_from_1_to_0_for_an_individual_for_one_year_between_ages_of_0_and_14 * multiplier_for_sharing_win_households) total_increase_in_annual_ln_income_for_young_per_1000_under_5s_targeted = ( present_value_of_benefits_from_reducing_point_in_time_probability_of_malaria_infection_from_100_to_0_for_individual_for_one_year_between_ages_of_0_and_14 * reduction_in_number_of_people_infected_with_malaria_at_point_in_time_per_1000_under_5s_targeted_young ) total_increase_in_annual_ln_income_for_old_per_1000_under_5s_targeted = ( present_value_of_benefits_from_reducing_point_in_time_probability_of_malaria_infection_from_100_to_0_for_individual_for_one_year_between_ages_of_0_and_14 * reduction_in_number_of_people_infected_with_malaria_at_point_in_time_per_1000_under_5s_targeted_old ) value_from_development_benefits_per_1000_under_5s_targeted = ( value_of_increasing_ln_consumption_per_capita_per_annum * (total_increase_in_annual_ln_income_for_old_per_1000_under_5s_targeted + total_increase_in_annual_ln_income_for_young_per_1000_under_5s_targeted )) value_from_development_per_dollar_wout_levfun = ( value_from_development_benefits_per_1000_under_5s_targeted / (cost_per_child_targeted * 1000)) return { "SMC: value from development per dollar w/out lev/fun": value_from_development_per_dollar_wout_levfun }