diff --git a/.buildlibrary b/.buildlibrary index ba50d27..90b4ebb 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '50561428' +ValidationKey: '50586312' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index ba09162..8d7b20a 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.55.8 -date-released: '2024-02-13' +version: 2.55.9 +date-released: '2024-02-15' abstract: Package contains routines to prepare data for validation exercises. authors: - family-names: Bodirsky diff --git a/DESCRIPTION b/DESCRIPTION index e6b7714..e48ba6c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: mrvalidation Title: madrat data preparation for validation purposes -Version: 2.55.8 -Date: 2024-02-13 +Version: 2.55.9 +Date: 2024-02-15 Authors@R: c( person("Benjamin Leon", "Bodirsky", , "bodirsky@pik-potsdam.de", role = c("aut", "cre")), person("Stephen", "Wirth", role = "aut"), diff --git a/R/calcValidAgEmployment.R b/R/calcValidAgEmployment.R index 4971886..120ccde 100644 --- a/R/calcValidAgEmployment.R +++ b/R/calcValidAgEmployment.R @@ -5,6 +5,7 @@ #' @param datasource ILO for reporting aggregated employment in crop+livestock production, or ILO_FAO, which uses the #' same aggregated employment data from ILO, but applies FAO value of production shares to disaggregated between #' employment in crop and in livestock production. +#' @param dataVersionILO "" for the oldest version, or "monthYear" (e.g. "Aug23") for a newer version #' #' @return List of magpie objects with results on country level, weight on country level, unit and description. #' @author Debbora Leip @@ -15,14 +16,14 @@ #' } #' -calcValidAgEmployment <- function(datasource = "ILO") { +calcValidAgEmployment <- function(datasource = "ILO", dataVersionILO = "Aug23") { if (datasource == "ILO") { - agEmpl <- calcOutput("AgEmplILO", aggregate = FALSE)[, , c("Livestock", "Crops")] + agEmpl <- calcOutput("AgEmplILO", dataVersionILO = dataVersionILO, aggregate = FALSE)[, , c("Livestock", "Crops")] out <- setNames(dimSums(agEmpl, dim = 3), "Labor|Employment|Agricultural employment (mio people)") description <- "Employment in agriculture (livestock+crop production) from ILO modelled estimates" } else if (datasource == "ILO_FAO") { - agEmpl <- calcOutput("AgEmplILO", aggregate = FALSE)[, , c("Livestock", "Crops")] + agEmpl <- calcOutput("AgEmplILO", dataVersionILO = dataVersionILO, aggregate = FALSE)[, , c("Livestock", "Crops")] out <- setNames(agEmpl, c("Labor|Employment|Agricultural employment|+|Livestock products (mio people)", "Labor|Employment|Agricultural employment|+|Crop products (mio people)")) description <- paste0("Employment in agriculture (livestock+crop production) from ILO modelled estimates, ", @@ -31,6 +32,10 @@ calcValidAgEmployment <- function(datasource = "ILO") { stop("Datsource not available") } + + if (dataVersionILO == "") dataVersionILO <- "Aug21" + datasource <- paste(datasource, dataVersionILO, sep = "_") + out <- add_dimension(out, dim = 3.1, add = "scenario", nm = "historical") out <- add_dimension(out, dim = 3.2, add = "model", nm = datasource) diff --git a/R/calcValidHourlyLaborCosts.R b/R/calcValidHourlyLaborCosts.R index 677ecf6..6dc3099 100644 --- a/R/calcValidHourlyLaborCosts.R +++ b/R/calcValidHourlyLaborCosts.R @@ -9,6 +9,7 @@ #' \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 #' } +#' @param dataVersionILO "" for the oldest version, or "monthYear" (e.g. "Aug23") for a newer version #' @return List of magpie objects with results on country level, weight on country level, unit and description. #' @author Debbora Leip #' @@ -18,31 +19,33 @@ #' } #' -calcValidHourlyLaborCosts <- function(datasource = "ILO_completed") { +calcValidHourlyLaborCosts <- function(datasource = "ILO_completed", dataVersionILO = "Aug23") { if (datasource == "ILO_completed") { - hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "ILO", fillWithRegression = TRUE, - calibYear = NULL, cutAfterCalibYear = FALSE, aggregate = FALSE) + hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "ILO", dataVersionILO = dataVersionILO, + 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 == "ILO_raw") { - hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "ILO", + hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "ILO", dataVersionILO = dataVersionILO, fillWithRegression = 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_completed") { - hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "USDA_FAO", fillWithRegression = TRUE, - calibYear = NULL, cutAfterCalibYear = FALSE, aggregate = FALSE) + hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "USDA_FAO", dataVersionILO = dataVersionILO, + 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", + hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "USDA_FAO", dataVersionILO = dataVersionILO, fillWithRegression = FALSE, aggregate = FALSE) description <- paste("Hourly labor costs in agriculture (based on USDA/FAO data completed with a", @@ -54,8 +57,8 @@ calcValidHourlyLaborCosts <- function(datasource = "ILO_completed") { 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) + agEmpl <- calcOutput("AgEmplILO", dataVersionILO = dataVersionILO, aggregate = FALSE, subsectors = FALSE) + weeklyHours <- calcOutput("WeeklyHoursILO", dataVersionILO = dataVersionILO, aggregate = FALSE) weight <- hourlyCosts years <- intersect(getYears(hourlyCosts, as.integer = TRUE), intersect(getYears(agEmpl, as.integer = TRUE), getYears(weeklyHours, as.integer = TRUE))) @@ -64,7 +67,9 @@ calcValidHourlyLaborCosts <- function(datasource = "ILO_completed") { as.integer = TRUE), years), ] <- agEmpl[, max(years), ] * weeklyHours[, max(years), ] weight[hourlyCosts == 0] <- 0 - # add dimensions + # USDA_FAO still depends on ILO employment + if (dataVersionILO == "") dataVersionILO <- "Aug21" + datasource <- paste(datasource, dataVersionILO, sep = "_") 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/calcValidTotalLaborCosts.R b/R/calcValidTotalLaborCosts.R index bc26f87..9c96a9c 100644 --- a/R/calcValidTotalLaborCosts.R +++ b/R/calcValidTotalLaborCosts.R @@ -4,6 +4,7 @@ #' #' @param datasource "USDA" (which uses FAO VoP and USDA cost shares) or "ILO" (which is based on ILO datasets and #' calibrated to the USDA/FAO approach, but includes costs for some countries without VoP data) or "GTAP" +#' @param dataVersionILO "" for the oldest version, or "monthYear" (e.g. "Aug23") for a newer version #' #' @return List of magpie objects with results on country level, weight on country level, unit and description. #' @author Debbora Leip @@ -14,16 +15,17 @@ #' } #' -calcValidTotalLaborCosts <- function(datasource = "USDA") { +calcValidTotalLaborCosts <- function(datasource = "USDA", dataVersionILO = "Aug23") { - out <- calcOutput("LaborCosts", datasource = datasource, subsectors = TRUE, otherLivst = FALSE, - aggregate = FALSE)[, , c("Crops", "Livestock")] + out <- calcOutput("LaborCosts", datasource = datasource, dataVersionILO = dataVersionILO, + subsectors = TRUE, otherLivst = FALSE, aggregate = FALSE)[, , c("Crops", "Livestock")] out <- setNames(out, c("Costs Optimization|Input Factors|Labor costs|+|Crop products (million US$05/yr)", "Costs Optimization|Input Factors|Labor costs|+|Livestock products (million US$05/yr)")) if (datasource == "USDA") datasource <- "USDA/FAO" - if (datasource == "ILO") datasource <- "ILO based" + if (dataVersionILO == "") dataVersionILO <- "Aug21" + if (datasource == "ILO") datasource <- paste0("ILO_", dataVersionILO, " based") out <- add_dimension(out, 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 f85afc8..4e611bd 100644 --- a/R/calcValidWageDevelopment.R +++ b/R/calcValidWageDevelopment.R @@ -10,6 +10,7 @@ #' \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 +#' @param dataVersionILO "" for the oldest version, or "monthYear" (e.g. "Aug23") for a newer version #' @return List of magpie objects with results on country level, weight on country level, unit and description. #' @author Debbora Leip #' @@ -19,9 +20,10 @@ #' } #' -calcValidWageDevelopment <- function(datasource = "ILO_completed", baseYear = 2000) { +calcValidWageDevelopment <- function(datasource = "ILO_completed", baseYear = 2000, dataVersionILO = "Aug23") { - hourlyCosts <- setNames(calcOutput("ValidHourlyLaborCosts", datasource = datasource, aggregate = FALSE), NULL) + hourlyCosts <- setNames(calcOutput("ValidHourlyLaborCosts", datasource = datasource, + dataVersionILO = dataVersionILO, aggregate = FALSE), NULL) if (!baseYear %in% getYears(hourlyCosts, as.integer = TRUE)) stop("Baseyear not available.") @@ -35,6 +37,9 @@ calcValidWageDevelopment <- function(datasource = "ILO_completed", baseYear = 20 description <- paste("Wage index calculated as hourly labor costs in agriculture relative to 2000") + # USDA_FAO still depends on ILO employment + if (dataVersionILO == "") dataVersionILO <- "Aug21" + datasource <- paste(datasource, dataVersionILO, sep = "_") 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 ab58bf9..f868e82 100644 --- a/R/fullVALIDATION.R +++ b/R/fullVALIDATION.R @@ -37,22 +37,24 @@ fullVALIDATION <- function(rev = 0.1) { file = valfile, append = TRUE, try = TRUE) calcOutput(type = "ValidConsumptionValue", datasource = "FAO", aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) - calcOutput(type = "ValidAgEmployment", datasource = "ILO", aggregate = "REG+GLO", - file = valfile, append = TRUE, try = TRUE) - calcOutput(type = "ValidAgEmployment", datasource = "ILO_FAO", aggregate = "REG+GLO", - 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) + for (dvILO in c("", "Aug23")) { + calcOutput(type = "ValidAgEmployment", datasource = "ILO", dataVersionILO = dvILO, aggregate = "REG+GLO", + file = valfile, append = TRUE, try = TRUE) + calcOutput(type = "ValidAgEmployment", datasource = "ILO_FAO", dataVersionILO = dvILO, aggregate = "REG+GLO", + file = valfile, append = TRUE, try = TRUE) + calcOutput(type = "ValidHourlyLaborCosts", datasource = "ILO_completed", dataVersionILO = dvILO, + aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) + calcOutput(type = "ValidHourlyLaborCosts", datasource = "USDA_FAO_completed", dataVersionILO = dvILO, + aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) + calcOutput(type = "ValidWageDevelopment", datasource = "ILO_completed", dataVersionILO = dvILO, baseYear = 2000, + aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) + calcOutput(type = "ValidWageDevelopment", datasource = "ILO_completed", dataVersionILO = dvILO, baseYear = 2010, + aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) + calcOutput(type = "ValidWageDevelopment", datasource = "USDA_FAO_completed", dataVersionILO = dvILO, + baseYear = 2000, aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) + calcOutput(type = "ValidWageDevelopment", datasource = "USDA_FAO_completed", dataVersionILO = dvILO, + 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", @@ -329,7 +331,9 @@ fullVALIDATION <- function(rev = 0.1) { file = valfile, append = TRUE, try = TRUE) calcOutput(type = "ValidCostsAEI", datasource = "IMPACT", aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) - calcOutput(type = "ValidTotalLaborCosts", datasource = "ILO", aggregate = "REG+GLO", + calcOutput(type = "ValidTotalLaborCosts", datasource = "ILO", dataVersionILO = "Aug23", aggregate = "REG+GLO", + file = valfile, append = TRUE, try = TRUE) + calcOutput(type = "ValidTotalLaborCosts", datasource = "ILO", dataVersionILO = "", aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) calcOutput(type = "ValidTotalLaborCosts", datasource = "USDA", aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) diff --git a/README.md b/README.md index e5efd64..7b99ba2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # madrat data preparation for validation purposes -R package **mrvalidation**, version **2.55.8** +R package **mrvalidation**, version **2.55.9** [![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 , R package version 2.55.8, . +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, von Jeetze P, Wang X, Dietrich J, Alves M (2024). _mrvalidation: madrat data preparation for validation purposes_. doi: 10.5281/zenodo.4317826 (URL: https://doi.org/10.5281/zenodo.4317826), R package version 2.55.9, . 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 Patrick {von Jeetze} and Xiaoxi Wang and Jan Philipp Dietrich and Marcos Alves}, year = {2024}, - note = {R package version 2.55.8}, + note = {R package version 2.55.9}, doi = {10.5281/zenodo.4317826}, url = {https://github.com/pik-piam/mrvalidation}, } diff --git a/man/calcValidAgEmployment.Rd b/man/calcValidAgEmployment.Rd index 8118491..ee463f5 100644 --- a/man/calcValidAgEmployment.Rd +++ b/man/calcValidAgEmployment.Rd @@ -4,12 +4,14 @@ \alias{calcValidAgEmployment} \title{calcValidAgEmployment} \usage{ -calcValidAgEmployment(datasource = "ILO") +calcValidAgEmployment(datasource = "ILO", dataVersionILO = "Aug23") } \arguments{ \item{datasource}{ILO for reporting aggregated employment in crop+livestock production, or ILO_FAO, which uses the same aggregated employment data from ILO, but applies FAO value of production shares to disaggregated between employment in crop and in livestock production.} + +\item{dataVersionILO}{"" for the oldest version, or "monthYear" (e.g. "Aug23") for a newer version} } \value{ List of magpie objects with results on country level, weight on country level, unit and description. diff --git a/man/calcValidHourlyLaborCosts.Rd b/man/calcValidHourlyLaborCosts.Rd index 3dd7342..570bb3b 100644 --- a/man/calcValidHourlyLaborCosts.Rd +++ b/man/calcValidHourlyLaborCosts.Rd @@ -4,7 +4,10 @@ \alias{calcValidHourlyLaborCosts} \title{calcValidHourlyLaborCosts} \usage{ -calcValidHourlyLaborCosts(datasource = "ILO_completed") +calcValidHourlyLaborCosts( + datasource = "ILO_completed", + dataVersionILO = "Aug23" +) } \arguments{ \item{datasource}{Available datasources are: @@ -14,6 +17,8 @@ calcValidHourlyLaborCosts(datasource = "ILO_completed") \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 }} + +\item{dataVersionILO}{"" for the oldest version, or "monthYear" (e.g. "Aug23") for a newer version} } \value{ List of magpie objects with results on country level, weight on country level, unit and description. diff --git a/man/calcValidTotalLaborCosts.Rd b/man/calcValidTotalLaborCosts.Rd index 2601aa7..8355ee6 100644 --- a/man/calcValidTotalLaborCosts.Rd +++ b/man/calcValidTotalLaborCosts.Rd @@ -4,11 +4,13 @@ \alias{calcValidTotalLaborCosts} \title{calcValidTotalLaborCosts} \usage{ -calcValidTotalLaborCosts(datasource = "USDA") +calcValidTotalLaborCosts(datasource = "USDA", dataVersionILO = "Aug23") } \arguments{ \item{datasource}{"USDA" (which uses FAO VoP and USDA cost shares) or "ILO" (which is based on ILO datasets and calibrated to the USDA/FAO approach, but includes costs for some countries without VoP data) or "GTAP"} + +\item{dataVersionILO}{"" for the oldest version, or "monthYear" (e.g. "Aug23") for a newer version} } \value{ List of magpie objects with results on country level, weight on country level, unit and description. diff --git a/man/calcValidWageDevelopment.Rd b/man/calcValidWageDevelopment.Rd index d80e935..152df80 100644 --- a/man/calcValidWageDevelopment.Rd +++ b/man/calcValidWageDevelopment.Rd @@ -4,7 +4,11 @@ \alias{calcValidWageDevelopment} \title{calcValidWageDevelopment} \usage{ -calcValidWageDevelopment(datasource = "ILO_completed", baseYear = 2000) +calcValidWageDevelopment( + datasource = "ILO_completed", + baseYear = 2000, + dataVersionILO = "Aug23" +) } \arguments{ \item{datasource}{Available datasources are: @@ -16,6 +20,8 @@ calcValidWageDevelopment(datasource = "ILO_completed", baseYear = 2000) }} \item{baseYear}{year relative to which the wage development should be calculated} + +\item{dataVersionILO}{"" for the oldest version, or "monthYear" (e.g. "Aug23") for a newer version} } \value{ List of magpie objects with results on country level, weight on country level, unit and description.