tests/ folder, create a file to develop procedures, say, tests/test_estimate_model.R.git commit once this is done.# expand asic spec vector for top currencies
algo_date <-
spec %>%
tidyr::expand(
tidyr::nesting(model, algo),
date = seq(min(release), to = as.Date("2020-12-31"), by = 1)
) %>%
dplyr::left_join(
spec,
by = c("model", "algo", "date" = "release")
) %>%
dplyr::group_by(model) %>%
tidyr::fill(dplyr::everything(), .direction = "down") %>%
dplyr::ungroup()
# make baseline data
# complete in asic x (currency x algo x date)
# include NA
base_currency_algo_date <-
currency_algo_date %>%
dplyr::filter(asic_dummy)
base_currency_algo_date <-
base_currency_algo_date %>%
tidyr::expand(
model = unique(algo_date$model),
tidyr::nesting(currency, algo, date)
) %>%
dplyr::left_join(
algo_date,
by = c("model", "algo", "date")
) %>%
dplyr::filter(!is.na(hash_rate_spec)) %>%
dplyr::left_join(
currency_algo_date,
by = c("currency", "algo", "date")
) %>%
dplyr::left_join(
spec %>%
dplyr::select(model, release),
by = "model"
)
base_currency_algo_date <-
base_currency_algo_date %>%
dplyr::mutate(currency_base = (currency == currency_base))
git commit once this is done.# make baseline data for computing utility and choice probability
make_baseline_data_asic <-
function(
spec,
currency_algo_date,
currency_base
) {
# expand asic spec vector for top currencies
algo_date <-
spec %>%
tidyr::expand(
tidyr::nesting(model, algo),
date = seq(min(release), to = as.Date("2020-12-31"), by = 1)
) %>%
dplyr::left_join(
spec,
by = c("model", "algo", "date" = "release")
) %>%
dplyr::group_by(model) %>%
tidyr::fill(dplyr::everything(), .direction = "down") %>%
dplyr::ungroup()
# make baseline data
# complete in asic x (currency x algo x date)
# include NA
base_currency_algo_date <-
currency_algo_date %>%
dplyr::filter(asic_dummy)
base_currency_algo_date <-
base_currency_algo_date %>%
tidyr::expand(
model = unique(algo_date$model),
tidyr::nesting(currency, algo, date)
) %>%
dplyr::left_join(
algo_date,
by = c("model", "algo", "date")
) %>%
dplyr::filter(!is.na(hash_rate_spec)) %>%
dplyr::left_join(
currency_algo_date,
by = c("currency", "algo", "date")
) %>%
dplyr::left_join(
spec %>%
dplyr::select(model, release),
by = "model"
)
base_currency_algo_date <-
base_currency_algo_date %>%
dplyr::mutate(currency_base = (currency == currency_base))
return(base_currency_algo_date)
}
Cut this function and paste it to a file in R/ folder that collects R function definitions, say, R/functions.R.
devtools::load_all(".") to load the function definition as a method in the project package.
Check that there is no global reference in the function by running codetools::findGlobals(make_baseline_data_asic) in the R console. This will list all global variables used in the function. Check there are no user-defined global variables in the list. The variable names used in dplyr is recognized as global variable, but they are okay. git commit once this is done.
> codetools::findGlobals(make_baseline_data_asic)
[1] "!" "$" "%>%" "(" "::" "{"
[7] "<-" "==" "algo" "as.Date" "asic_dummy" "c"
[13] "currency" "date" "hash_rate_spec" "is.na" "min" "model"
[19] "release" "return" "seq" "unique"
tests/test_estimate_model.R, keep a line to perform the function:# make basic data
base_currency_algo_date <-
make_baseline_data_asic(
spec = spec,
currency_algo_date = currency_algo_date,
currency_base = currency_base
)
git commit once this is done. It should be like this:tests/test_estimate_model.R, make a file in the main/ folder to run the procedure while cutting unnecessary steps, say, main/estimate_model.R . git commit once this is done. It should look like this:tests/test_estimate_model.R. You can work on main/estimate_model.R only after you confirm the performance of the procedure inside tests/test_estimate_model.R.