Works with linear allocation problems. The function invokes ffp_opt_solin_relow, has parameters that are also required for that function. The addition here is *fl_rho* becomes *ar_rho*

ffp_opt_anlyz_rhgin(
  df,
  svr_id_i,
  svr_A_i,
  svr_alpha_i,
  svr_beta_i,
  fl_N_agg,
  ar_rho,
  svr_inpalc = "optiallocate",
  svr_expout = "opti_exp_outcome"
)

Arguments

df

tibble data table including variables using svr names below each row is potentially an individual who will receive alternative allocations

svr_id_i

string name of the identify key for each i, to make sure merging happens properly

svr_A_i

string name of the A_i variable, dot product of covariates and coefficients

svr_alpha_i

string name of the alpha_i variable, individual-specific (marginal-effects)

svr_beta_i

string name of the beta_i variable, relative preference weight for each child

fl_N_agg

float total resource avaible for allocation, if not specific, sum by svr_N_i

ar_rho

array preferences for equality for the planner, each value from negative infinity to 1

svr_inpalc

string variable name for newly generated input optimal allocation

svr_expout

string variable name for newly generated expected outcome

Value

a dataframe that expands the df inputs with additional results. a list with a dataframe and an array

  • df_opti_alloc_all_rho - table with columns for optimal allocation and exp outcome different rhos

  • mt_opti_alloc_all_rho - a matrix row = indi, col = rho, value = optimal allocation

  • mt_expc_outcm_all_rho - a matrix row = indi, col = rho, value = exp outcome optimal allocations

  • mt_gini - a matrix row = rhos, col = opti-allo and exp-out, value = gini

Author

Fan Wang, http://fanwangecon.github.io

Examples

data(df_opt_dtgch_cbem4)
df <- df_opt_dtgch_cbem4
svr_id_i <- 'indi.id'
svr_A_i <- 'A_lin'
svr_alpha_i <- 'alpha_lin'
svr_beta_i <- 'beta'
fl_N_agg <- 10000
ar_rho = c(-50, -10, -0.1, 0.1, 0.5, 0.7)
ls_lin_solu_all_rhos <- ffp_opt_anlyz_rhgin(df, svr_id_i, svr_A_i, svr_alpha_i, svr_beta_i, fl_N_agg, ar_rho)
df_opti_alloc_all_rho <- ls_lin_solu_all_rhos$df_opti_alloc_all_rho
summary(df_opti_alloc_all_rho)
#>   S.country             vil.id         indi.id        svymthRound
#>  Length:1043        Min.   : 1.00   Min.   :   2.0   Min.   :24  
#>  Class :character   1st Qu.: 7.00   1st Qu.: 298.5   1st Qu.:24  
#>  Mode  :character   Median :12.00   Median : 627.0   Median :24  
#>                     Mean   :12.52   Mean   : 634.8   Mean   :24  
#>                     3rd Qu.:17.00   3rd Qu.: 939.5   3rd Qu.:24  
#>                     Max.   :33.00   Max.   :1349.0   Max.   :24  
#>    alpha_lin         alpha_log            A_lin           A_log      
#>  Min.   :0.01014   Min.   :0.006687   Min.   :73.70   Min.   :4.287  
#>  1st Qu.:0.01014   1st Qu.:0.006687   1st Qu.:77.73   1st Qu.:4.334  
#>  Median :0.06018   Median :0.012090   Median :78.45   Median :4.343  
#>  Mean   :0.04108   Mean   :0.010321   Mean   :78.46   Mean   :4.343  
#>  3rd Qu.:0.06018   3rd Qu.:0.012090   3rd Qu.:79.15   3rd Qu.:4.351  
#>  Max.   :0.06619   Max.   :0.013940   Max.   :84.61   Max.   :4.417  
#>       beta           rho_c1_optiallocate rho_c1_opti_exp_outcome
#>  Min.   :0.0009588   Min.   :  0.000     Min.   :76.56          
#>  1st Qu.:0.0009588   1st Qu.:  0.000     1st Qu.:78.35          
#>  Median :0.0009588   Median :  0.000     Median :79.28          
#>  Mean   :0.0009588   Mean   :  9.588     Mean   :78.96          
#>  3rd Qu.:0.0009588   3rd Qu.: 15.122     3rd Qu.:79.43          
#>  Max.   :0.0009588   Max.   :216.490     Max.   :84.61          
#>  rho_c2_optiallocate rho_c2_opti_exp_outcome rho_c3_optiallocate
#>  Min.   : 0.000      Min.   :74.37           Min.   : 0.000     
#>  1st Qu.: 0.000      1st Qu.:78.35           1st Qu.: 0.000     
#>  Median : 0.000      Median :79.35           Median : 0.000     
#>  Mean   : 9.588      Mean   :79.05           Mean   : 9.588     
#>  3rd Qu.:17.191      3rd Qu.:79.87           3rd Qu.: 0.000     
#>  Max.   :94.000      Max.   :84.61           Max.   :63.897     
#>  rho_c3_opti_exp_outcome rho_c4_optiallocate rho_c4_opti_exp_outcome
#>  Min.   :74.37           Min.   : 0.000      Min.   :74.19          
#>  1st Qu.:77.73           1st Qu.: 0.000      1st Qu.:77.73          
#>  Median :78.46           Median : 0.000      Median :78.46          
#>  Mean   :79.10           Mean   : 9.588      Mean   :79.10          
#>  3rd Qu.:79.87           3rd Qu.: 0.000      3rd Qu.:79.87          
#>  Max.   :84.61           Max.   :64.217      Max.   :84.61          
#>  rho_c5_optiallocate rho_c5_opti_exp_outcome rho_c6_optiallocate
#>  Min.   : 0.000      Min.   :73.70           Min.   : 0.000     
#>  1st Qu.: 0.000      1st Qu.:77.73           1st Qu.: 0.000     
#>  Median : 0.000      Median :78.46           Median : 0.000     
#>  Mean   : 9.588      Mean   :79.10           Mean   : 9.588     
#>  3rd Qu.: 0.000      3rd Qu.:79.87           3rd Qu.: 0.000     
#>  Max.   :64.252      Max.   :84.61           Max.   :64.252     
#>  rho_c6_opti_exp_outcome
#>  Min.   :73.70          
#>  1st Qu.:77.73          
#>  Median :78.46          
#>  Mean   :79.10          
#>  3rd Qu.:79.87          
#>  Max.   :84.61          
mt_opti_alloc_all_rho <- ls_lin_solu_all_rhos$mt_opti_alloc_all_rho
summary(mt_opti_alloc_all_rho)
#>  rho_c1_optiallocate rho_c2_optiallocate rho_c3_optiallocate
#>  Min.   :  0.000     Min.   : 0.000      Min.   : 0.000     
#>  1st Qu.:  0.000     1st Qu.: 0.000      1st Qu.: 0.000     
#>  Median :  0.000     Median : 0.000      Median : 0.000     
#>  Mean   :  9.588     Mean   : 9.588      Mean   : 9.588     
#>  3rd Qu.: 15.122     3rd Qu.:17.191      3rd Qu.: 0.000     
#>  Max.   :216.490     Max.   :94.000      Max.   :63.897     
#>  rho_c4_optiallocate rho_c5_optiallocate rho_c6_optiallocate
#>  Min.   : 0.000      Min.   : 0.000      Min.   : 0.000     
#>  1st Qu.: 0.000      1st Qu.: 0.000      1st Qu.: 0.000     
#>  Median : 0.000      Median : 0.000      Median : 0.000     
#>  Mean   : 9.588      Mean   : 9.588      Mean   : 9.588     
#>  3rd Qu.: 0.000      3rd Qu.: 0.000      3rd Qu.: 0.000     
#>  Max.   :64.217      Max.   :64.252      Max.   :64.252     
mt_expc_outcm_all_rho <- ls_lin_solu_all_rhos$mt_expc_outcm_all_rho
summary(mt_expc_outcm_all_rho)
#>  rho_c1_opti_exp_outcome rho_c2_opti_exp_outcome rho_c3_opti_exp_outcome
#>  Min.   :76.56           Min.   :74.37           Min.   :74.37          
#>  1st Qu.:78.35           1st Qu.:78.35           1st Qu.:77.73          
#>  Median :79.28           Median :79.35           Median :78.46          
#>  Mean   :78.96           Mean   :79.05           Mean   :79.10          
#>  3rd Qu.:79.43           3rd Qu.:79.87           3rd Qu.:79.87          
#>  Max.   :84.61           Max.   :84.61           Max.   :84.61          
#>  rho_c4_opti_exp_outcome rho_c5_opti_exp_outcome rho_c6_opti_exp_outcome
#>  Min.   :74.19           Min.   :73.70           Min.   :73.70          
#>  1st Qu.:77.73           1st Qu.:77.73           1st Qu.:77.73          
#>  Median :78.46           Median :78.46           Median :78.46          
#>  Mean   :79.10           Mean   :79.10           Mean   :79.10          
#>  3rd Qu.:79.87           3rd Qu.:79.87           3rd Qu.:79.87          
#>  Max.   :84.61           Max.   :84.61           Max.   :84.61          
mt_gini <- ls_lin_solu_all_rhos$mt_gini
summary(mt_gini)
#>    it_rho_ctr     optiallocate       outcome          planner_elas   
#>  Min.   : 1.00   Min.   :0.6902   Min.   :0.006735   Min.   :0.7029  
#>  1st Qu.: 3.75   1st Qu.:0.7645   1st Qu.:0.009164   1st Qu.:0.7376  
#>  Median : 6.50   Median :0.8097   Median :0.013847   Median :1.1014  
#>  Mean   : 6.50   Mean   :0.7801   Mean   :0.011644   Mean   :1.1173  
#>  3rd Qu.: 9.25   3rd Qu.:0.8107   3rd Qu.:0.013905   3rd Qu.:1.3863  
#>  Max.   :12.00   Max.   :0.8107   Max.   :0.013908   Max.   :1.6740  
#>                  NA's   :6        NA's   :6