Skip to content

Commit

Permalink
added labor-capital-share validation and renamed feed conversion indi…
Browse files Browse the repository at this point in the history
…cator
  • Loading branch information
Debbora Leip committed Feb 26, 2024
1 parent 7a67f9e commit 83ddde0
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '50673798'
ValidationKey: '50693577'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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.56.2
version: 2.56.3
date-released: '2024-02-26'
abstract: Package contains routines to prepare data for validation exercises.
authors:
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: mrvalidation
Title: madrat data preparation for validation purposes
Version: 2.56.2
Version: 2.56.3
Date: 2024-02-26
Authors@R: c(
person("Benjamin Leon", "Bodirsky", , "[email protected]", role = c("aut", "cre")),
Expand Down
42 changes: 42 additions & 0 deletions R/calcValidFactorReqShares.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#' @title calcValidFactorReqShares
#'
#' @description calculates the validation data for labor and capital requirement shares in agriculture
#' (currently the same shares for crop and livestock production based on USDA data)
#' @param subtype for which to report requirement shares, either "crop" or "livestock"
#'
#' @return List of magpie objects with results on country level, weight on country level, unit and description.
#' @author Debbora Leip
#' @examples
#'
#' \dontrun{
#' calcOutput("ValidFactorReqShares")
#' }
#'

calcValidFactorReqShares <- function(subtype = "crop") {

if (!(subtype %in% c("crop", "livestock"))) stop("subtype must be either 'crop' or 'livestock'")

out <- setNames(calcOutput("AgCapLabourShare", aggregate = FALSE),
paste0("Factor requirement shares|", stringr::str_to_title(subtype),
" products|+|Capital requirement share (%)"))
out <- mbind(out, setNames(1 - out, paste0("Factor requirement shares|", stringr::str_to_title(subtype),
" products|+|Labor requirement share (%)")))

out <- add_dimension(out, dim = 3.1, add = "scenario", nm = "historical")
out <- add_dimension(out, dim = 3.2, add = "model", nm = "USDA")


# production as weight (0 weight to countries with unexpectedly high capital shares)
weight <- dimSums(collapseDim(calcOutput("Production", aggregate = FALSE)[, , "dm"]), dim = 3.1)
weight[c("BLZ", "CRI", "DOM", "HND", "JAM", "MEX", "NIC", "PAN", "SLV"), , ] <- 0
weight <- weight[, getItems(out, dim = 2), ]
weight[out[, , "Capital", pmatch = TRUE] == 0] <- 0


return(list(x = out,
weight = weight,
unit = "%",
description = "Factor requirement shares based on USDA data")
)
}
22 changes: 11 additions & 11 deletions R/calcValidFeedConversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#' @description calculates various feed indicators
#'
#' @param livestockSystem if TRUE, ruminant meat and milk are aggregated, and poultry meat and egg are aggregated
#' @param subtractBalanceflow if TRUE, balanceflow is subtracted so that the feed efficiency reflects
#' @param subtractBalanceflow if TRUE, balanceflow is subtracted so that the feed conversion reflects
#' our feedbasket calucaltions. If FALSE, it reflects the FAO values and the pasture demand
#'
#'
Expand All @@ -19,7 +19,7 @@
#' @importFrom magpiesets reporthelper findset
#' @importFrom magclass dimOrder
calcValidFeedConversion <- function(livestockSystem = TRUE, subtractBalanceflow = FALSE) {
### calculate product specific feed conversion efficiency as quotient between
### calculate product specific feed conversion as quotient between
### feed and animal products

mb <- calcOutput("FAOmassbalance", aggregate = FALSE)
Expand Down Expand Up @@ -107,32 +107,32 @@ calcValidFeedConversion <- function(livestockSystem = TRUE, subtractBalanceflow
getNames(quotientProductspecfic, dim = 1) <- reportingnames(getNames(quotientProductspecfic, dim = 1))
}

# Calculate feed conversion efficiency total
# Calculate feed conversion total
quotientTmp <- collapseNames(dimSums(quotientProductspecfic, dim = c("ItemCodeItem"))[, , "ge"])
indicatorTmp <- collapseNames(dimSums(feedProductspecific,
dim = c("ItemCodeItem", "ElementShort"))[, , "ge"]) / quotientTmp
nameIndicator <- "Productivity|Feed conversion efficiency"
nameIndicator <- "Productivity|Feed conversion"
indicatorTmp <- setNames(collapseNames(indicatorTmp), paste0(nameIndicator, " (", "GE per GE", ")"))
quotientTmp <- setNames(collapseNames(quotientTmp), paste0(nameIndicator, " (", "GE per GE", ")"))
x <- mbind(x, indicatorTmp)
weight <- mbind(weight, quotientTmp)

# calculate feed conversion efficiency Livestock specific
# calculate feed conversion Livestock specific
quotientTmp <- quotientProductspecfic[, , c("ge", "nr")]
indicatorTmp <- dimSums(feedProductspecific, dim = c("ItemCodeItem"))[, , c("ge", "nr")] / quotientTmp
prefix <- "Productivity|Feed conversion efficiency|"
prefix <- "Productivity|Feed conversion|"
nameIndicator <- paste0(prefix, getNames(indicatorTmp, dim = 1), " (", "GE per GE", ")")
x <- mbind(x, setNames(collapseNames(indicatorTmp[, , "ge"]), nameIndicator))
weight <- mbind(weight, setNames(collapseNames(quotientTmp[, , "ge"]), nameIndicator))
prefix <- "Productivity|Feed protein conversion efficiency|"
prefix <- "Productivity|Feed protein conversion|"
nameIndicator <- paste0(prefix, getNames(indicatorTmp, dim = 1), " (", "Nr per Nr", ")")
x <- mbind(x, setNames(collapseNames(indicatorTmp[, , "nr"]), nameIndicator))
weight <- mbind(weight, setNames(collapseNames(quotientTmp[, , "nr"]), nameIndicator))

# calculate feed conversion efficiency Livestock and product specific
# calculate feed conversion Livestock and product specific
quotientTmp <- collapseNames(quotientProductspecfic[, , "ge"])
indicatorTmp <- collapseNames(feedProductspecific[, , "ge"]) / quotientTmp
prefix <- "Productivity|Feed conversion efficiency|"
prefix <- "Productivity|Feed conversion|"
for (item in getNames(feedProductspecific, dim = 2)) {
nameIndicator <- paste0(prefix, item, "|+|",
getNames(indicatorTmp, dim = 1), " (", "GE per GE", ")")
Expand All @@ -142,10 +142,10 @@ calcValidFeedConversion <- function(livestockSystem = TRUE, subtractBalanceflow
weight <- mbind(weight, setNames(weightTmp, nameIndicator))
}

# calculate feed conversion efficiency Product specific
# calculate feed conversion Product specific
quotientTmp <- collapseNames(dimSums(quotientProductspecfic, dim = c("ItemCodeItem"))[, , "ge"])
indicatorTmp <- collapseNames(dimSums(feedProductspecific, dim = c("ElementShort"))[, , "ge"]) / quotientTmp
prefix <- "Productivity|Feed conversion efficiency|+|"
prefix <- "Productivity|Feed conversion|+|"
nameIndicator <- paste0(prefix, getNames(indicatorTmp, dim = 1), " (", "GE per GE", ")")
x <- mbind(x, setNames(collapseNames(indicatorTmp), nameIndicator))
weightTmp <- collapseNames(indicatorTmp) * NA
Expand Down
5 changes: 5 additions & 0 deletions R/fullVALIDATION.R
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ fullVALIDATION <- function(rev = 0.1) {
calcOutput(type = "ValidCostsTransport", datasource = "GTAPwholesale", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)

calcOutput(type = "ValidFactorReqShares", subtype = "crop", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidFactorReqShares", subtype = "livestock", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)

# Diversity indices
calcOutput(type = "ValidBII", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# madrat data preparation for validation purposes

R package **mrvalidation**, version **2.56.2**
R package **mrvalidation**, version **2.56.3**

[![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)

Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Benjamin Leon Bodirsky <bodirsky@

To cite package **mrvalidation** in publications use:

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 <https://doi.org/10.5281/zenodo.4317826>, R package version 2.56.2, <https://github.com/pik-piam/mrvalidation>.
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.56.3, <URL: https://github.com/pik-piam/mrvalidation>.

A BibTeX entry for LaTeX users is

Expand All @@ -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.56.2},
note = {R package version 2.56.3},
doi = {10.5281/zenodo.4317826},
url = {https://github.com/pik-piam/mrvalidation},
}
Expand Down
28 changes: 28 additions & 0 deletions man/calcValidFactorReqShares.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/calcValidFeedConversion.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 83ddde0

Please sign in to comment.