Works with binary allocation problems. The function invokes ffp_opt_sobin_target_row. The example tests think of as bottled protein.

ffp_opt_anlyz_rhgin_bin(
  df,
  svr_id_i,
  svr_A_i = "A",
  svr_alpha_i = "alpha",
  svr_beta_i = "beta",
  ar_rho = c(0.5, 0.1, -1, -20),
  svr_rho = "rho",
  svr_rho_val = "rho_val",
  svr_inpalc = "rank",
  svr_expout = "opti_exp_outcome",
  verbose = FALSE
)

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 elasticity information

svr_beta_i

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

ar_rho

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

svr_rho

string variable name for the index planner inequality aversion variable, initially rho, then called rho, this is the index variable, index for each one of the rho values

svr_rho_val

string variable name for the value of the planner inequality aversion variable

svr_inpalc

string variable name for newly generated input optimal allocation

svr_expout

string variable name for newly generated expected outcome

verbose

boolean print out intermediary function outputs

Value

a list with a dataframe and an array

  • df_all_rho - table where optimal targets given rhos are additional columns, note rank_max = highest rank reachest, lowest number

  • df_all_rho_long - long version of df_all_rho, single column all targets another column rho values

Author

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

Examples

library(dplyr)
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'
ar_rho = c(-50, -10, -0.1, 0.1, 0.5, 0.7)
ls_bin_solu_all_rhos <- ffp_opt_anlyz_rhgin_bin(df, svr_id_i, svr_A_i, svr_alpha_i, svr_beta_i, ar_rho)
#> Joining, by = "indi.id"
df_all_rho <- ls_bin_solu_all_rhos$df_all_rho
head(df_all_rho %>% select(svr_id_i, svr_A_i, svr_alpha_i, starts_with("rho")), 30)
#> Note: Using an external vector in selections is ambiguous.
#> i Use `all_of(svr_id_i)` instead of `svr_id_i` to silence this message.
#> i See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
#> This message is displayed once per session.
#> Note: Using an external vector in selections is ambiguous.
#> i Use `all_of(svr_A_i)` instead of `svr_A_i` to silence this message.
#> i See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
#> This message is displayed once per session.
#> Note: Using an external vector in selections is ambiguous.
#> i Use `all_of(svr_alpha_i)` instead of `svr_alpha_i` to silence this message.
#> i See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
#> This message is displayed once per session.
#> # A tibble: 30 x 9
#>    indi.id A_lin alpha_lin rho_c1_rk rho_c2_rk rho_c3_rk rho_c4_rk rho_c5_rk
#>      <dbl> <dbl>     <dbl>     <int>     <int>     <int>     <int>     <int>
#>  1       2  78.4    0.0101       937       967       967       967       967
#>  2       3  79.9    0.0323       853       669       669       669       669
#>  3       4  78.9    0.0323       583       578       578       578       578
#>  4       5  80.6    0.0662       734       521       202       201       201
#>  5       6  77.8    0.0101       787       861       861       861       861
#>  6       7  79.6    0.0662       484       428       125       125       125
#>  7       8  77.8    0.0101       793       865       865       865       865
#>  8       9  78.0    0.0101       823       883       883       883       883
#>  9      10  80.0    0.0662       572       483       166       166       166
#> 10      11  77.7    0.0602       126       126       358       358       358
#> # ... with 20 more rows, and 1 more variable: rho_c6_rk <int>
head(df_all_rho, 15)
#> # A tibble: 15 x 18
#>    indi.id A_lin alpha_lin     beta rank_min rank_max avg_rank S.country vil.id
#>      <dbl> <dbl>     <dbl>    <dbl>    <int>    <int>    <dbl> <chr>      <dbl>
#>  1       2  78.4    0.0101 0.000959      967      937     962  Cebu           1
#>  2       3  79.9    0.0323 0.000959      853      669     700. Cebu           1
#>  3       4  78.9    0.0323 0.000959      583      578     579. Cebu           1
#>  4       5  80.6    0.0662 0.000959      734      201     343. Cebu           1
#>  5       6  77.8    0.0101 0.000959      861      787     849. Cebu           1
#>  6       7  79.6    0.0662 0.000959      484      125     235. Cebu           1
#>  7       8  77.8    0.0101 0.000959      865      793     853  Cebu           1
#>  8       9  78.0    0.0101 0.000959      883      823     873  Cebu           1
#>  9      10  80.0    0.0662 0.000959      572      166     286. Cebu           1
#> 10      11  77.7    0.0602 0.000959      358      126     281. Cebu           1
#> 11      12  77.7    0.0602 0.000959      350      117     272. Cebu           1
#> 12      13  78.9    0.0323 0.000959      585      579     580  Cebu           1
#> 13      14  78.8    0.0602 0.000959      518      335     466  Cebu           1
#> 14      15  81.1    0.0662 0.000959      875      219     382. Cebu           1
#> 15      16  78.8    0.0323 0.000959      566      552     564. Cebu           1
#> # ... with 9 more variables: svymthRound <dbl>, alpha_log <dbl>, A_log <dbl>,
#> #   rho_c1_rk <int>, rho_c2_rk <int>, rho_c3_rk <int>, rho_c4_rk <int>,
#> #   rho_c5_rk <int>, rho_c6_rk <int>
summary(df_all_rho)
#>     indi.id           A_lin         alpha_lin            beta          
#>  Min.   :   2.0   Min.   :73.70   Min.   :0.01014   Min.   :0.0009588  
#>  1st Qu.: 298.5   1st Qu.:77.73   1st Qu.:0.01014   1st Qu.:0.0009588  
#>  Median : 627.0   Median :78.45   Median :0.06018   Median :0.0009588  
#>  Mean   : 634.8   Mean   :78.46   Mean   :0.04108   Mean   :0.0009588  
#>  3rd Qu.: 939.5   3rd Qu.:79.15   3rd Qu.:0.06018   3rd Qu.:0.0009588  
#>  Max.   :1349.0   Max.   :84.61   Max.   :0.06619   Max.   :0.0009588  
#>     rank_min         rank_max         avg_rank        S.country        
#>  Min.   : 176.0   Min.   :   1.0   Min.   :  44.67   Length:1043       
#>  1st Qu.: 414.0   1st Qu.: 131.0   1st Qu.: 266.25   Class :character  
#>  Median : 594.0   Median : 317.0   Median : 470.33   Mode  :character  
#>  Mean   : 625.5   Mean   : 418.4   Mean   : 522.00                     
#>  3rd Qu.: 837.5   3rd Qu.: 677.5   3rd Qu.: 756.75                     
#>  Max.   :1043.0   Max.   :1036.0   Max.   :1041.83                     
#>      vil.id       svymthRound   alpha_log            A_log      
#>  Min.   : 1.00   Min.   :24   Min.   :0.006687   Min.   :4.287  
#>  1st Qu.: 7.00   1st Qu.:24   1st Qu.:0.006687   1st Qu.:4.334  
#>  Median :12.00   Median :24   Median :0.012090   Median :4.343  
#>  Mean   :12.52   Mean   :24   Mean   :0.010321   Mean   :4.343  
#>  3rd Qu.:17.00   3rd Qu.:24   3rd Qu.:0.012090   3rd Qu.:4.351  
#>  Max.   :33.00   Max.   :24   Max.   :0.013940   Max.   :4.417  
#>    rho_c1_rk        rho_c2_rk        rho_c3_rk        rho_c4_rk     
#>  Min.   :   1.0   Min.   :   1.0   Min.   :   1.0   Min.   :   1.0  
#>  1st Qu.: 261.5   1st Qu.: 261.5   1st Qu.: 261.5   1st Qu.: 261.5  
#>  Median : 522.0   Median : 522.0   Median : 522.0   Median : 522.0  
#>  Mean   : 522.0   Mean   : 522.0   Mean   : 522.0   Mean   : 522.0  
#>  3rd Qu.: 782.5   3rd Qu.: 782.5   3rd Qu.: 782.5   3rd Qu.: 782.5  
#>  Max.   :1043.0   Max.   :1043.0   Max.   :1043.0   Max.   :1043.0  
#>    rho_c5_rk        rho_c6_rk     
#>  Min.   :   1.0   Min.   :   1.0  
#>  1st Qu.: 261.5   1st Qu.: 261.5  
#>  Median : 522.0   Median : 522.0  
#>  Mean   : 522.0   Mean   : 522.0  
#>  3rd Qu.: 782.5   3rd Qu.: 782.5  
#>  Max.   :1043.0   Max.   :1043.0  
df_all_rho_long <- ls_bin_solu_all_rhos$df_all_rho_long
head(df_all_rho_long, 15)
#> # A tibble: 15 x 7
#>    indi.id A_lin alpha_lin     beta   rho rho_val  rank
#>      <dbl> <dbl>     <dbl>    <dbl> <dbl>   <dbl> <int>
#>  1       2  78.4    0.0101 0.000959     1   -50     937
#>  2       2  78.4    0.0101 0.000959     2   -10     967
#>  3       2  78.4    0.0101 0.000959     3    -0.1   967
#>  4       2  78.4    0.0101 0.000959     4     0.1   967
#>  5       2  78.4    0.0101 0.000959     5     0.5   967
#>  6       2  78.4    0.0101 0.000959     6     0.7   967
#>  7       3  79.9    0.0323 0.000959     1   -50     853
#>  8       3  79.9    0.0323 0.000959     2   -10     669
#>  9       3  79.9    0.0323 0.000959     3    -0.1   669
#> 10       3  79.9    0.0323 0.000959     4     0.1   669
#> 11       3  79.9    0.0323 0.000959     5     0.5   669
#> 12       3  79.9    0.0323 0.000959     6     0.7   669
#> 13       4  78.9    0.0323 0.000959     1   -50     583
#> 14       4  78.9    0.0323 0.000959     2   -10     578
#> 15       4  78.9    0.0323 0.000959     3    -0.1   578
summary(df_all_rho_long)
#>     indi.id           A_lin         alpha_lin            beta          
#>  Min.   :   2.0   Min.   :73.70   Min.   :0.01014   Min.   :0.0009588  
#>  1st Qu.: 298.0   1st Qu.:77.72   1st Qu.:0.01014   1st Qu.:0.0009588  
#>  Median : 627.0   Median :78.45   Median :0.06018   Median :0.0009588  
#>  Mean   : 634.8   Mean   :78.46   Mean   :0.04108   Mean   :0.0009588  
#>  3rd Qu.: 940.0   3rd Qu.:79.15   3rd Qu.:0.06018   3rd Qu.:0.0009588  
#>  Max.   :1349.0   Max.   :84.61   Max.   :0.06619   Max.   :0.0009588  
#>       rho         rho_val           rank     
#>  Min.   :1.0   Min.   :-50.0   Min.   :   1  
#>  1st Qu.:2.0   1st Qu.:-10.0   1st Qu.: 261  
#>  Median :3.5   Median :  0.0   Median : 522  
#>  Mean   :3.5   Mean   : -9.8   Mean   : 522  
#>  3rd Qu.:5.0   3rd Qu.:  0.5   3rd Qu.: 783  
#>  Max.   :6.0   Max.   :  0.7   Max.   :1043