Description Usage Arguments Value Author(s) References Examples
View source: R/ff_opti_bisect.R
This is only for strictly monotonically functions that have unique crossing at zero. There are potentially three types of inputs relevant for the bisection root evaluation. Values in each row are parameters for the same nonlinear function, we want to find roots for N nonlinear functions defined by each row. First type of input are these row specific variable values. Second type of inputs are scalars or arrays that are fixed over all rows. Third type of inputs are values that are shifting over bisection iterations. The implementation here assumes that we have lower and upper bound values that are common across all individauls (rows), and that garantee opposing signs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ff_opti_bisect_pmap_multi(
df,
fc_withroot,
fl_lower_x,
fl_upper_x,
ls_svr_df_in_func,
svr_root_x = "x",
it_iter_tol = 50,
fl_zero_tol = 10^-5,
bl_keep_iter = TRUE,
st_bisec_prefix = "bisec_",
st_lower_x = "a",
st_lower_fx = "fa",
st_upper_x = "b",
st_upper_fx = "fb"
)
|
df |
dataframe containing all row/individual specific variable information, will append bisection results to datafram |
fc_withroot |
function with root, the function should have hard-coded in scalars and arrays that would not change over iterations and would not change across individuals |
fl_lower_x |
float value of common lower bound |
fl_upper_x |
float value of common upper bound, opposing sign |
ls_svr_df_in_func |
list of string names variables in df that are inputs for fc_withroot. |
svr_root_x |
string the x variable name that appears n fc_withroot. |
it_iter_tol |
integer how many maximum iterations to allow for bisection at most |
fl_zero_tol |
float at what gap to zero will algorithm stop |
bl_keep_iter |
whether to keep all iteration results as data columns |
st_bisec_prefix |
string prefix for all bisection iteration etc results variables |
st_lower_x |
string variable name component for lower bound x |
st_lower_fx |
string variable name component for lower bound x evaluated at function |
st_upper_x |
string variable name component for upper bound x |
st_upper_fx |
string variable name component for upper bound x evaluated at function |
dataframe containing bisection root for each individual/row
Fan Wang, http://fanwangecon.github.io
https://fanwangecon.github.io/REconTools/reference/ff_opti_bisect_pmap_multi.html https://fanwangecon.github.io/REconTools/articles/fv_opti_bisect_pmap_multi.html https://github.com/FanWangEcon/REconTools/blob/master/R/ff_opti_bisect.R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | library(dplyr)
library(tibble)
it_N_child_cnt <- 9
ar_intercept = seq(-10, -1, length.out = it_N_child_cnt)
ar_slope = seq(0.1, 1, length.out = it_N_child_cnt)
df_lines <- as_tibble(cbind(ar_intercept, ar_slope)) %>% rowid_to_column(var='ID')
ar_st_col_names = c('ID','fl_int', 'fl_slope')
df_lines <- df_lines %>% rename_all(~c(ar_st_col_names))
fc_withroot_line <- function(fl_int, fl_slope, x){
return(fl_int + fl_slope*x)
}
fl_lower_x_line <- 0
fl_upper_x_line <- 100000
ls_svr_df_in_func_line <- c('fl_int', 'fl_slope')
svr_root_x_line <- 'x'
fl_zero_tol = 10^-6
df_bisec <- ff_opti_bisect_pmap_multi(df_lines, fc_withroot_line,
fl_lower_x_line, fl_upper_x_line,
ls_svr_df_in_func_line, svr_root_x_line, bl_keep_iter = FALSE)
df_bisec %>% select(-one_of('f_p_t_f_a'))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.