| Title: | Utility Functions and Composite Goods in Economics |
|---|---|
| Description: | Provides utility functions and composite goods for building economic models. |
| Authors: | Mizuki Uchida [aut, cre] |
| Maintainer: | Mizuki Uchida <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-07-14 04:41:43 UTC |
| Source: | https://github.com/UchidaMizuki/econagent |
Create goods
goods_by(.data, ...)goods_by(.data, ...)
.data |
A data frame that contains columns |
... |
Variables to group by. |
A econ_goods object.
Compose goods
goods_compose(data, utility, node = NULL)goods_compose(data, utility, node = NULL)
data |
A |
utility |
A |
node |
A node name for composition goods. By default, it is |
A econ_goods object.
Consume goods
goods_consume(data, incomes = NULL)goods_consume(data, incomes = NULL)
data |
A |
incomes |
A data frame of a list of data frames that contains columns
|
A econ_goods object.
Consume goods recursively
goods_consume_recursively(data, f, ...)goods_consume_recursively(data, f, ...)
data |
A |
f |
A function that returns a data frame with columns |
... |
Additional arguments passed to |
A econ_goods object.
Produce goods
goods_produce(data, quantities = NULL)goods_produce(data, quantities = NULL)
data |
A |
quantities |
A data frame of a list of data frames that contains columns
|
A econ_goods object.
Produce goods recursively
goods_produce_recursively(data, f, ...)goods_produce_recursively(data, f, ...)
data |
A |
f |
A function that returns a data frame with columns |
... |
Additional arguments passed to |
A econ_goods object.
Reprice goods
goods_reprice(data, prices = NULL)goods_reprice(data, prices = NULL)
data |
A |
prices |
A data frame or a list of data frames that contains columns
|
A econ_goods object.
Reprice goods recursively
goods_reprice_recursively(data, f, ...)goods_reprice_recursively(data, f, ...)
data |
A |
f |
A function that returns a data frame with columns |
... |
Additional arguments passed to |
A econ_goods object.
Iceberg trade cost
goods_trade_iceberg(data, trade)goods_trade_iceberg(data, trade)
data |
A |
trade |
A data frame with |
A econ_goods object.
Update trade cost
goods_trade_update(data, trade)goods_trade_update(data, trade)
data |
A |
trade |
A data frame with |
A econ_goods object.
Update goods data
goods_update(data, value)goods_update(data, value)
data |
A |
value |
A data frame with new values. |
A econ_goods object.
Create a new utility function
new_util(f, ..., class = character())new_util(f, ..., class = character())
f |
A function that returns the utility. |
... |
Parameters to be passed to |
class |
Name of subclass. |
A econ_util object.
Create a new homothetic utility function
new_util_homothetic(f, ..., class = character())new_util_homothetic(f, ..., class = character())
f |
A function that returns the utility. |
... |
Parameters to be passed to |
class |
Name of subclass. |
A util_homothetic object.
util_2goods_budget(prices, income)util_2goods_budget(prices, income)
prices |
A numeric vector of length 2 with the prices of the goods. |
income |
A scalar numeric of income. |
A function that takes a scalar numeric of quantity of good X and returns a scalar numeric of quantity of good Y.
util_2goods_indifference( f, utility, otherwise = NA_real_, interval = c(1e-06, 1e+06), tol = 1e-06, ... )util_2goods_indifference( f, utility, otherwise = NA_real_, interval = c(1e-06, 1e+06), tol = 1e-06, ... )
f |
A |
utility |
A scalar numeric of utility. |
otherwise |
Default value when the root is not found. By default,
|
interval |
Passed to |
tol |
Passed to |
... |
Passed to |
A function that takes a scalar numeric of quantity of good X and returns a scalar numeric of quantity of good Y.
util_2goods_utility(f, quantity, gradient = FALSE)util_2goods_utility(f, quantity, gradient = FALSE)
f |
A |
quantity |
A scalar numeric of quantity. |
gradient |
Logical input to return the gradient. By default, |
A function that takes a scalar numeric of quantity of good X and
returns a scalar numeric of total utility (gradient = TRUE) or marginal
utility (gradient = FALSE).
Calibrate a utility function
util_calibrate(f, prices, quantities, ...)util_calibrate(f, prices, quantities, ...)
f |
A |
prices |
A numeric vector of prices. |
quantities |
A numeric vector of quantities. |
... |
Additional arguments. |
A econ_util object with calibrated parameters.
Constant elasticity of substitution (CES) utility function
util_ces( substitution, homogeneity = 1, efficiency = NA_real_, weights = double(), homothetic = homogeneity == 1 ) util_ces2( elasticity_of_substitution, homogeneity = 1, efficiency = NA_real_, weights = double(), homothetic = homogeneity == 1 )util_ces( substitution, homogeneity = 1, efficiency = NA_real_, weights = double(), homothetic = homogeneity == 1 ) util_ces2( elasticity_of_substitution, homogeneity = 1, efficiency = NA_real_, weights = double(), homothetic = homogeneity == 1 )
substitution |
A scalar numeric of substitution parameter. |
homogeneity |
A scalar numeric of degree of homogeneity. By default,
|
efficiency |
A scalar numeric of efficiency parameter. |
weights |
A numeric vector of weights. |
homothetic |
A logical scalar. By default, |
elasticity_of_substitution |
A scalar numeric of elasticity of substitution. |
A util_ces object.
Cobb-Douglas utility function
util_cobb_douglas( efficiency = NA_real_, weights = double(), homothetic = length(weights) == 0 || sum(weights) == 1 )util_cobb_douglas( efficiency = NA_real_, weights = double(), homothetic = length(weights) == 0 || sum(weights) == 1 )
efficiency |
A scalar numeric of efficiency parameter. By default,
|
weights |
A numeric vector of weight parameters. By default, |
homothetic |
A logical scalar. By default, |
A util_cobb_douglas object.
This function works as Marshallian demand function when income is input, and
as Hicksian demand function when utility is input.
util_demand(f, prices, income = NULL, utility = NULL, gradient = FALSE, ...)util_demand(f, prices, income = NULL, utility = NULL, gradient = FALSE, ...)
f |
A |
prices |
A numeric vector of prices. |
income |
A scalar numeric of income. If |
utility |
A scalar numeric of utility level. If |
gradient |
Logical input to return the gradient. By default, |
... |
Additional arguments. |
when gradient = FALSE, a numeric vector of quantities. When
gradient = TRUE, a numeric matrix of gradients of quantities related to prices.
Hicksian demand function
util_demand_hicksian(f, prices, utility, gradient = FALSE, ...)util_demand_hicksian(f, prices, utility, gradient = FALSE, ...)
f |
A |
prices |
A numeric vector of prices. |
utility |
A scalar numeric of utility level. |
gradient |
Logical input to return the gradient. By default, |
... |
Additional arguments. |
when gradient = FALSE, a numeric vector of quantities. When
gradient = TRUE, a numeric matrix of gradients of quantities related to prices.
Marshallian demand function
util_demand_marshallian(f, prices, income, gradient = FALSE, ...)util_demand_marshallian(f, prices, income, gradient = FALSE, ...)
f |
A |
prices |
A numeric vector of prices. |
income |
A scalar numeric of income. |
gradient |
Logical input to return the gradient. By default, |
... |
Additional arguments. |
when gradient = FALSE, a numeric vector of quantities. When
gradient = TRUE, a numeric matrix of gradients of quantities related to prices.
Expenditure function
util_expenditure(f, prices, utility, gradient = FALSE, ...)util_expenditure(f, prices, utility, gradient = FALSE, ...)
f |
A |
prices |
A numeric vector of prices. |
utility |
A scalar numeric of utility level. |
gradient |
Logical input to return the gradient. By default, |
... |
Additional arguments. |
When gradient = FALSE, a scalar numeric of expenditure. When
gradient = TRUE, a numeric vector of gradients of expenditure related to
prices.
Gradient of a utility function
util_gradient(f, quantities, ...)util_gradient(f, quantities, ...)
f |
A |
quantities |
A numeric vector of quantities. |
... |
Additional arguments. |
A numeric vector of gradients.
Indirect utility function
util_indirect(f, prices, income, gradient = FALSE, ...)util_indirect(f, prices, income, gradient = FALSE, ...)
f |
A |
prices |
A numeric vector of prices. |
income |
A scalar numeric of income. |
gradient |
Logical input to return the gradient. By default, |
... |
Additional arguments. |
When gradient = FALSE, a scalar numeric of utility level. When
gradient = TRUE, a numeric vector of gradients of utility level related to
prices.
Leontief utility function
util_leontief(efficiency = NA_real_, weights = double())util_leontief(efficiency = NA_real_, weights = double())
efficiency |
A scalar numeric of efficiency parameter. By default,
|
weights |
A numeric vector of weight parameters. By default, |
A util_leontief object.
Linear utility function
util_linear(efficiency = NA_real_, weights = double())util_linear(efficiency = NA_real_, weights = double())
efficiency |
A scalar numeric of efficiency parameter. By default,
|
weights |
A numeric vector of weight parameters. By default, |
A util_linear object.
util_price(f, prices, quantities, ...)util_price(f, prices, quantities, ...)
f |
A |
prices |
A numeric vector of prices. |
quantities |
A numeric vector of quantities. |
... |
Additional arguments. |
A numeric scalar of price.