pik-piam / magpie4

R package | MAgPIE outputs R package for MAgPIE version 4.x
GNU Lesser General Public License v3.0
1 stars 23 forks source link

Inconsistent output of FoodExpanditure() and consumptionValue(..., type="food") functions #2

Closed mishkos closed 4 years ago

mishkos commented 4 years ago

Ideally this should be the same. For the difference between the output of FoodExpenditure() and consumptionValue(..., type="food"), it basically comes from usage of different approaches for calculation of prices and quantities, the former using prices per kcal and caloric intake and the latter using prices per tones DM and tDM consumption. Since prices in both case are calculated as Lagrangian multipliers, it could be that the difference in output of functions comes from a general equation system setup in magpie and related interplay between demand variables.

tscheypidi commented 4 years ago

has this been fixed yet?

bodirsky commented 4 years ago

I do not understand the issue, and miskos answer..

bodirsky commented 4 years ago

ok, this is the issue:

a=FoodExpenditure("../../inputdata/fulldata.gdx")[,2050,] sum(a) [1] 7855.305 b=consumptionValue("../../inputdata/fulldata.gdx", type="food")[,"y2050",] sum(b) [1] 5660919

bodirsky commented 4 years ago

the food expenditure function calculates expenditure based on calories and calorie-prices: price = readGDX(gdx,"p15_prices_kcal") which in the gams code is the equation

p15_prices_kcal(t,iso,kfo)=sum(i_to_iso(i,iso), q15_food_demand.m(i,kfo)); q15_food_demand(i2,kfo) .. (vm_dem_food(i2,kfo) + sum(ct, f15_household_balanceflow(ct,i2,kfo,"dm")))

the consumption value function receives its prices from the equation: d <- readGDX(gdx,"ov_supply",select = list(type="level"),react = "warning") and the quantities from the variable readGDX(gdx, "ov_dem_food", select=list(type="level"))

bodirsky commented 4 years ago

So i see one bug in the food expenditure function, because it omits the multiplication by 365. This still does not close the gap (still ~50%)

bodirsky commented 4 years ago

ah, no. the multiplication by 365 is done.

bodirsky commented 4 years ago

ah, the food expenditure is by default as per-capita. if you switch it to per-capita = FALSE, it provides similar values as the consumption value

a = FoodExpenditure(gdx,per_capita=FALSE)[,2050,]

sum(a) [1] 5787212

b=consumptionValue("../../inputdata/fulldata.gdx", type="food")[,"y2050",] sum(b) [1] 5660919

so everything is fine, no bugs :)