From 0744a5a2378067c509e1164f648a24ee0b86c3c0 Mon Sep 17 00:00:00 2001 From: evaaepelde Date: Tue, 30 Jan 2024 12:47:09 +0100 Subject: [PATCH] clean code and refresh build --- R/main.R | 68 +++++++++++---- R/utils.R | 159 ++++++++++++++++++++++++---------- man/add_coicop.Rd | 5 +- man/adjust_wh.Rd | 5 +- man/adjust_wh_is.Rd | 5 +- man/available_var_impact.Rd | 8 +- man/available_var_intersec.Rd | 9 +- man/basic_graph.Rd | 11 ++- man/calc_di.Rd | 44 ++++++++-- man/elevate_hbs.Rd | 7 +- man/ex_shocks.Rd | 11 ++- man/impact.Rd | 24 +++-- man/impact_intersectional.Rd | 29 +++++-- man/intersectional_graph.Rd | 16 +++- man/load_rawhbs.Rd | 4 +- man/price_shock.Rd | 18 +++- man/rename_values.Rd | 5 +- man/standardize.Rd | 4 +- 18 files changed, 315 insertions(+), 117 deletions(-) diff --git a/R/main.R b/R/main.R index 602ba8f..a19b688 100644 --- a/R/main.R +++ b/R/main.R @@ -1,7 +1,12 @@ -# ex_shocks +#' ex_shocks #' -#' Details: function to save a csv file in which the change in prices must be introduced to apply a price shock. Save the file, introduce the price shocks and load in R.The COICOP variables of the file correspond to the aggregate variables of the package, if you are not going to aggregate the COICOP variables you have to replace the column labels by the COICOP variables that appear in your dataset. -#' @return description +#' Function to save a csv file in which the change in prices must be +#' introduced to apply a price shock. Save the file, introduce the price shocks +#' and load in R.The COICOP variables of the file correspond to the aggregate +#' variables of the package, if you are not going to aggregate the COICOP +#' variables you have to replace the column labels by the COICOP variables that +#' appear in your dataset. +#' @return a csv file in which the change in prices must be introduced to apply a price shock #' @export ex_shocks <- function(){ exshock <- get("shocks") @@ -10,17 +15,43 @@ ex_shocks <- function(){ #' calc_di #' -#' Main function to calculate the distributional impacts for different price shocks and to save the results and the figures. +#' Main function to calculate the distributional impacts for different price shocks +#' and to save the results and the figures. #' @param year year for the simulation. Available time series: 2006-2021. #' @param elevate if TRUE elevate the HBS to national accounting. If FALSE (by default) do not elevate. -#' @param shocks a dataset with the price shocks per coicop to be applied. The format of the dataset has to correspond to the predefined one in the package. To save a csv file with the right format to enter the price shocks run `ex_shocks()`. You can enter more scenarios by including more columns to the right (e.g. s3). A price shock greater than 1 indicates a price increase (e.g. 1.1 indicates a 10% increase) and less than 1 indicates a price decrease (e.g. 0.9 indicates a 10% decrease). -#' @param var_impact variable(s) according to which you want to calculate distributional impacts. If "all" (by default) calculates the distributional impacts for each of the variables specified in the package. If not, you can indicate the variable on the basis of which you want to calculate the distributional impacts. If not, you can indicate a variable or a vector of variables to calculate distributional impacts.If you want to see the variables for which the calculation is available run `available_var_impact()`. If you do not want to calculate distributional impacts per variable indicate NULL. -#' @param var_intersec set of variables (2) according to which you want to calculate the intersectional distributional impacts. If "all", it calculates the distributional impacts for each of the combinations of variables specified in the package. If not, you can indicate the set of variables according to which you want to calculate the intersectional distributional impacts. If you wish to see the set of variables for which the calculation is available, run `available_var_intersec()`. To enter a set of variables for the calculation, it must follow the same format as the output of `available_var_intersec()`, i.e. a table whose columns have category_a and category_b as their titles. If you do not want to calculate distributional impacts, indicate NULL (by default). -#' @param save if TRUE saves the dataframes with the results for the distributional impacts calculated by the function. If FALSE do not save. -#' @param file_name_impact name of the file to save the results of basic distributional impacts, if save TRUE. By default "D_impacts". -#' @param file_name_intersec name of the file to save the results of the intersectional distributional impacts, if save TRUE. By default "DI_impacts". -#' @param fig if TRUE (by default) create and save the figures of the distributional impacts calculated by the function. If FALSE do not create neither save. -#' @return a list containing the generated datasets summarising the basic or/and the intersectional distributional impacts per selected variable or set of variables. +#' @param shocks a dataset with the price shocks per coicop to be applied. +#' The format of the dataset has to correspond to the predefined one in the package. +#' To save a csv file with the right format to enter the price shocks run `ex_shocks()`. +#' You can enter more scenarios by including more columns to the right (e.g. s3). +#' A price shock greater than 1 indicates a price increase +#' (e.g. 1.1 indicates a 10\% increase) and less than 1 indicates a price decrease +#' (e.g. 0.9 indicates a 10\% decrease). +#' @param var_impact variable(s) according to which you want to calculate distributional +#' impacts. If "all" (by default) calculates the distributional impacts for each of the +#' variables specified in the package. If not, you can indicate the variable on the basis +#' of which you want to calculate the distributional impacts. If not, you can indicate a +#' variable or a vector of variables to calculate distributional impacts.If you want to +#' see the variables for which the calculation is available run `available_var_impact()`. +#' If you do not want to calculate distributional impacts per variable indicate `NULL`. +#' @param var_intersec set of variables (2) according to which you want to calculate +#' the intersectional distributional impacts. If "all", it calculates the distributional +#' impacts for each of the combinations of variables specified in the package. If not, +#' you can indicate the set of variables according to which you want to calculate the +#' intersectional distributional impacts. If you wish to see the set of variables for +#' which the calculation is available, run `available_var_intersec()`. To enter a set +#' of variables for the calculation, it must follow the same format as the output of +#' `available_var_intersec()`, i.e. a table whose columns have category_a and category_b +#' as their titles. If you do not want to calculate distributional impacts, indicate NULL (by default). +#' @param save if TRUE saves the dataframes with the results for the distributional +#' impacts calculated by the function. If FALSE do not save. +#' @param file_name_impact name of the file to save the results of basic distributional +#' impacts, if save TRUE. By default "D_impacts". +#' @param file_name_intersec name of the file to save the results of the intersectional +#' distributional impacts, if save TRUE. By default "DI_impacts". +#' @param fig if TRUE (by default) create and save the figures of the distributional +#' impacts calculated by the function. If FALSE do not create neither save. +#' @return a list containing the generated datasets summarising the basic or/and the +#' intersectional distributional impacts per selected variable or set of variables. #' @export calc_di <-function(year, elevate=F, shocks, var_impact = "all", var_intersec = NULL, save=T, file_name_impact = "D_impact", file_name_intersec = "DI_impact", fig=T) { @@ -83,18 +114,23 @@ calc_di <-function(year, elevate=F, shocks, var_impact = "all", var_intersec = N return(return_list) } -# available_var_impact +#' available_var_impact #' -#' Details: function that returns the variables for which the calculation of basic distributional impacts is available. +#' Function that returns the variables for which the calculation of +#' basic distributional impacts is available. +#' @return variables for which the calculation of basic distributional impacts is available #' @export available_var_impact <- function(){ av_var_impact <- categories$categories print(av_var_impact) } -# available_var_intersec +#' available_var_intersec #' -#' Details: function that returns the variables for which the calculation of intersectional distributional impacts is available. +#' Function that returns the set of variables for which the calculation +#' of intersectional distributional impacts is available. +#' @return set of variables for which the calculation of intersectional +#' distributional impacts is available #' @export available_var_intersec <- function(){ av_var_intersec <- is_categories diff --git a/R/utils.R b/R/utils.R index 81a183b..ba7ae87 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,9 +1,10 @@ library(usethis) library(magrittr) -# rename_values +#' rename_values #' -#' Details: function to rename the codified values of the dataset to the meaningful values detailed in the mapping included in the package. +#' Function to rename the codified values of the dataset to the meaningful +#' values detailed in the mapping included in the package. #' @param data dataset to be standardized. #' @param current_var column name to be standardized. #' @return a dataset with labels renamed based in the mapping included in the package. @@ -28,9 +29,9 @@ rename_values = function(data, current_var) { } -# standardize +#' standardize #' -#' Details: function to standarize data names. +#' Function to standarize data names. #' @param data dataset to be standardized. #' @return a dataset with the variables and labels renamed based in the mapping included in the package. #' @export @@ -61,9 +62,9 @@ standardize <- function(data) { } -# load_rawhbs +#' load_rawhbs #' -#' Details: function to load the Spanish Household Budget Survey (HBS). +#' Function to load the Spanish Household Budget Survey (HBS). #' @param year year of the HBS you want to load. #' @param path Local path to the folder where the HBS's are stored. Not included in the package. #' @return a list with the 3 files of the HBS. @@ -227,9 +228,10 @@ load_rawhbs <- function(year, path) { } -# add_coicop +#' add_coicop #' -#' Details: function to add COICOP categories in the Spanish Household Budget Survey (HBS) according to the aggregation (coicop_year) specified in the package. +#' Function to add COICOP categories in the Spanish Household Budget Survey +#' (HBS) according to the aggregation (coicop_year) specified in the package. #' @param data dataset with the data from the HBS. #' @param year year of the HBS to be modified according to the aggregation specified in the package. #' @return a dataset with HBS data where COICOP categories are aggregated according to the classification specified in the package. @@ -271,12 +273,13 @@ add_coicop <- function(data, year) { } -# elevate_hbs +#' elevate_hbs #' -#' Details: function to elevate the Spanish Household Budget Survey (HBS) to national accounting. +#' Function to elevate the Spanish Household Budget Survey (HBS) to national accounting. #' @param data dataset with the data from the HBS. #' @param year year of the HBS you want to elevate to national accounting. -#' @param country country of the HBS you want to elevate. By default "ES" (for the moment it only works for Spain, so DO NOT TOUCH). +#' @param country country of the HBS you want to elevate. By default "ES" +#' (for the moment it only works for Spain, so DO NOT TOUCH). #' @return a dataset with the HBS data where expenses are elevated to national accounting. #' @export elevate_hbs <- function(data, year, country = "ES") { @@ -415,13 +418,23 @@ elevate_hbs <- function(data, year, country = "ES") { } -# price_shock +#' price_shock #' -#' Details: function to apply a specific price shock to the different COICOP categories of the Household Budget Survey (HBS). +#' Function to apply a specific price shock to the different COICOP +#' categories of the Household Budget Survey (HBS). #' @param data input data from the HBS to apply the price shocks. -#' @param shocks a dataset with the price shocks per coicop to be applied. The format of the dataset has to correspond to the predefined one in the package. To save a csv file with the right format to enter the price shocks run `ex_shocks()`. You can enter more scenarios by including more columns to the right (e.g. s3). A price shock greater than 1 indicates a price increase (e.g. 1.1 indicates a 10% increase) and less than 1 indicates a price decrease (e.g. 0.9 indicates a 10% decrease). The COICOP variables correspond to the aggregate variables of the package, if you are not going to aggregate the COICOP variables you have to replace the column labels by the COICOP variables that appear in your dataset. +#' @param shocks a dataset with the price shocks per coicop to be applied. +#' The format of the dataset has to correspond to the predefined one in the package. +#' To save a csv file with the right format to enter the price shocks run `ex_shocks()`. +#' You can enter more scenarios by including more columns to the right (e.g. s3). +#' A price shock greater than 1 indicates a price increase (e.g. 1.1 indicates a +#' 10\% increase) and less than 1 indicates a price decrease (e.g. 0.9 indicates a +#' 10\% decrease). The COICOP variables correspond to the aggregate variables of +#' the package, if you are not going to aggregate the COICOP variables you have to +#' replace the column labels by the COICOP variables that appear in your dataset. #' @param year base year for the simulation. It must be the same as the year of the HBS. -#' @return a dataset with the HBS data and the new expenses for COICOP categories after the application of the price shock. +#' @return a dataset with the HBS data and the new expenses for COICOP categories +#' after the application of the price shock. #' @export price_shock <- function(data, shocks, year) { @@ -470,9 +483,10 @@ price_shock <- function(data, shocks, year) { } -# adjust_wh +#' adjust_wh #' -#' Details: function to adjust the width and height of a basic graph depending on the number of scenarios and labels. +#' Function to adjust the width and height of a basic graph depending +#' on the number of scenarios and labels. #' @param data a dataset used to create a basic graph. #' @param var_w variable on which the width of the basic graph depends. #' @param var_h variable on which the height of the basic graph depends. @@ -500,9 +514,10 @@ adjust_wh <- function(data, var_w, var_h) { } -# adjust_wh_is +#' adjust_wh_is #' -#' Details: function to adjust the width and height of a intersectional graph depending on the number of scenarios and labels. +#' Function to adjust the width and height of a intersectional graph +#' depending on the number of scenarios and labels. #' @param data a dataset used to create an intersectional graph. #' @param var_w variable on which the width of the intersectional graph depends. #' @param var_h variable on which the height of the intersectional graph depends. @@ -530,11 +545,16 @@ adjust_wh_is <- function(data, var_w, var_h) { } -# basic_graph +#' basic_graph #' -#' Details: function to create a basic graph to summarize the distributional impact based in one or more socioeconomic or demographic variable (one plot per variable) (INTERNAL FUNCTION). +#' Function to create a basic graph to summarize the distributional impact +#' based in one or more socioeconomic or demographic variable (one plot per variable). #' @param data a dataset with the input data needed to generate a basic graph. -#' @param var variable(s) according to which you want to generate the graph. If categories$categories (by default) creates a graph with the distributional impacts for each of the variables specified in the package. If not, you can indicate a variable or a vector of variables to crate the graph.If you want to see the variables for which the function is available run `available_var_impact()`. +#' @param var variable(s) according to which you want to generate the graph. If +#' categories$categories (by default) creates a graph with the distributional +#' impacts for each of the variables specified in the package. If not, you can +#' indicate a variable or a vector of variables to crate the graph.If you want to +#' see the variables for which the function is available run `available_var_impact()`. #' @return a graph per selected variable/s summarizing distributional impacts. #' @export basic_graph <- function(data, var = categories$categories){ @@ -563,19 +583,31 @@ basic_graph <- function(data, var = categories$categories){ } -# impact +#' impact #' -#' Details: function to calculate the distributional impacts based in one or more socioeconomic or demographic variables (one impact per variable). -#' @param data a dataset with the input data needed to calculate distributional impacts. The dataset should contain both the household expenditures collected in the HBS and the expenditures after applying the price shock. -#' @param var variable(s) according to which you want to calculate distributional impacts. If categories$categories (by default) calculates the distributional impacts for each of the variables specified in the package. If not, you can indicate a variable or a vector of variables to calculate distributional impacts.If you want to see the variables for which the calculation is available run `available_var_impact()`. -#' @param save If TRUE (by default) saves a list of the generated datasets (.RData) summarising the distributional impacts per selected variable. If FALSE do not save. +#' Function to calculate the distributional impacts based in one or more +#' socioeconomic or demographic variables (one impact per variable). +#' @param data a dataset with the input data needed to calculate distributional +#' impacts. The dataset should contain both the household expenditures collected +#' in the HBS and the expenditures after applying the price shock. +#' @param var variable(s) according to which you want to calculate distributional +#' impacts. If categories$categories (by default) calculates the distributional +#' impacts for each of the variables specified in the package. If not, you can +#' indicate a variable or a vector of variables to calculate distributional impacts. +#' If you want to see the variables for which the calculation is available run `available_var_impact()`. +#' @param save If TRUE (by default) saves a list of the generated datasets (.RData) +#' summarising the distributional impacts per selected variable. If FALSE do not save. #' @param file_name name of the file to save the results, if save TRUE. By default "D_impacts". -#' @param fig generates and saves a graph that summarises the distributional impacts. By default it is TRUE, for the graph/s not to be generated and saved indicate FALSE. -#' @return a list containing the generated datasets (.RData) summarising the distributional impacts per selected variable. +#' @param fig generates and saves a graph that summarises the distributional impacts. +#' By default it is TRUE, for the graph/s not to be generated and saved indicate FALSE. +#' @return a list containing the generated datasets (.RData) summarising the +#' distributional impacts per selected variable. #' @export impact <- function(data, var = categories$categories, save = T, file_name = "D_impacts", fig = T) { d_impacts = list() # Generamos una lista vacia + missing_vars = c() + for (g in var) { if (g %in% colnames(data)) { gastotS_cols <- grep("^GASTOT_s", names(data), value = TRUE) # generamos un vector con todos los nombres que empiecen por GASTOT_s @@ -591,7 +623,8 @@ impact <- function(data, var = categories$categories, save = T, file_name = "D_i ) d_impacts[[paste0('di_',g)]] = get(paste0('di_',g)) # añadir el resultado a la lista con el nombre di_g } else { - warning(paste0(var, " is not present in the dataset")) + missing_vars <- c(missing_vars, g) + warning(paste0(g, " is not present in the dataset")) } } @@ -602,7 +635,7 @@ impact <- function(data, var = categories$categories, save = T, file_name = "D_i if (fig == T) { - + var <- setdiff(var, missing_vars) basic_graph(data = d_impacts, var) } @@ -612,11 +645,21 @@ impact <- function(data, var = categories$categories, save = T, file_name = "D_i } -# intersectional_graph +#' intersectional_graph #' -#' Details: function to create an intersectional graph to summarize the distributional impact based in the intersection of two socioeconomic or demographic variables (2 variables per plot). +#' Function to create an intersectional graph to summarize the distributional +#' impact based in the intersection of two socioeconomic or demographic variables +#' (2 variables per plot). #' @param data a dataset with the input data needed to generate the intersectional graph. -#' @param pairs set of variables (2) according to which you want to create the intersectional graph. If is_categories (by default), it generates the intersectional graph for each of the combinations of variables specified in the package. If not, you can indicate the set of variables according to which you want to generste the intersectional graph. If you wish to see the set of variables for which the calculation is available, run `available_var_intersec()`. To enter a set of variables for the calculation, it must follow the same format as the output of `available_var_intersec()`, i.e. a table whose columns have category_a and category_b as their titles. +#' @param pairs set of variables (2) according to which you want to create the +#' intersectional graph. If is_categories (by default), it generates the intersectional +#' graph for each of the combinations of variables specified in the package. If not, +#' you can indicate the set of variables according to which you want to generste the +#' intersectional graph. If you wish to see the set of variables for which the +#' calculation is available, run `available_var_intersec()`. To enter a set of +#' variables for the calculation, it must follow the same format as the output of +#' `available_var_intersec()`, i.e. a table whose columns have category_a and +#' category_b as their titles. #' @return a graph per selected set of variables summarizing the distributional impacts. #' @export intersectional_graph <- function(data, pairs = is_categories){ @@ -645,20 +688,36 @@ intersectional_graph <- function(data, pairs = is_categories){ } -# impact_intersectional +#' impact_intersectional #' -#' Details: function to calculate the distributional impacts based in the intersection of two socioeconomic or demographic variables (2 variables per impact). -#' @param data a dataset with the input data needed to calculate the intersectional distributional impacts. The dataset should contain both the household expenditures collected in the HBS and the expenditures after applying the price shock. -#' @param pairs set of variables (2) according to which you want to calculate distributional impacts. If is_categories (by default) calculates the intersectional distributional impacts for each of the set of variables specified in the package. If not, you can indicate the set of variables according to which you want to calculate the intersectional distributional impacts.If you want to see the set of variables for which the calculation is available run `available_var_intersec()`. To enter a set of variables for the calculation, it must follow the same format as the output of `available_var_intersec()`, i.e. a table whose columns have category_a and category_b as their titles. -#' @param save If TRUE (by default) saves a list of the generated datasets (.RData) summarising the intersectional distributional impacts per selected set of variable. If FALSE do not save. +#' Function to calculate the distributional impacts based in the intersection +#' of two socioeconomic or demographic variables (2 variables per impact). +#' @param data a dataset with the input data needed to calculate the intersectional +#' distributional impacts. The dataset should contain both the household expenditures +#' collected in the HBS and the expenditures after applying the price shock. +#' @param pairs set of variables (2) according to which you want to calculate +#' distributional impacts. If is_categories (by default) calculates the intersectional +#' distributional impacts for each of the set of variables specified in the package. +#' If not, you can indicate the set of variables according to which you want to calculate +#' the intersectional distributional impacts.If you want to see the set of variables for +#' which the calculation is available run `available_var_intersec()`. To enter a +#' set of variables for the calculation, it must follow the same format as the +#' output of `available_var_intersec()`, i.e. a table whose columns have category_a +#' and category_b as their titles. +#' @param save If TRUE (by default) saves a list of the generated datasets (.RData) +#' summarising the intersectional distributional impacts per selected set of variable. +#' If FALSE do not save. #' @param file_name name of the file to save the results, if save TRUE. By default "DI_impacts". -#' @param fig generates and saves a graph that summarises the intersectional distributional impacts. By default it is TRUE, for the graph/s not to be generated and saved indicate FALSE. -#' @return a list containing the generated datasets (.RData) summarising the intersectional distributional impacts per selected set of variables. +#' @param fig generates and saves a graph that summarises the intersectional distributional +#' impacts. By default it is TRUE, for the graph/s not to be generated and saved indicate FALSE. +#' @return a list containing the generated datasets (.RData) summarising the intersectional +#' distributional impacts per selected set of variables. #' @export impact_intersectional <- function(data, pairs = is_categories, save = T, file_name = "DI_impact", fig = T) { is_d_impacts = list() # Generamos una lista vacia - for (r in 1:nrow(pairs)) { # para el numero de filas de pairs + missing_vars = c() + for (r in 1:nrow(pairs)) { # para el numero de filas de pairs var_a = pairs$category_a[r] # te coge el valor de pair en la columna a en la row r var_b = pairs$category_b[r] # te coge el valor de pair en la columna a en la row r # ensure that var_a and var_b are in the dataset (as column names) @@ -677,9 +736,15 @@ impact_intersectional <- function(data, pairs = is_categories, save = T, file_na ) is_d_impacts[[paste0('di_',var_a,'_',var_b)]] = get(paste0('di_',var_a,'_',var_b)) # añadir el resultado a la lista con el nombre di_g } else { - if (var_a %in% colnames(data) & !var_b %in% colnames(data)) {warning(paste0(var_b," is not present in the dataset"))} - else if (!var_a %in% colnames(data) & var_b %in% colnames(data)) {warning(paste0(var_a," is not present in the dataset"))} - else {warning(paste0(var_a, "and ", var_b," are not present in the dataset"))} + if (var_a %in% colnames(data) & !var_b %in% colnames(data)) { + missing_vars <- c(missing_vars, var_b) + warning(paste0(var_b," is not present in the dataset"))} + else if (!var_a %in% colnames(data) & var_b %in% colnames(data)) { + missing_vars <- c(missing_vars, var_a) + warning(paste0(var_a," is not present in the dataset"))} + else { + missing_vars <- c(missing_vars, var_a, var_b) + warning(paste0(var_a, "and ", var_b," are not present in the dataset"))} } } @@ -689,7 +754,9 @@ impact_intersectional <- function(data, pairs = is_categories, save = T, file_na } if (fig == T) { - + pairs <- pairs %>% + dplyr::filter(!category_a %in% missing_vars, + !category_b %in% missing_vars) intersectional_graph(data = is_d_impacts, pairs) } diff --git a/man/add_coicop.Rd b/man/add_coicop.Rd index 84fb772..d7ea311 100644 --- a/man/add_coicop.Rd +++ b/man/add_coicop.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/utils.R \name{add_coicop} \alias{add_coicop} -\title{Details: function to add COICOP categories in the Spanish Household Budget Survey (HBS) according to the aggregation (coicop_year) specified in the package.} +\title{add_coicop} \usage{ add_coicop(data, year) } @@ -15,5 +15,6 @@ add_coicop(data, year) a dataset with HBS data where COICOP categories are aggregated according to the classification specified in the package. } \description{ -Details: function to add COICOP categories in the Spanish Household Budget Survey (HBS) according to the aggregation (coicop_year) specified in the package. +Function to add COICOP categories in the Spanish Household Budget Survey +(HBS) according to the aggregation (coicop_year) specified in the package. } diff --git a/man/adjust_wh.Rd b/man/adjust_wh.Rd index aafd6d0..d8145b7 100644 --- a/man/adjust_wh.Rd +++ b/man/adjust_wh.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/utils.R \name{adjust_wh} \alias{adjust_wh} -\title{Details: function to adjust the width and height of a basic graph depending on the number of scenarios and labels.} +\title{adjust_wh} \usage{ adjust_wh(data, var_w, var_h) } @@ -17,5 +17,6 @@ adjust_wh(data, var_w, var_h) a list containing the width and the height of the basic graph to be created. } \description{ -Details: function to adjust the width and height of a basic graph depending on the number of scenarios and labels. +Function to adjust the width and height of a basic graph depending +on the number of scenarios and labels. } diff --git a/man/adjust_wh_is.Rd b/man/adjust_wh_is.Rd index 315ea61..62925ae 100644 --- a/man/adjust_wh_is.Rd +++ b/man/adjust_wh_is.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/utils.R \name{adjust_wh_is} \alias{adjust_wh_is} -\title{Details: function to adjust the width and height of a intersectional graph depending on the number of scenarios and labels.} +\title{adjust_wh_is} \usage{ adjust_wh_is(data, var_w, var_h) } @@ -17,5 +17,6 @@ adjust_wh_is(data, var_w, var_h) a list containing the width and the height of the intersectional graph to be created. } \description{ -Details: function to adjust the width and height of a intersectional graph depending on the number of scenarios and labels. +Function to adjust the width and height of a intersectional graph +depending on the number of scenarios and labels. } diff --git a/man/available_var_impact.Rd b/man/available_var_impact.Rd index 2b65891..0adf3ef 100644 --- a/man/available_var_impact.Rd +++ b/man/available_var_impact.Rd @@ -2,10 +2,14 @@ % Please edit documentation in R/main.R \name{available_var_impact} \alias{available_var_impact} -\title{Details: function that returns the variables for which the calculation of basic distributional impacts is available.} +\title{available_var_impact} \usage{ available_var_impact() } +\value{ +variables for which the calculation of basic distributional impacts is available +} \description{ -Details: function that returns the variables for which the calculation of basic distributional impacts is available. +Function that returns the variables for which the calculation of +basic distributional impacts is available. } diff --git a/man/available_var_intersec.Rd b/man/available_var_intersec.Rd index e535bb6..0144a5c 100644 --- a/man/available_var_intersec.Rd +++ b/man/available_var_intersec.Rd @@ -2,10 +2,15 @@ % Please edit documentation in R/main.R \name{available_var_intersec} \alias{available_var_intersec} -\title{Details: function that returns the variables for which the calculation of intersectional distributional impacts is available.} +\title{available_var_intersec} \usage{ available_var_intersec() } +\value{ +set of variables for which the calculation of intersectional +distributional impacts is available +} \description{ -Details: function that returns the variables for which the calculation of intersectional distributional impacts is available. +Function that returns the set of variables for which the calculation +of intersectional distributional impacts is available. } diff --git a/man/basic_graph.Rd b/man/basic_graph.Rd index 2894992..8009dfa 100644 --- a/man/basic_graph.Rd +++ b/man/basic_graph.Rd @@ -2,18 +2,23 @@ % Please edit documentation in R/utils.R \name{basic_graph} \alias{basic_graph} -\title{Details: function to create a basic graph to summarize the distributional impact based in one or more socioeconomic or demographic variable (one plot per variable) (INTERNAL FUNCTION).} +\title{basic_graph} \usage{ basic_graph(data, var = categories$categories) } \arguments{ \item{data}{a dataset with the input data needed to generate a basic graph.} -\item{var}{variable(s) according to which you want to generate the graph. If categories$categories (by default) creates a graph with the distributional impacts for each of the variables specified in the package. If not, you can indicate a variable or a vector of variables to crate the graph.If you want to see the variables for which the function is available run `available_var_impact()`.} +\item{var}{variable(s) according to which you want to generate the graph. If +categories$categories (by default) creates a graph with the distributional +impacts for each of the variables specified in the package. If not, you can +indicate a variable or a vector of variables to crate the graph.If you want to +see the variables for which the function is available run `available_var_impact()`.} } \value{ a graph per selected variable/s summarizing distributional impacts. } \description{ -Details: function to create a basic graph to summarize the distributional impact based in one or more socioeconomic or demographic variable (one plot per variable) (INTERNAL FUNCTION). +Function to create a basic graph to summarize the distributional impact +based in one or more socioeconomic or demographic variable (one plot per variable). } diff --git a/man/calc_di.Rd b/man/calc_di.Rd index a2b6289..43bb811 100644 --- a/man/calc_di.Rd +++ b/man/calc_di.Rd @@ -21,23 +21,49 @@ calc_di( \item{elevate}{if TRUE elevate the HBS to national accounting. If FALSE (by default) do not elevate.} -\item{shocks}{a dataset with the price shocks per coicop to be applied. The format of the dataset has to correspond to the predefined one in the package. To save a csv file with the right format to enter the price shocks run `ex_shocks()`. You can enter more scenarios by including more columns to the right (e.g. s3). A price shock greater than 1 indicates a price increase (e.g. 1.1 indicates a 10% increase) and less than 1 indicates a price decrease (e.g. 0.9 indicates a 10% decrease).} +\item{shocks}{a dataset with the price shocks per coicop to be applied. +The format of the dataset has to correspond to the predefined one in the package. +To save a csv file with the right format to enter the price shocks run `ex_shocks()`. +You can enter more scenarios by including more columns to the right (e.g. s3). +A price shock greater than 1 indicates a price increase +(e.g. 1.1 indicates a 10\% increase) and less than 1 indicates a price decrease +(e.g. 0.9 indicates a 10\% decrease).} -\item{var_impact}{variable(s) according to which you want to calculate distributional impacts. If "all" (by default) calculates the distributional impacts for each of the variables specified in the package. If not, you can indicate the variable on the basis of which you want to calculate the distributional impacts. If not, you can indicate a variable or a vector of variables to calculate distributional impacts.If you want to see the variables for which the calculation is available run `available_var_impact()`. If you do not want to calculate distributional impacts per variable indicate NULL.} +\item{var_impact}{variable(s) according to which you want to calculate distributional +impacts. If "all" (by default) calculates the distributional impacts for each of the +variables specified in the package. If not, you can indicate the variable on the basis +of which you want to calculate the distributional impacts. If not, you can indicate a +variable or a vector of variables to calculate distributional impacts.If you want to +see the variables for which the calculation is available run `available_var_impact()`. +If you do not want to calculate distributional impacts per variable indicate `NULL`.} -\item{var_intersec}{set of variables (2) according to which you want to calculate the intersectional distributional impacts. If "all", it calculates the distributional impacts for each of the combinations of variables specified in the package. If not, you can indicate the set of variables according to which you want to calculate the intersectional distributional impacts. If you wish to see the set of variables for which the calculation is available, run `available_var_intersec()`. To enter a set of variables for the calculation, it must follow the same format as the output of `available_var_intersec()`, i.e. a table whose columns have category_a and category_b as their titles. If you do not want to calculate distributional impacts, indicate NULL (by default).} +\item{var_intersec}{set of variables (2) according to which you want to calculate +the intersectional distributional impacts. If "all", it calculates the distributional +impacts for each of the combinations of variables specified in the package. If not, +you can indicate the set of variables according to which you want to calculate the +intersectional distributional impacts. If you wish to see the set of variables for +which the calculation is available, run `available_var_intersec()`. To enter a set +of variables for the calculation, it must follow the same format as the output of +`available_var_intersec()`, i.e. a table whose columns have category_a and category_b +as their titles. If you do not want to calculate distributional impacts, indicate NULL (by default).} -\item{save}{if TRUE saves the dataframes with the results for the distributional impacts calculated by the function. If FALSE do not save.} +\item{save}{if TRUE saves the dataframes with the results for the distributional +impacts calculated by the function. If FALSE do not save.} -\item{file_name_impact}{name of the file to save the results of basic distributional impacts, if save TRUE. By default "D_impacts".} +\item{file_name_impact}{name of the file to save the results of basic distributional +impacts, if save TRUE. By default "D_impacts".} -\item{file_name_intersec}{name of the file to save the results of the intersectional distributional impacts, if save TRUE. By default "DI_impacts".} +\item{file_name_intersec}{name of the file to save the results of the intersectional +distributional impacts, if save TRUE. By default "DI_impacts".} -\item{fig}{if TRUE (by default) create and save the figures of the distributional impacts calculated by the function. If FALSE do not create neither save.} +\item{fig}{if TRUE (by default) create and save the figures of the distributional +impacts calculated by the function. If FALSE do not create neither save.} } \value{ -a list containing the generated datasets summarising the basic or/and the intersectional distributional impacts per selected variable or set of variables. +a list containing the generated datasets summarising the basic or/and the +intersectional distributional impacts per selected variable or set of variables. } \description{ -Main function to calculate the distributional impacts for different price shocks and to save the results and the figures. +Main function to calculate the distributional impacts for different price shocks +and to save the results and the figures. } diff --git a/man/elevate_hbs.Rd b/man/elevate_hbs.Rd index 38b8fb5..bba8d9a 100644 --- a/man/elevate_hbs.Rd +++ b/man/elevate_hbs.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/utils.R \name{elevate_hbs} \alias{elevate_hbs} -\title{Details: function to elevate the Spanish Household Budget Survey (HBS) to national accounting.} +\title{elevate_hbs} \usage{ elevate_hbs(data, year, country = "ES") } @@ -11,11 +11,12 @@ elevate_hbs(data, year, country = "ES") \item{year}{year of the HBS you want to elevate to national accounting.} -\item{country}{country of the HBS you want to elevate. By default "ES" (for the moment it only works for Spain, so DO NOT TOUCH).} +\item{country}{country of the HBS you want to elevate. By default "ES" +(for the moment it only works for Spain, so DO NOT TOUCH).} } \value{ a dataset with the HBS data where expenses are elevated to national accounting. } \description{ -Details: function to elevate the Spanish Household Budget Survey (HBS) to national accounting. +Function to elevate the Spanish Household Budget Survey (HBS) to national accounting. } diff --git a/man/ex_shocks.Rd b/man/ex_shocks.Rd index ddf87f0..9530aa6 100644 --- a/man/ex_shocks.Rd +++ b/man/ex_shocks.Rd @@ -2,13 +2,18 @@ % Please edit documentation in R/main.R \name{ex_shocks} \alias{ex_shocks} -\title{Details: function to save a csv file in which the change in prices must be introduced to apply a price shock. Save the file, introduce the price shocks and load in R.The COICOP variables of the file correspond to the aggregate variables of the package, if you are not going to aggregate the COICOP variables you have to replace the column labels by the COICOP variables that appear in your dataset.} +\title{ex_shocks} \usage{ ex_shocks() } \value{ -description +a csv file in which the change in prices must be introduced to apply a price shock } \description{ -Details: function to save a csv file in which the change in prices must be introduced to apply a price shock. Save the file, introduce the price shocks and load in R.The COICOP variables of the file correspond to the aggregate variables of the package, if you are not going to aggregate the COICOP variables you have to replace the column labels by the COICOP variables that appear in your dataset. +Function to save a csv file in which the change in prices must be +introduced to apply a price shock. Save the file, introduce the price shocks +and load in R.The COICOP variables of the file correspond to the aggregate +variables of the package, if you are not going to aggregate the COICOP +variables you have to replace the column labels by the COICOP variables that +appear in your dataset. } diff --git a/man/impact.Rd b/man/impact.Rd index c101075..9d9f3af 100644 --- a/man/impact.Rd +++ b/man/impact.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/utils.R \name{impact} \alias{impact} -\title{Details: function to calculate the distributional impacts based in one or more socioeconomic or demographic variables (one impact per variable).} +\title{impact} \usage{ impact( data, @@ -13,19 +13,29 @@ impact( ) } \arguments{ -\item{data}{a dataset with the input data needed to calculate distributional impacts. The dataset should contain both the household expenditures collected in the HBS and the expenditures after applying the price shock.} +\item{data}{a dataset with the input data needed to calculate distributional +impacts. The dataset should contain both the household expenditures collected +in the HBS and the expenditures after applying the price shock.} -\item{var}{variable(s) according to which you want to calculate distributional impacts. If categories$categories (by default) calculates the distributional impacts for each of the variables specified in the package. If not, you can indicate a variable or a vector of variables to calculate distributional impacts.If you want to see the variables for which the calculation is available run `available_var_impact()`.} +\item{var}{variable(s) according to which you want to calculate distributional +impacts. If categories$categories (by default) calculates the distributional +impacts for each of the variables specified in the package. If not, you can +indicate a variable or a vector of variables to calculate distributional impacts. +If you want to see the variables for which the calculation is available run `available_var_impact()`.} -\item{save}{If TRUE (by default) saves a list of the generated datasets (.RData) summarising the distributional impacts per selected variable. If FALSE do not save.} +\item{save}{If TRUE (by default) saves a list of the generated datasets (.RData) +summarising the distributional impacts per selected variable. If FALSE do not save.} \item{file_name}{name of the file to save the results, if save TRUE. By default "D_impacts".} -\item{fig}{generates and saves a graph that summarises the distributional impacts. By default it is TRUE, for the graph/s not to be generated and saved indicate FALSE.} +\item{fig}{generates and saves a graph that summarises the distributional impacts. +By default it is TRUE, for the graph/s not to be generated and saved indicate FALSE.} } \value{ -a list containing the generated datasets (.RData) summarising the distributional impacts per selected variable. +a list containing the generated datasets (.RData) summarising the +distributional impacts per selected variable. } \description{ -Details: function to calculate the distributional impacts based in one or more socioeconomic or demographic variables (one impact per variable). +Function to calculate the distributional impacts based in one or more +socioeconomic or demographic variables (one impact per variable). } diff --git a/man/impact_intersectional.Rd b/man/impact_intersectional.Rd index 418df4d..acd8928 100644 --- a/man/impact_intersectional.Rd +++ b/man/impact_intersectional.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/utils.R \name{impact_intersectional} \alias{impact_intersectional} -\title{Details: function to calculate the distributional impacts based in the intersection of two socioeconomic or demographic variables (2 variables per impact).} +\title{impact_intersectional} \usage{ impact_intersectional( data, @@ -13,19 +13,34 @@ impact_intersectional( ) } \arguments{ -\item{data}{a dataset with the input data needed to calculate the intersectional distributional impacts. The dataset should contain both the household expenditures collected in the HBS and the expenditures after applying the price shock.} +\item{data}{a dataset with the input data needed to calculate the intersectional +distributional impacts. The dataset should contain both the household expenditures +collected in the HBS and the expenditures after applying the price shock.} -\item{pairs}{set of variables (2) according to which you want to calculate distributional impacts. If is_categories (by default) calculates the intersectional distributional impacts for each of the set of variables specified in the package. If not, you can indicate the set of variables according to which you want to calculate the intersectional distributional impacts.If you want to see the set of variables for which the calculation is available run `available_var_intersec()`. To enter a set of variables for the calculation, it must follow the same format as the output of `available_var_intersec()`, i.e. a table whose columns have category_a and category_b as their titles.} +\item{pairs}{set of variables (2) according to which you want to calculate +distributional impacts. If is_categories (by default) calculates the intersectional +distributional impacts for each of the set of variables specified in the package. +If not, you can indicate the set of variables according to which you want to calculate +the intersectional distributional impacts.If you want to see the set of variables for +which the calculation is available run `available_var_intersec()`. To enter a +set of variables for the calculation, it must follow the same format as the +output of `available_var_intersec()`, i.e. a table whose columns have category_a +and category_b as their titles.} -\item{save}{If TRUE (by default) saves a list of the generated datasets (.RData) summarising the intersectional distributional impacts per selected set of variable. If FALSE do not save.} +\item{save}{If TRUE (by default) saves a list of the generated datasets (.RData) +summarising the intersectional distributional impacts per selected set of variable. +If FALSE do not save.} \item{file_name}{name of the file to save the results, if save TRUE. By default "DI_impacts".} -\item{fig}{generates and saves a graph that summarises the intersectional distributional impacts. By default it is TRUE, for the graph/s not to be generated and saved indicate FALSE.} +\item{fig}{generates and saves a graph that summarises the intersectional distributional +impacts. By default it is TRUE, for the graph/s not to be generated and saved indicate FALSE.} } \value{ -a list containing the generated datasets (.RData) summarising the intersectional distributional impacts per selected set of variables. +a list containing the generated datasets (.RData) summarising the intersectional +distributional impacts per selected set of variables. } \description{ -Details: function to calculate the distributional impacts based in the intersection of two socioeconomic or demographic variables (2 variables per impact). +Function to calculate the distributional impacts based in the intersection +of two socioeconomic or demographic variables (2 variables per impact). } diff --git a/man/intersectional_graph.Rd b/man/intersectional_graph.Rd index c90a9de..2d10b81 100644 --- a/man/intersectional_graph.Rd +++ b/man/intersectional_graph.Rd @@ -2,18 +2,28 @@ % Please edit documentation in R/utils.R \name{intersectional_graph} \alias{intersectional_graph} -\title{Details: function to create an intersectional graph to summarize the distributional impact based in the intersection of two socioeconomic or demographic variables (2 variables per plot).} +\title{intersectional_graph} \usage{ intersectional_graph(data, pairs = is_categories) } \arguments{ \item{data}{a dataset with the input data needed to generate the intersectional graph.} -\item{pairs}{set of variables (2) according to which you want to create the intersectional graph. If is_categories (by default), it generates the intersectional graph for each of the combinations of variables specified in the package. If not, you can indicate the set of variables according to which you want to generste the intersectional graph. If you wish to see the set of variables for which the calculation is available, run `available_var_intersec()`. To enter a set of variables for the calculation, it must follow the same format as the output of `available_var_intersec()`, i.e. a table whose columns have category_a and category_b as their titles.} +\item{pairs}{set of variables (2) according to which you want to create the +intersectional graph. If is_categories (by default), it generates the intersectional +graph for each of the combinations of variables specified in the package. If not, +you can indicate the set of variables according to which you want to generste the +intersectional graph. If you wish to see the set of variables for which the +calculation is available, run `available_var_intersec()`. To enter a set of +variables for the calculation, it must follow the same format as the output of +`available_var_intersec()`, i.e. a table whose columns have category_a and +category_b as their titles.} } \value{ a graph per selected set of variables summarizing the distributional impacts. } \description{ -Details: function to create an intersectional graph to summarize the distributional impact based in the intersection of two socioeconomic or demographic variables (2 variables per plot). +Function to create an intersectional graph to summarize the distributional +impact based in the intersection of two socioeconomic or demographic variables +(2 variables per plot). } diff --git a/man/load_rawhbs.Rd b/man/load_rawhbs.Rd index 705bec0..1c22b56 100644 --- a/man/load_rawhbs.Rd +++ b/man/load_rawhbs.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/utils.R \name{load_rawhbs} \alias{load_rawhbs} -\title{Details: function to load the Spanish Household Budget Survey (HBS).} +\title{load_rawhbs} \usage{ load_rawhbs(year, path) } @@ -15,5 +15,5 @@ load_rawhbs(year, path) a list with the 3 files of the HBS. } \description{ -Details: function to load the Spanish Household Budget Survey (HBS). +Function to load the Spanish Household Budget Survey (HBS). } diff --git a/man/price_shock.Rd b/man/price_shock.Rd index 81a3cbe..66c1f80 100644 --- a/man/price_shock.Rd +++ b/man/price_shock.Rd @@ -2,20 +2,30 @@ % Please edit documentation in R/utils.R \name{price_shock} \alias{price_shock} -\title{Details: function to apply a specific price shock to the different COICOP categories of the Household Budget Survey (HBS).} +\title{price_shock} \usage{ price_shock(data, shocks, year) } \arguments{ \item{data}{input data from the HBS to apply the price shocks.} -\item{shocks}{a dataset with the price shocks per coicop to be applied. The format of the dataset has to correspond to the predefined one in the package. To save a csv file with the right format to enter the price shocks run `ex_shocks()`. You can enter more scenarios by including more columns to the right (e.g. s3). A price shock greater than 1 indicates a price increase (e.g. 1.1 indicates a 10% increase) and less than 1 indicates a price decrease (e.g. 0.9 indicates a 10% decrease). The COICOP variables correspond to the aggregate variables of the package, if you are not going to aggregate the COICOP variables you have to replace the column labels by the COICOP variables that appear in your dataset.} +\item{shocks}{a dataset with the price shocks per coicop to be applied. +The format of the dataset has to correspond to the predefined one in the package. +To save a csv file with the right format to enter the price shocks run `ex_shocks()`. +You can enter more scenarios by including more columns to the right (e.g. s3). +A price shock greater than 1 indicates a price increase (e.g. 1.1 indicates a +10\% increase) and less than 1 indicates a price decrease (e.g. 0.9 indicates a +10\% decrease). The COICOP variables correspond to the aggregate variables of +the package, if you are not going to aggregate the COICOP variables you have to +replace the column labels by the COICOP variables that appear in your dataset.} \item{year}{base year for the simulation. It must be the same as the year of the HBS.} } \value{ -a dataset with the HBS data and the new expenses for COICOP categories after the application of the price shock. +a dataset with the HBS data and the new expenses for COICOP categories +after the application of the price shock. } \description{ -Details: function to apply a specific price shock to the different COICOP categories of the Household Budget Survey (HBS). +Function to apply a specific price shock to the different COICOP +categories of the Household Budget Survey (HBS). } diff --git a/man/rename_values.Rd b/man/rename_values.Rd index 362efc8..f8ce733 100644 --- a/man/rename_values.Rd +++ b/man/rename_values.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/utils.R \name{rename_values} \alias{rename_values} -\title{Details: function to rename the codified values of the dataset to the meaningful values detailed in the mapping included in the package.} +\title{rename_values} \usage{ rename_values(data, current_var) } @@ -15,5 +15,6 @@ rename_values(data, current_var) a dataset with labels renamed based in the mapping included in the package. } \description{ -Details: function to rename the codified values of the dataset to the meaningful values detailed in the mapping included in the package. +Function to rename the codified values of the dataset to the meaningful +values detailed in the mapping included in the package. } diff --git a/man/standardize.Rd b/man/standardize.Rd index 19cfd74..52b18cc 100644 --- a/man/standardize.Rd +++ b/man/standardize.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/utils.R \name{standardize} \alias{standardize} -\title{Details: function to standarize data names.} +\title{standardize} \usage{ standardize(data) } @@ -13,5 +13,5 @@ standardize(data) a dataset with the variables and labels renamed based in the mapping included in the package. } \description{ -Details: function to standarize data names. +Function to standarize data names. }