From da44fcd6c870229d5601479dad816ebdef2c9a45 Mon Sep 17 00:00:00 2001 From: Debbora Leip Date: Mon, 9 Oct 2023 22:06:49 +0200 Subject: [PATCH] updated wage validation --- .buildlibrary | 2 +- .pre-commit-config.yaml | 2 +- CITATION.cff | 4 +-- DESCRIPTION | 4 +-- R/calcValidHourlyLaborCosts.R | 57 +++++++++++++++++++++++++------- R/calcValidWageDevelopment.R | 32 +++++++++--------- R/fullVALIDATION.R | 18 ++++++---- README.md | 6 ++-- man/calcValidHourlyLaborCosts.Rd | 11 ++++-- man/calcValidWageDevelopment.Rd | 9 +++-- 10 files changed, 97 insertions(+), 48 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index f8e29a1..32fecef 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '49342278' +ValidationKey: '49392085' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5d2e4ca..7a47c41 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,7 @@ repos: - id: mixed-line-ending - repo: https://github.com/lorenzwalthert/precommit - rev: v0.3.2.9019 + rev: v0.3.2.9021 hooks: - id: parsable-R - id: deps-in-desc diff --git a/CITATION.cff b/CITATION.cff index b2c1930..0fd7945 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,8 +2,8 @@ cff-version: 1.2.0 message: If you use this software, please cite it using the metadata from this file. type: software title: 'mrvalidation: madrat data preparation for validation purposes' -version: 2.51.4 -date-released: '2023-09-27' +version: 2.51.5 +date-released: '2023-10-09' abstract: Package contains routines to prepare data for validation exercises. authors: - family-names: Bodirsky diff --git a/DESCRIPTION b/DESCRIPTION index d407b08..13b4087 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: mrvalidation Title: madrat data preparation for validation purposes -Version: 2.51.4 -Date: 2023-09-27 +Version: 2.51.5 +Date: 2023-10-09 Authors@R: c( person("Benjamin Leon", "Bodirsky", , "bodirsky@pik-potsdam.de", role = c("aut", "cre")), person("Stephen", "Wirth", role = "aut"), diff --git a/R/calcValidHourlyLaborCosts.R b/R/calcValidHourlyLaborCosts.R index aa6f566..677ecf6 100644 --- a/R/calcValidHourlyLaborCosts.R +++ b/R/calcValidHourlyLaborCosts.R @@ -2,36 +2,69 @@ #' #' @description hourly labor costs in crop+livestock production #' -#' @param datasource So far only "ILO_completed" (based on regression between ILO hourly labor costs and GDP pc MER, -#' calibrated to match USDA/FAO total labor costs) -#' +#' @param datasource Available datasources are: +#' \itemize{ +#' \item ILO_raw : ILO hourly labor costs data +#' \item ILO_completed : ILO hourly labor costs data completed with a regression with GDP pc MER +#' \item USDA_FA0_raw : USDA/FAO hourly labor costs data +#' \item USDA_FA0_completed : USDA/FAO hourly labor costs data completed with a regression with GDP pc MER +#' } #' @return List of magpie objects with results on country level, weight on country level, unit and description. #' @author Debbora Leip #' #' @examples #' \dontrun{ -#' calcOutput("ValidHourlyLaborCosts", datasource="ILO_completed") +#' calcOutput("ValidHourlyLaborCosts", datasource = "ILO_completed") #' } #' calcValidHourlyLaborCosts <- function(datasource = "ILO_completed") { if (datasource == "ILO_completed") { - hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "USDA_FAO", aggregate = FALSE) - hourlyCosts <- setNames(hourlyCosts, "Labor|Wages|Hourly labor costs (USDMER05/h)") + hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "ILO", fillWithRegression = TRUE, + calibYear = NULL, cutAfterCalibYear = FALSE, aggregate = FALSE) + + description <- paste("Hourly labor costs in agriculture (based on ILO data completed with a", + "regression with GDP)") - # total hours worked in 2010 as weight for aggregation to world regions - agEmpl <- calcOutput("AgEmplILO", aggregate = FALSE, subsectors = FALSE) - weeklyHours <- calcOutput("WeeklyHoursILO", aggregate = FALSE) - weight <- hourlyCosts - weight[, , ] <- agEmpl[, 2010, ] * weeklyHours[, 2010, ] + } else if (datasource == "ILO_raw") { + hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "ILO", + fillWithRegression = FALSE, aggregate = FALSE) description <- paste("Hourly labor costs in agriculture (based on ILO data completed with a", - "regression with GDP, calibrated using USDA and FAO data)") + "regression with GDP)") + + } else if (datasource == "USDA_FAO_completed") { + hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "USDA_FAO", fillWithRegression = TRUE, + calibYear = NULL, cutAfterCalibYear = FALSE, aggregate = FALSE) + + description <- paste("Hourly labor costs in agriculture (based on ILO data completed with a", + "regression with GDP)") + + } else if (datasource == "USDA_FAO_raw") { + hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "USDA_FAO", + fillWithRegression = FALSE, aggregate = FALSE) + + description <- paste("Hourly labor costs in agriculture (based on USDA/FAO data completed with a", + "regression with GDP)") } else { stop("Datsource not available") } + hourlyCosts <- setNames(hourlyCosts, "Labor|Wages|Hourly labor costs (USDMER05/h)") + + # total hours worked as weight for aggregation to world regions + agEmpl <- calcOutput("AgEmplILO", aggregate = FALSE, subsectors = FALSE) + weeklyHours <- calcOutput("WeeklyHoursILO", aggregate = FALSE) + weight <- hourlyCosts + years <- intersect(getYears(hourlyCosts, as.integer = TRUE), + intersect(getYears(agEmpl, as.integer = TRUE), getYears(weeklyHours, as.integer = TRUE))) + weight[, years, ] <- agEmpl[, years, ] * weeklyHours[, years, ] + weight[, setdiff(getYears(hourlyCosts, + as.integer = TRUE), years), ] <- agEmpl[, max(years), ] * weeklyHours[, max(years), ] + weight[hourlyCosts == 0] <- 0 + + # add dimensions out <- add_dimension(hourlyCosts, dim = 3.1, add = "scenario", nm = "historical") out <- add_dimension(out, dim = 3.2, add = "model", nm = datasource) diff --git a/R/calcValidWageDevelopment.R b/R/calcValidWageDevelopment.R index 53aa750..f85afc8 100644 --- a/R/calcValidWageDevelopment.R +++ b/R/calcValidWageDevelopment.R @@ -2,8 +2,13 @@ #' #' @description wage index: hourly labor costs in crop+livestock production relative to a baseyear #' -#' @param datasource So far only "ILO_completed" (based on regression between ILO hourly labor costs and GDP pc MER, -#' calibrated to match USDA/FAO total labor costs) +#' @param datasource Available datasources are: +#' \itemize{ +#' \item ILO_raw : based on ILO hourly labor costs data +#' \item ILO_completed : based on ILO hourly labor costs data completed with a regression with GDP pc MER +#' \item USDA_FA0_raw : based on USDA/FAO hourly labor costs data +#' \item USDA_FA0_completed : based on USDA/FAO hourly labor costs data completed with a regression with GDP pc MER +#' } #' @param baseYear year relative to which the wage development should be calculated #' @return List of magpie objects with results on country level, weight on country level, unit and description. #' @author Debbora Leip @@ -16,24 +21,19 @@ calcValidWageDevelopment <- function(datasource = "ILO_completed", baseYear = 2000) { - if (datasource == "ILO_completed") { - hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "USDA_FAO", aggregate = FALSE) + hourlyCosts <- setNames(calcOutput("ValidHourlyLaborCosts", datasource = datasource, aggregate = FALSE), NULL) - if (!baseYear %in% getYears(hourlyCosts, as.integer = TRUE)) stop("Baseyear not available.") + if (!baseYear %in% getYears(hourlyCosts, as.integer = TRUE)) stop("Baseyear not available.") - wageIndex <- collapseDim(hourlyCosts / hourlyCosts[, baseYear, ], dim = 2.2) - wageIndex <- setNames(wageIndex, paste0("Labor|Wages|Hourly labor costs relative to ", baseYear, " (index)")) + wageIndex <- collapseDim(hourlyCosts / hourlyCosts[, baseYear, ], dim = 2.2) + wageIndex <- setNames(wageIndex, paste0("Labor|Wages|Hourly labor costs relative to ", baseYear, " (index)")) - # population in 2000 as weight for aggregation to world regions and globally - weight <- wageIndex - weight[, , ] <- calcOutput("Population", naming = "scenario", - aggregate = FALSE, years = c(baseYear))[, , "SSP2", drop = TRUE] + # population in 2000 as weight for aggregation to world regions and globally + weight <- wageIndex + weight[, , ] <- calcOutput("Population", naming = "scenario", + aggregate = FALSE, years = c(baseYear))[, , "SSP2", drop = TRUE] - description <- paste("Wage index calculated as hourly labor costs in agriculture relative to 2000 (based on ILO", - "data completed with a regression with GDP, calibrated using USDA and FAO data)") - } else { - stop("Datsource not available") - } + description <- paste("Wage index calculated as hourly labor costs in agriculture relative to 2000") out <- add_dimension(wageIndex, dim = 3.1, add = "scenario", nm = "historical") out <- add_dimension(out, dim = 3.2, add = "model", nm = datasource) diff --git a/R/fullVALIDATION.R b/R/fullVALIDATION.R index f7b9014..d5577fb 100644 --- a/R/fullVALIDATION.R +++ b/R/fullVALIDATION.R @@ -13,7 +13,7 @@ #' fullVALIDATION <- function(rev = 0.1) { -if (rev < 4.66) stop("mrvalidation(>= 2.34.0) does not support revision below 4.63 anymore. + if (rev < 4.66) stop("mrvalidation(>= 2.34.0) does not support revision below 4.63 anymore. Please use a older snapshot/version of the library, if you need older revisions.") # all validation data regional aggregations happens here # for the first variable output calculation, append paramenter should be set to FALSE so that the @@ -43,10 +43,16 @@ if (rev < 4.66) stop("mrvalidation(>= 2.34.0) does not support revision below 4. file = valfile, append = TRUE, try = TRUE) calcOutput(type = "ValidHourlyLaborCosts", datasource = "ILO_completed", aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) + calcOutput(type = "ValidHourlyLaborCosts", datasource = "USDA_FAO_completed", aggregate = "REG+GLO", + file = valfile, append = TRUE, try = TRUE) calcOutput(type = "ValidWageDevelopment", datasource = "ILO_completed", baseYear = 2000, aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) calcOutput(type = "ValidWageDevelopment", datasource = "ILO_completed", baseYear = 2010, aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) + calcOutput(type = "ValidWageDevelopment", datasource = "USDA_FAO_completed", baseYear = 2000, + aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) + calcOutput(type = "ValidWageDevelopment", datasource = "USDA_FAO_completed", baseYear = 2010, + aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) calcOutput(type = "ValidGini", aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) calcOutput(type = "ValidPovertyLine", aggregate = "REG+GLO", @@ -80,9 +86,9 @@ if (rev < 4.66) stop("mrvalidation(>= 2.34.0) does not support revision below 4. append = TRUE, try = TRUE) # ready calcOutput(type = "ValidTrade", aggregate = "REG+GLO", file = valfile, append = TRUE, net_trade = FALSE, equalized = FALSE, try = TRUE) # ready - calcOutput(type = "ValidTrade", aggregate = "REG+GLO", - datasource = "FAOBilateral", file = valfile, - append = TRUE, try = TRUE) # ready + calcOutput(type = "ValidTrade", aggregate = "REG+GLO", + datasource = "FAOBilateral", file = valfile, + append = TRUE, try = TRUE) # ready calcOutput(type = "ValidTrade", aggregate = "REG+GLO", datasource = "FAOBilateral", file = valfile, append = TRUE, net_trade = FALSE, equalized = FALSE, try = TRUE) # ready @@ -265,7 +271,7 @@ if (rev < 4.66) stop("mrvalidation(>= 2.34.0) does not support revision below 4. calcOutput(type = "ValidTauPastr", aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) calcOutput(type = "ValidLSUdensity", aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) calcOutput(type = "ValidAgriResearchIntensity", aggregate = "REG+GLO", datasource = "Pardey", - file = valfile, append = TRUE, try = TRUE) + file = valfile, append = TRUE, try = TRUE) # Prices calcOutput(type = "ValidPriceAgriculture", datasource = "WBGEM", aggregate = FALSE, @@ -318,7 +324,7 @@ if (rev < 4.66) stop("mrvalidation(>= 2.34.0) does not support revision below 4. file = valfile, append = TRUE, try = TRUE) calcOutput(type = "ValidTotalLaborCosts", datasource = "GTAP", aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) -calcOutput(type = "ValidCostsTransport", datasource = "GTAPwholesale", aggregate = "REG+GLO", + calcOutput(type = "ValidCostsTransport", datasource = "GTAPwholesale", aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) # Diversity indices diff --git a/README.md b/README.md index cad93ea..2910969 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # madrat data preparation for validation purposes -R package **mrvalidation**, version **2.51.4** +R package **mrvalidation**, version **2.51.5** [![CRAN status](https://www.r-pkg.org/badges/version/mrvalidation)](https://cran.r-project.org/package=mrvalidation) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4317826.svg)](https://doi.org/10.5281/zenodo.4317826) [![R build status](https://github.com/pik-piam/mrvalidation/workflows/check/badge.svg)](https://github.com/pik-piam/mrvalidation/actions) [![codecov](https://codecov.io/gh/pik-piam/mrvalidation/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrvalidation) [![r-universe](https://pik-piam.r-universe.dev/badges/mrvalidation)](https://pik-piam.r-universe.dev/builds) @@ -39,7 +39,7 @@ In case of questions / problems please contact Benjamin Leon Bodirsky . +Bodirsky B, Wirth S, Karstens K, Humpenoeder F, Stevanovic M, Mishra A, Biewald A, Weindl I, Beier F, Chen D, Crawford M, Leip D, Molina Bacca E, Kreidenweis U, W. Yalew A, Humpenoeder F, von Jeetze P, Wang X, Dietrich J, Alves M (2023). _mrvalidation: madrat data preparation for validation purposes_. doi: 10.5281/zenodo.4317826 (URL: https://doi.org/10.5281/zenodo.4317826), R package version 2.51.5, . A BibTeX entry for LaTeX users is @@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is title = {mrvalidation: madrat data preparation for validation purposes}, author = {Benjamin Leon Bodirsky and Stephen Wirth and Kristine Karstens and Florian Humpenoeder and Mishko Stevanovic and Abhijeet Mishra and Anne Biewald and Isabelle Weindl and Felicitas Beier and David Chen and Michael Crawford and Debbora Leip and Edna {Molina Bacca} and Ulrich Kreidenweis and Amsalu {W. Yalew} and Florian {Humpenoeder } and Patrick {von Jeetze } and Xiaoxi Wang and Jan Philipp Dietrich and Marcos Alves}, year = {2023}, - note = {R package version 2.51.4}, + note = {R package version 2.51.5}, doi = {10.5281/zenodo.4317826}, url = {https://github.com/pik-piam/mrvalidation}, } diff --git a/man/calcValidHourlyLaborCosts.Rd b/man/calcValidHourlyLaborCosts.Rd index 2bbdba0..3dd7342 100644 --- a/man/calcValidHourlyLaborCosts.Rd +++ b/man/calcValidHourlyLaborCosts.Rd @@ -7,8 +7,13 @@ calcValidHourlyLaborCosts(datasource = "ILO_completed") } \arguments{ -\item{datasource}{So far only "ILO_completed" (based on regression between ILO hourly labor costs and GDP pc MER, -calibrated to match USDA/FAO total labor costs)} +\item{datasource}{Available datasources are: +\itemize{ +\item ILO_raw : ILO hourly labor costs data +\item ILO_completed : ILO hourly labor costs data completed with a regression with GDP pc MER +\item USDA_FA0_raw : USDA/FAO hourly labor costs data +\item USDA_FA0_completed : USDA/FAO hourly labor costs data completed with a regression with GDP pc MER +}} } \value{ List of magpie objects with results on country level, weight on country level, unit and description. @@ -18,7 +23,7 @@ hourly labor costs in crop+livestock production } \examples{ \dontrun{ -calcOutput("ValidHourlyLaborCosts", datasource="ILO_completed") +calcOutput("ValidHourlyLaborCosts", datasource = "ILO_completed") } } diff --git a/man/calcValidWageDevelopment.Rd b/man/calcValidWageDevelopment.Rd index d7c059d..d80e935 100644 --- a/man/calcValidWageDevelopment.Rd +++ b/man/calcValidWageDevelopment.Rd @@ -7,8 +7,13 @@ calcValidWageDevelopment(datasource = "ILO_completed", baseYear = 2000) } \arguments{ -\item{datasource}{So far only "ILO_completed" (based on regression between ILO hourly labor costs and GDP pc MER, -calibrated to match USDA/FAO total labor costs)} +\item{datasource}{Available datasources are: +\itemize{ +\item ILO_raw : based on ILO hourly labor costs data +\item ILO_completed : based on ILO hourly labor costs data completed with a regression with GDP pc MER +\item USDA_FA0_raw : based on USDA/FAO hourly labor costs data +\item USDA_FA0_completed : based on USDA/FAO hourly labor costs data completed with a regression with GDP pc MER +}} \item{baseYear}{year relative to which the wage development should be calculated} }