kayaLaspeyres: kayaLaspeyres

View source: R/kayaLaspeyres.R

kayaLaspeyresR Documentation

kayaLaspeyres

Description

Calculates the Laspeyres decomposition of a changes in a target variable t into drivers based on a kaya-like identity. The kaya-like identity needs to be of the form t = d1 * d2/d1 * d3/d2 * ... * dn/dn-1 * t/dn, where d1, d2/d1, ..., dn/dn-1, t/dn are the drivers of change in the target variable t. The Laspeyres decomposition calculates an additive decomposition of the change over time in the target variable based on the changes in the drivers (for formula of the laspeyres decomposition see comment in .laspeyresDriver). The function returns the change in the target variable and the decomposition of the change into the drivers.

Usage

kayaLaspeyres(data, driverNames = NULL, type = "relative", fixTimeSteps = TRUE)

Arguments

data

MAgPIE object with target variable and variables to calculate drivers. Needs to have the target variable as first column in the data dimension, and the variables to calculate the drivers in the following columns. I.e. getItems(data, dim = 3) should return c(t, d1, d2, ..., dn). If decomposition is to be calculated for multiple scenarios, the data object can have a scenario dimension in 3.2.

driverNames

Names of the drivers in the data object. If NULL, names of the drivers are set based on the names of the variables d1, d2, ..., dn in the data object (i.e. "d2/d1", "d3/d2", ..., "t/dn"). Name of the target variable is always kept as provided in the data object. Default is NULL.

type

Type of the output. "relative" returns the relative change in the target variable from each time step to the next and its decomposition by drivers, "absolute" returns the absolute change over time and its decomposition. Default is "absolute".

fixTimeSteps

Logical. For a consistent decomposition, the time steps in the data object need to be of equal length. If fixTimeSteps is TRUE, the function will check if the time steps are of equal length and if not, will interpolate the data linearily to have equal time steps. If fixTimeSteps is FALSE, the function will only throw a warning if the time steps are not of equal length. Default is TRUE.

Value

The function returns the change in the target variable and the decomposition of the change into the drivers either in percentage points or absolute values (unit of target variable).

Author(s)

Debbora Leip

See Also

kayaFractions

Examples

## Not run: 
data <- new.magpie(cells_and_regions = c("EUR", "SSA", "USA", "LAM", "IND", "OAS"),
                   years = c(2000, 2005, 2010),
                   names = as.vector(outer(c("Area", "Population", "Supply"),
                                           c("SSP1", "SSP2"), paste, sep = ".")),
                   sets = c("Region", "Year", "Variable", "Scenario"), fill = runif(108))
kayaLaspeyres(data)

## End(Not run)


pik-piam/magpie4 documentation built on Feb. 28, 2025, 3:29 p.m.