Skip to content

Instantly share code, notes, and snippets.

@maurolepore
Last active August 3, 2021 20:23
Show Gist options
  • Save maurolepore/d06031455f8bfbfeb1f3dad4ae1e2590 to your computer and use it in GitHub Desktop.
Save maurolepore/d06031455f8bfbfeb1f3dad4ae1e2590 to your computer and use it in GitHub Desktop.
#' Calculate the nevitable Policy Response (IPR)
#'
#' @param plan_x What is this?
#' @param scen_start  What is this?
#' @param scen_end  What is this?
#' @param year_x  What is this?
#' @param year_start  What is this?
#' @param year_end  What is this?
#'
ipr_technology <- function(plan_x, scen_start, scen_end, year_x, year_start, year_end) {
  relative_prod <- (scen_end - plan_x) / (scen_end - scen_start)
  relative_time <- (year_end - year_start) / (year_end - year_x)

  max(c(0, relative_prod * relative_time))
}

ipr_technology(
  plan_x = 100,
  scen_start = 200,
  scen_end = 150,
  year_x = 2040,
  year_start = 2020,
  year_end = 2025
)
#> [1] 0.3333333

ipr_technology(
  plan_x = 300,
  scen_start = 200,
  scen_end = 150,
  year_x = 2040,
  year_start = 2020,
  year_end = 2025
)
#> [1] 0

Created on 2021-08-03 by the reprex package (v2.0.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment