Skip to contents

scenario_linear_change() to add a linear_value percentage point change to baseline_value from a baseline_year. It provides values for scenarios stated as "Increase INDICATOR by XX% points".

scenario_linear_change_col() wraps around scenario_linear_change() to provide linear values from a column specified in linear_value rather than a single value.

The calculation is done by taking the baseline_year value_col and adding the linear_value times the number of years between the baseline year and the current year. For instance, if baseline_year is 2018, linear_value is 2, and baseline_year value_col is 10, then 2019 value_col will be 12, 2020 14, etc.

It differs from scenario_aroc() percent_change in two ways: it is not compounded and it adds percentage points and not percentage of values.

upper_limit and lower_limit allow to trim values when they are exceeding the bounds after calculations. If values were already exceeding the bounds before calculations, they are kept.

Usage

scenario_linear_change(
  df,
  linear_value,
  value_col = "value",
  start_year = 2018,
  end_year = 2025,
  baseline_year = start_year,
  target_year = end_year,
  scenario_name = glue::glue("linear_change"),
  scenario_col = "scenario",
  trim = TRUE,
  small_is_best = FALSE,
  keep_better_values = FALSE,
  upper_limit = 100,
  lower_limit = 0,
  trim_years = TRUE,
  start_year_trim = start_year,
  end_year_trim = end_year,
  ind_ids = billion_ind_codes("all"),
  default_scenario = "default"
)

scenario_linear_change_col(
  df,
  linear_value_col,
  value_col = "value",
  start_year = 2018,
  end_year = 2025,
  baseline_year = start_year,
  target_year = end_year,
  scenario_col = "scenario",
  scenario_name = glue::glue("linear_change"),
  trim = TRUE,
  small_is_best = FALSE,
  keep_better_values = FALSE,
  upper_limit = 100,
  lower_limit = 0,
  trim_years = TRUE,
  start_year_trim = start_year,
  end_year_trim = end_year,
  ind_ids = billion_ind_codes("all"),
  default_scenario = "default"
)

Arguments

df

Data frame in long format, where 1 row corresponds to a specific country, year, and indicator.

linear_value

vector indicating the increase to apply.

value_col

Column name of column with indicator values.

start_year

Start year for scenario, defaults to 2018.

end_year

End year for scenario, defaults to 2025

baseline_year

Year from which the scenario is measured. Defaults to start_year

target_year

Year by which the scenario should eventually be achieved. Defaults to end_year

scenario_name

Name of the scenario. Defaults to scenario_percent_change_baseline_year

scenario_col

Column name of column with scenario identifiers. Useful for calculating contributions on data in long format rather than wide format.

trim

logical to indicate if the data should be trimmed between upper_limit and lower_limit.

small_is_best

Logical to identify if a lower value is better than a higher one (e.g. lower obesity in a positive public health outcome, so obesity rate should have small_is_best = TRUE).

keep_better_values

logical to indicate if "better" values should be kept from value_col if they are present. Follows the direction set in small_is_best. For instance, if small_is_best is TRUE, then value_col lower than col will be kept.

upper_limit

numeric indicating the upper bound of the data after calculation. If value_col is already higher before calculation it will be kept

lower_limit

numeric indicating the lower bound of the data after calculation. If value_col is already lower before calculation it will be kept

trim_years

logical to indicate if years before start_year_trim and after end_year_trim should be removed

start_year_trim

(integer) year to start trimming from.

end_year_trim

(integer) year to end trimming.

ind_ids

Named vector of indicator codes for input indicators to the Billion. Although separate indicator codes can be used than the standard, they must be supplied as a named vector where the names correspond to the output of billion_ind_codes().

default_scenario

name of the default scenario to be used.

linear_value_col

name of column with linear values