Download 107/replication_package/Code/MATLAB/compute_efficiency.m from chuxuan/REPRO-Bench: direct link, hf CLI and curl.
- Browser
- Download file 7.62 kB
-
https://huggingface.co/datasets/chuxuan/REPRO-Bench/resolve/main/107/replication_package/Code/MATLAB/compute_efficiency.m
- Command line
-
hf download hf://datasets/chuxuan/REPRO-Bench/107/replication_package/Code/MATLAB/compute_efficiency.m
-
curl -L -o compute_efficiency.m https://huggingface.co/datasets/chuxuan/REPRO-Bench/resolve/main/107/replication_package/Code/MATLAB/compute_efficiency.m
7.62 kB
| function results = compute_efficiency(commit_models,no_commit_models, ... | |
| no_p_commit_models) | |
| % compute efficiency of behavior change & other outcomes from the | |
| % commitment contract and two piece-rate incentives | |
| n = length(commit_models); | |
| % compute average change in attendance from the contract | |
| delta_a_Cs = []; | |
| avg_delta_a_C = 0; | |
| for i = 1:n | |
| avg_delta_a_C = avg_delta_a_C + (commit_models(i).mu .* ... | |
| (commit_models(i).avg_att - no_p_commit_models(i).avg_att)); | |
| delta_a_Cs = [delta_a_Cs, commit_models(i).avg_att - no_p_commit_models(i).avg_att]; | |
| end | |
| results.avg_delta_a_C = avg_delta_a_C; | |
| % compute average period 1 incremental welfare from the contract | |
| avg_delta_surplus = 0; | |
| for i = 1:n | |
| avg_delta_surplus = avg_delta_surplus + (commit_models(i).mu .* ... | |
| (commit_models(i).t1_utility - no_p_commit_models(i).t1_utility)); | |
| end | |
| results.avg_delta_surplus = avg_delta_surplus; | |
| % compute the surplus just for those who took up the contract | |
| mu_commit = 0; | |
| for i = 1:n | |
| mu_commit = mu_commit + commit_models(i).mu; | |
| end | |
| results.commit_delta_surplus = avg_delta_surplus / mu_commit; | |
| % compute average change in expected benefits from the contract | |
| avg_delta_benefits = 0; | |
| for i = 1:n | |
| avg_delta_benefits = avg_delta_benefits + ... | |
| (commit_models(i).mu .* commit_models(i).b .* ... | |
| (commit_models(i).avg_att - no_p_commit_models(i).avg_att)); | |
| end | |
| results.avg_delta_benefits = avg_delta_benefits; | |
| % compute average change in expected costs from the contract | |
| avg_delta_costs = 0; | |
| for i = 1:n | |
| avg_delta_costs = avg_delta_costs + (commit_models(i).mu .* ... | |
| (commit_models(i).avg_costs - no_p_commit_models(i).avg_costs)); | |
| end | |
| results.avg_delta_costs = avg_delta_costs; | |
| % compute efficiency of behavior change from the commitment contract | |
| results.V_E = results.avg_delta_benefits - results.avg_delta_costs; | |
| % compute the optimal r | |
| syms r | |
| eqns_n = []; % placeholder for numerator | |
| eqns_d = []; % placeholder for denominator | |
| for k = 1:n | |
| eqns_n = [ eqns_n; commit_models(k).mu .* (1 - commit_models(k).beta) .* ... | |
| commit_models(k).b .* commit_models(k).beta .* ... | |
| commit_models(k).f(commit_models(k).beta .* (commit_models(k).b + r)) ]; | |
| eqns_n = [ eqns_n; no_commit_models(k).mu .* (1 - no_commit_models(k).beta) .* ... | |
| no_commit_models(k).b .* no_commit_models(k).beta .* ... | |
| no_commit_models(k).f(no_commit_models(k).beta .* (no_commit_models(k).b + r)) ]; | |
| eqns_d = [ eqns_d; commit_models(k).mu .* (commit_models(k).beta .^ 2) .* ... | |
| commit_models(k).f(commit_models(k).beta .* (commit_models(k).b + r)) ]; | |
| eqns_d = [ eqns_d; no_commit_models(k).mu .* (no_commit_models(k).beta .^ 2) .* ... | |
| no_commit_models(k).f(no_commit_models(k).beta .* (no_commit_models(k).b + r)) ]; | |
| end | |
| r_opt = vpasolve(sum(eqns_n) ./ sum(eqns_d) == r, r); | |
| results.r_opt = double(r_opt); | |
| % compute outcomes under r_opt | |
| results.U_E_r_opt = compute_incentive_efficiency(results.r_opt, ... | |
| commit_models, no_commit_models); | |
| [results.delta_surplus_r_opt, results.delta_benefits_r_opt, ... | |
| results.delta_costs_r_opt, results.delta_att_r_opt] = ... | |
| compute_incentive_outcomes(results.r_opt, ... | |
| commit_models, no_commit_models); | |
| % find the r that generates the same expected change in attendance | |
| syms r | |
| eqns = []; | |
| for k = 1:n | |
| eqns = [ eqns; (commit_models(k).mu .* ... | |
| (commit_models(k).F(commit_models(k).beta .* ... | |
| (commit_models(k).b + r)) ... | |
| - commit_models(k).F(commit_models(k).beta .* ... | |
| commit_models(k).b))) ]; | |
| eqns = [ eqns; (no_commit_models(k).mu .* ... | |
| (no_commit_models(k).F(no_commit_models(k).beta .* ... | |
| (no_commit_models(k).b + r)) ... | |
| - no_commit_models(k).F(no_commit_models(k).beta .* ... | |
| no_commit_models(k).b))) ]; | |
| end | |
| r_att = vpasolve(commit_models(1).T .* sum(eqns) == avg_delta_a_C, r); | |
| results.r_att = double(r_att); | |
| % compute outcomes under r_att | |
| results.U_E_r_att = compute_incentive_efficiency(results.r_att, ... | |
| commit_models, no_commit_models); | |
| [results.delta_surplus_r_att, results.delta_benefits_r_att, ... | |
| results.delta_costs_r_att, results.delta_att_r_att] = ... | |
| compute_incentive_outcomes(results.r_att, ... | |
| commit_models, no_commit_models); | |
| end | |
| %% Helper functions | |
| function U_E = compute_incentive_efficiency(r, commit_models, ... | |
| no_commit_models) | |
| % compute the efficiency of behavior change under incentive r | |
| N = length(commit_models); | |
| U_E = 0; | |
| inc = [r 0]; | |
| for j = 1:N | |
| commit_models(j) = commit_models(j).compute_incentive_behavior(inc); | |
| U_E = U_E + commit_models(j).mu .* ... | |
| (commit_models(j).net_surplus_r(1) - ... | |
| commit_models(j).net_surplus_r(2)); | |
| no_commit_models(j) = no_commit_models(j).compute_incentive_behavior(inc); | |
| U_E = U_E + no_commit_models(j).mu .* ... | |
| (no_commit_models(j).net_surplus_r(1) - ... | |
| no_commit_models(j).net_surplus_r(2)); | |
| end | |
| end | |
| function [delta_surplus, delta_benefits, delta_costs, delta_a_r] = ... | |
| compute_incentive_outcomes(r, commit_models, no_commit_models) | |
| % compute the expected change in agent surplus, benefits, and costs | |
| % under incentive r | |
| N = length(commit_models); | |
| delta_surplus = 0; | |
| delta_benefits = 0; | |
| delta_costs = 0; | |
| delta_a_r = 0; | |
| inc = [r 0]; | |
| for j = 1:N | |
| commit_models(j) = commit_models(j).compute_incentive_behavior(inc); | |
| no_commit_models(j) = no_commit_models(j).compute_incentive_behavior(inc); | |
| % expected change in agent surplus | |
| delta_surplus = delta_surplus + commit_models(j).mu .* ... | |
| (commit_models(j).surplus_r(1) - ... | |
| commit_models(j).surplus_r(2)); | |
| delta_surplus = delta_surplus + no_commit_models(j).mu .* ... | |
| (no_commit_models(j).surplus_r(1) - ... | |
| no_commit_models(j).surplus_r(2)); | |
| % expected change in health benefits | |
| delta_benefits = delta_benefits + commit_models(j).mu .* ... | |
| (commit_models(j).benefits_r(1) - ... | |
| commit_models(j).benefits_r(2)); | |
| delta_benefits = delta_benefits + no_commit_models(j).mu .* ... | |
| (no_commit_models(j).benefits_r(1) - ... | |
| no_commit_models(j).benefits_r(2)); | |
| % expected change in costs | |
| delta_costs = delta_costs + commit_models(j).mu .* ... | |
| (commit_models(j).costs_r(1) - ... | |
| commit_models(j).costs_r(2)); | |
| delta_costs = delta_costs + no_commit_models(j).mu .* ... | |
| (no_commit_models(j).costs_r(1) - ... | |
| no_commit_models(j).costs_r(2)); | |
| % expected change in attendance | |
| delta_a_r = delta_a_r + commit_models(j).mu .* ... | |
| commit_models(j).change_att_r(1); | |
| delta_a_r = delta_a_r + no_commit_models(j).mu .* ... | |
| no_commit_models(j).change_att_r(1); | |
| end | |
| end | |