Package {dmai}


Type: Package
Title: Divisia Monetary Aggregates Index
Version: 1.0.0
Date: 2026-11-05
Description: Builds monetary aggregates from their components by the methods of index number theory. The Divisia index of Barnett (1980) <doi:10.1016/0304-4076(80)90070-6> weights every component (currency, demand deposits, savings and time deposits, ...) by its share in the expenditure on monetary services, priced by its user cost (Barnett 1978) <doi:10.1016/0165-1765(78)90051-4>. Also gives the Fisher ideal index, a variant with simple growth rates, the simple-sum aggregate, the currency equivalent index of Rotemberg, Driscoll and Poterba (1995), the dual user-cost price index and the Divisia second moments of Barnett and Serletis (1990) <doi:10.1016/0304-4076(90)90104-2>; benchmark rates given or taken from the components (upper envelope); 'ggplot2' graphics, a plain-language interpretation of every result and a built-in 'shiny' application.
License: GPL-2
URL: https://myaseen208.com/dmai/, https://github.com/myaseen208/dmai
BugReports: https://github.com/myaseen208/dmai/issues
Encoding: UTF-8
Language: en-US
LazyData: true
Depends: R (≥ 4.2)
Imports: data.table, ggplot2, grDevices, scales, stats, utils
Suggests: bslib, DT, knitr, magick, pkgload, quarto, ragg, R.rsp, shiny, svglite, testthat (≥ 3.0.0), withr
VignetteBuilder: quarto, R.rsp
Config/testthat/edition: 3
Config/skill/prefix: dmai
RoxygenNote: 7.3.1
NeedsCompilation: no
Packaged: 2026-11-09 02:01:43 UTC; myaseen208
Author: Muhammad Yaseen ORCID iD [aut, cre, cph], Ahmad Nadeem [aut, ctb]
Maintainer: Muhammad Yaseen <myaseen208@gmail.com>
Repository: CRAN
Date/Publication: 2026-11-09 08:50:17 UTC

dmai: Divisia monetary aggregates index

Description

The dmai package builds monetary aggregates from their components (currency, demand deposits, savings and time deposits, ...) by the methods of index number theory. The Divisia index of Barnett (1980) weights every component by its share in the expenditure on monetary services, priced by its user cost (Barnett 1978); the package also gives the Fisher ideal index, a variant with simple growth rates, the simple sum and the currency equivalent index, the dual user-cost price index and the Divisia second moments.

Functions

dmai()

the aggregate by one method (Barnett, Hancock, Fisher, simple sum, currency equivalent).

dmai_compare()

every method on the same data.

dmai_user_cost()

user costs and expenditure shares of the components.

dmai_moments()

Divisia means and variances of the growth of the components.

dmai_interpret(), dmai_cite(), dmai_app()

plain-language interpretation, references and a shiny application.

The data sets money_sim (simulated monetary data) and cpi_ch19 (the artificial data of the Consumer Price Index Manual, used to check the index formulas) come with the package.

Author(s)

Muhammad Yaseen (myaseen208@gmail.com) and Ahmad Nadeem (Ahmed.Nadeem@sbp.org.pk)

References

Barnett, W. A. (1978). The user cost of money. Economics Letters, 1(2), 145–149. doi:10.1016/0165-1765(78)90051-4

Barnett, W. A. (1980). Economic monetary aggregates: an application of index number and aggregation theory. Journal of Econometrics, 14(1), 11–48. doi:10.1016/0304-4076(80)90070-6

See Also

Useful links:


Plot a dmai result with ggplot2

Description

autoplot() methods for the results of dmai; plot() draws the same figures.

Usage

autoplot.dmai_result(object, which = NULL, ...)

Arguments

object

a result of dmai(..., as_dt = FALSE), dmai_compare(), dmai_user_cost() or dmai_moments().

which

the figure: for dmai() results "index" (default, with the simple sum), "growth", "shares", "user_cost", "moments" or "price"; for dmai_compare() "index" or "growth"; for dmai_user_cost() "shares" or "user_cost".

...

not used.

Value

A ggplot object.

Author(s)

Muhammad Yaseen (myaseen208@gmail.com)

Examples

data(money_sim)
fit <-
  dmai(
      .data     = money_sim
    , method    = "Barnett"
    , logbase   = NULL
    , date      = "Date"
    , x         = NULL
    , r         = NULL
    , user_cost = NULL
    , benchmark = "rb"
    , percent   = TRUE
    , base      = 100
    , as_dt     = FALSE
    )
ggplot2::autoplot(
    object = fit
  , which  = "shares"
  )

Artificial price and quantity data of the Consumer Price Index Manual

Description

The artificial data set of Chapter 19 of the Consumer Price Index Manual (ILO et al. 2004, Tables 19.1 and 19.2): prices and quantities of six commodities in five periods. The Manual gives the chained Laspeyres, Paasche, Fisher and Tornqvist price indexes of these data (Tables 19.5 and 19.11), which the package reproduces: a Divisia quantity index is a Tornqvist index with the user costs as prices, so dmai() with the prices as x and the quantities as user_cost gives the Manual's price indexes (the two roles are symmetric in these formulas).

Usage

cpi_ch19

Format

A data frame with 5 rows and 13 columns: period (1 to 5), p1, ..., p6 (prices) and q1, ..., q6 (quantities).

Source

ILO, IMF, OECD, UNECE, Eurostat and The World Bank (2004). Consumer Price Index Manual: Theory and Practice. International Labour Office, Geneva. Chapter 19, Tables 19.1 and 19.2.

See Also

Other dmai data: money_sim

Examples

data(cpi_ch19)
# the chained Tornqvist price index of Table 19.11: 1, 1.4052, 1.3112, 1.2624, 1.2224
dmai(
    .data     = cpi_ch19
  , method    = "Barnett"
  , logbase   = NULL
  , date      = "period"
  , x         = paste0("p", 1:6)
  , r         = NULL
  , user_cost = paste0("q", 1:6)
  , benchmark = NULL
  , percent   = TRUE
  , base      = 1
  , as_dt     = TRUE
  )

Divisia monetary aggregates index

Description

dmai() aggregates monetary assets (currency, deposits, ...) into one index of monetary services. Each component is weighted by its share in the expenditure on monetary services, priced by its user cost (Barnett 1978, 1980): an asset that pays a rate close to the benchmark rate is held mostly as a store of value and gets a small weight, while currency and demand deposits get a large one. The simple sum, which weights every component equally, and the currency equivalent index are given for comparison.

Usage

dmai(
  .data,
  method = c("Barnett", "Hancock", "Fisher", "SimpleSum", "CE"),
  logbase = NULL,
  date = "Date",
  x = NULL,
  r = NULL,
  user_cost = NULL,
  benchmark = NULL,
  percent = TRUE,
  base = 100,
  as_dt = TRUE
)

## Default S3 method:
dmai(
  .data,
  method = c("Barnett", "Hancock", "Fisher", "SimpleSum", "CE"),
  logbase = NULL,
  date = "Date",
  x = NULL,
  r = NULL,
  user_cost = NULL,
  benchmark = NULL,
  percent = TRUE,
  base = 100,
  as_dt = TRUE
)

Arguments

.data

a data frame with one row per date: a date column and, for every component, a quantity column and a rate column (named x1, x2, ... and r1, r2, ... unless x and r are given).

method

"Barnett" (default), "Hancock", "Fisher", "SimpleSum" or "CE".

logbase

base of the logarithm of the growth DMAI of the "Barnett", "Fisher", "SimpleSum" and "CE" indexes; NULL (default) for the natural logarithm. Version 0.5.0 used base 10 by default; logbase = 10 reproduces it.

date

name of the date column (default "Date").

x

names of the quantity columns (default NULL: x1, x2, ...).

r

names of the rate columns, in the order of x (default NULL: r1, r2, ...).

user_cost

names of columns that give the user costs directly, in the order of x (default NULL: computed from the rates). The rates are then needed only for "CE".

benchmark

the benchmark rate: NULL (default, the largest component rate), a column name, a number or one value per row of .data, in the units of the rates.

percent

logical; are the rates in percent (default TRUE) or decimal?

base

value of the index at the first date (default 100).

as_dt

logical; TRUE (default) returns the table of the index, as version 0.5.0 did; FALSE returns the full result.

Details

With quantities x_{it} of components i = 1, \dots, n at dates t, their rates of return r_{it} and the benchmark rate R_t, the user cost of component i is

\pi_{it} = \frac{R_t - r_{it}}{1 + R_t}

(Barnett 1978) and its expenditure share s_{it} = \pi_{it}x_{it} / \sum_j \pi_{jt}x_{jt}. With \bar{s}_{it} = (s_{it} + s_{i,t-1})/2, the methods are

"Barnett"

the Divisia index in the discrete form of Tornqvist and Theil (Barnett 1980):

\log\frac{Q_t}{Q_{t-1}} = \sum_i \bar{s}_{it}\left(\log x_{it} - \log x_{i,t-1}\right).

"Hancock"

the same shares with simple growth rates (as in version 0.5.0):

\frac{Q_t}{Q_{t-1}} - 1 = \sum_i \bar{s}_{it}\left(\frac{x_{it}}{x_{i,t-1}} - 1\right).

"Fisher"

the Fisher ideal index, the geometric mean of the Laspeyres and Paasche indexes with the user costs as prices (Fisher 1922; Diewert 1976):

\frac{Q_t}{Q_{t-1}} = \left(\frac{\sum_i \pi_{i,t-1}x_{it}}{\sum_i \pi_{i,t-1}x_{i,t-1}}\cdot\frac{\sum_i \pi_{it}x_{it}}{\sum_i \pi_{it}x_{i,t-1}}\right)^{1/2}.

"SimpleSum"

the official aggregate \sum_i x_{it}.

"CE"

the currency equivalent index \sum_i (R_t - r_{it})x_{it}/R_t (Rotemberg, Driscoll and Poterba 1995; Barnett 1991).

All indexes are chained and equal base at the first date. The growth DMAI is 100\log(Q_t/Q_{t-1})/\log(\mathrm{logbase}), in percent for the natural logarithm, and 100(Q_t/Q_{t-1} - 1) for "Hancock".

The benchmark rate is the largest rate of the components at each date when benchmark = NULL (as in version 0.5.0; that component then has a user cost of zero), or the given benchmark, raised to the largest component rate where it is lower (the upper envelope). The factor 1/(1 + R_t) is common to the components and does not change the shares.

The dual user-cost price index follows by factor reversal, P_t = E_t / V_t, with the expenditure E_t = \sum_i \pi_{it}x_{it} and the aggregate V_t in the units of x (column value).

Value

With as_dt = TRUE, a data.table with the date, DMAI (the growth in percent, NA at the first date), index and value (the index in the units of x, equal to the simple sum at the first date). With as_dt = FALSE, an object of class c("dmai_index", "dmai_result", "list") with index (that table), components (quantities, rates, user costs and shares by date), benchmark, price (expenditure and dual price index), moments (see dmai_moments()), simple_sum, fisher (Laspeyres and Paasche links, for "Fisher") and settings. print(), plot(), ggplot2::autoplot() and dmai_interpret() apply.

Author(s)

Muhammad Yaseen (myaseen208@gmail.com) and Ahmad Nadeem (Ahmed.Nadeem@sbp.org.pk)

References

Barnett, W. A. (1978). The user cost of money. Economics Letters, 1(2), 145–149. doi:10.1016/0165-1765(78)90051-4

Barnett, W. A. (1980). Economic monetary aggregates: an application of index number and aggregation theory. Journal of Econometrics, 14(1), 11–48. doi:10.1016/0304-4076(80)90070-6

Diewert, W. E. (1976). Exact and superlative index numbers. Journal of Econometrics, 4(2), 115–145. doi:10.1016/0304-4076(76)90009-9

Hancock, D. (1985). The financial firm: production with monetary and nonmonetary goods. Journal of Political Economy, 93(5), 859–880. doi:10.1086/261339

Rotemberg, J. J., Driscoll, J. C. and Poterba, J. M. (1995). Money, output, and prices: evidence from a new monetary aggregate. Journal of Business and Economic Statistics, 13(1), 67–83.

See Also

dmai_compare, dmai_user_cost, dmai_moments, dmai_interpret, money_sim

Other dmai analyses: dmai_compare(), dmai_moments(), dmai_user_cost()

Examples

data(money_sim)
d <-
  dmai(
      .data     = money_sim
    , method    = "Barnett"
    , logbase   = NULL
    , date      = "Date"
    , x         = NULL
    , r         = NULL
    , user_cost = NULL
    , benchmark = "rb"
    , percent   = TRUE
    , base      = 100
    , as_dt     = TRUE
    )
d
fit <-
  dmai(
      .data     = money_sim
    , method    = "Barnett"
    , logbase   = NULL
    , date      = "Date"
    , x         = NULL
    , r         = NULL
    , user_cost = NULL
    , benchmark = "rb"
    , percent   = TRUE
    , base      = 100
    , as_dt     = FALSE
    )
fit
plot(x = fit)

Methods for dmai results

Description

The analysis functions of dmai return the named list they have always returned, now with the class c("dmai_<analysis>", "dmai_result", "list"). Components are read as before (x$ANOVA, x[["Means"]]); the methods below print, summarise and plot the result and turn any component into a data.table.

Usage

## S3 method for class 'dmai_result'
print(x, digits = 4L, ...)

## S3 method for class 'dmai_result'
summary(object, ...)

## S3 method for class 'summary.dmai_result'
print(x, ...)

## S3 method for class 'dmai_result'
format(x, ...)

## S3 method for class 'dmai_result'
as.data.table(x, keep.rownames = FALSE, ..., component = 1L)

## S3 method for class 'dmai_result'
as.data.frame(x, row.names = NULL, optional = FALSE, ..., component = 1L)

## S3 method for class 'dmai_result'
plot(x, ...)

Arguments

x, object

a dmai result.

digits

significant digits of printed numbers (default 4).

...

passed on (to print() of the components, or to the plotting function for plot()).

keep.rownames, row.names, optional

as in data.table::as.data.table() and as.data.frame(); row names of a matrix or data frame component are always kept, in a first column term.

component

name or number of the component to convert (default: the first one).

Value

print() returns x invisibly; summary() an object of class summary.dmai_result; format() a character string; as.data.table() and as.data.frame() the chosen component as a table; plot() a ggplot object.

Author(s)

Muhammad Yaseen (myaseen208@gmail.com)


Monetary aggregates in a web browser

Description

dmai_app() starts the application of dmai: load the components of a monetary aggregate (the simulated example money_sim or a CSV file), choose the quantity and rate columns and the benchmark rate, compute the Divisia or another index, compare all methods, inspect the user costs, weights and Divisia second moments. Every result page shows an interpretation computed from the results (dmai_interpret()), the output as R prints it, formatted tables, plots and the R code that repeats the analysis, each with a Copy button.

Usage

dmai_app(launch.browser = interactive(), ...)

dmai_app_object()

Arguments

launch.browser

passed to shiny::runApp(): TRUE (default in an interactive session) opens the application in the web browser.

...

further arguments to shiny::runApp(), such as port.

Details

The application needs the suggested packages shiny, bslib and DT. Plots are sent to the browser as WebP images when magick is installed (smaller than PNG; PNG otherwise) and can be downloaded as PNG, PDF or WebP. Text is set in IBM Plex Sans and output in IBM Plex Mono when the browser can reach Google Fonts, in the system fonts otherwise. A CSV file needs one row per date: a date column (read as a date when it looks like one) and a quantity and a rate column for every component.

Value

dmai_app() is called for its side effect and returns the value of shiny::runApp() when the application is closed; dmai_app_object() returns the application object (for shiny::runApp(), shiny::testServer() or deployment on a server).

Author(s)

Muhammad Yaseen (myaseen208@gmail.com)

See Also

dmai, dmai_compare, dmai_interpret

Examples

if (interactive()) {
  dmai_app(
      launch.browser = TRUE
    )
}

References of a result or of the package

Description

dmai_cite() gives the references of the methods behind a result of the package, or the references of every method in the package, as text or BibTeX. citation("dmai") cites the package and its main methods.

Usage

dmai_cite(x = NULL, style = c("text", "bibtex"))

## Default S3 method:
dmai_cite(x = NULL, style = c("text", "bibtex"))

Arguments

x

a result of a function of the package (with as_dt = FALSE for dmai()), or NULL (default) for every reference of the package.

style

"text" (default) or "bibtex".

Value

An object of class bibentry (printed in the chosen style).

Author(s)

Muhammad Yaseen (myaseen208@gmail.com)

Examples

dmai_cite(
    x     = NULL
  , style = "text"
  )
data(money_sim)
fit <-
  dmai(
      .data     = money_sim
    , method    = "Fisher"
    , logbase   = NULL
    , date      = "Date"
    , x         = NULL
    , r         = NULL
    , user_cost = NULL
    , benchmark = "rb"
    , percent   = TRUE
    , base      = 100
    , as_dt     = FALSE
    )
dmai_cite(
    x     = fit
  , style = "bibtex"
  )

Monetary aggregates by every method

Description

dmai_compare() computes the Divisia (Barnett and Hancock), Fisher ideal, simple-sum and currency equivalent aggregates of the same data, as indexes equal to base at the first date, with their growth rates and average annual growth.

Usage

dmai_compare(
  .data,
  methods = c("Barnett", "Hancock", "Fisher", "SimpleSum", "CE"),
  logbase = NULL,
  date = "Date",
  x = NULL,
  r = NULL,
  user_cost = NULL,
  benchmark = NULL,
  percent = TRUE,
  base = 100
)

## Default S3 method:
dmai_compare(
  .data,
  methods = c("Barnett", "Hancock", "Fisher", "SimpleSum", "CE"),
  logbase = NULL,
  date = "Date",
  x = NULL,
  r = NULL,
  user_cost = NULL,
  benchmark = NULL,
  percent = TRUE,
  base = 100
)

Arguments

.data

a data frame with one row per date: a date column and, for every component, a quantity column and a rate column (named x1, x2, ... and r1, r2, ... unless x and r are given).

methods

the methods to compare (default: all five; "CE" is dropped when no rates are given).

logbase

base of the logarithm of the growth DMAI of the "Barnett", "Fisher", "SimpleSum" and "CE" indexes; NULL (default) for the natural logarithm. Version 0.5.0 used base 10 by default; logbase = 10 reproduces it.

date

name of the date column (default "Date").

x

names of the quantity columns (default NULL: x1, x2, ...).

r

names of the rate columns, in the order of x (default NULL: r1, r2, ...).

user_cost

names of columns that give the user costs directly, in the order of x (default NULL: computed from the rates). The rates are then needed only for "CE".

benchmark

the benchmark rate: NULL (default, the largest component rate), a column name, a number or one value per row of .data, in the units of the rates.

percent

logical; are the rates in percent (default TRUE) or decimal?

base

value of the index at the first date (default 100).

Value

An object of class c("dmai_compare", "dmai_result", "list"): indexes (a long data.table: date, method, index, growth), summary (by method: average growth per period and per year, standard deviation of growth, last index value) and settings. plot() draws the indexes or their growth (which = "growth").

Author(s)

Muhammad Yaseen (myaseen208@gmail.com)

References

Barnett, W. A. (1980). Economic monetary aggregates: an application of index number and aggregation theory. Journal of Econometrics, 14(1), 11–48. doi:10.1016/0304-4076(80)90070-6

See Also

Other dmai analyses: dmai(), dmai_moments(), dmai_user_cost()

Examples

data(money_sim)
cmp <-
  dmai_compare(
      .data     = money_sim
    , methods   = c("Barnett", "Hancock", "Fisher", "SimpleSum", "CE")
    , logbase   = NULL
    , date      = "Date"
    , x         = NULL
    , r         = NULL
    , user_cost = NULL
    , benchmark = "rb"
    , percent   = TRUE
    , base      = 100
    )
cmp
plot(x = cmp)

Plain-language interpretation of a result

Description

dmai_interpret() turns a result of the package into a short report: a headline, findings, recommendations and cautions, computed from its numbers, with the sources of the method. It covers dmai() (with as_dt = FALSE), dmai_compare(), dmai_user_cost() and dmai_moments().

Usage

dmai_interpret(x, top = 3L, ...)

## Default S3 method:
dmai_interpret(x, top = 3L, ...)

## S3 method for class 'dmai_interpretation'
print(x, ...)

## S3 method for class 'dmai_interpretation'
format(x, style = c("text", "markdown"), width = getOption("width", 80L), ...)

Arguments

x

a result of a function of the package.

top

number of dates or components named in the findings (default 3).

...

unused.

style

"text" (default) or "markdown".

width

line width of the text (default getOption("width")).

Details

Growth per year is the average growth between the first and last dates, annualised with the spacing of the dates (monthly, quarterly, half-yearly or annual) when the date column is of class Date; otherwise growth is reported per period.

Value

An object of class "dmai_interpretation": a list with analysis, title, headline, findings, recommendations, cautions, facts (the numbers behind the sentences), guide (how to read the method) and sources. format() gives it as text or Markdown.

Author(s)

Muhammad Yaseen (myaseen208@gmail.com)

See Also

dmai_cite, dmai_app

Examples

data(money_sim)
fit <-
  dmai(
      .data     = money_sim
    , method    = "Barnett"
    , logbase   = NULL
    , date      = "Date"
    , x         = NULL
    , r         = NULL
    , user_cost = NULL
    , benchmark = "rb"
    , percent   = TRUE
    , base      = 100
    , as_dt     = FALSE
    )
dmai_interpret(
    x   = fit
  , top = 3
  )

Divisia second moments

Description

dmai_moments() gives the Divisia mean and variance of the growth rates of the components at every date (Theil 1967; Barnett and Serletis 1990):

\kappa_t = \sum_i \bar{s}_{it}\,\Delta\log x_{it}, \qquad K_t = \sum_i \bar{s}_{it}\left(\Delta\log x_{it} - \kappa_t\right)^2,

and the same for the user costs. A large variance means the components grow at very different rates, so that the choice of weights matters and the simple sum is a poor guide; Barnett and Serletis use it as a diagnostic of aggregation error.

Usage

dmai_moments(.data, ...)

## Default S3 method:
dmai_moments(
  .data,
  ...,
  date = "Date",
  x = NULL,
  r = NULL,
  user_cost = NULL,
  benchmark = NULL,
  percent = TRUE
)

## S3 method for class 'dmai_index'
dmai_moments(.data, ...)

Arguments

.data

a data frame as in dmai(), or a result of dmai(..., as_dt = FALSE).

...

further arguments of dmai() (date, x, r, user_cost, benchmark, percent) when .data is a data frame.

date

name of the date column (default "Date").

x

names of the quantity columns (default NULL: x1, x2, ...).

r

names of the rate columns, in the order of x (default NULL: r1, r2, ...).

user_cost

names of columns that give the user costs directly, in the order of x (default NULL: computed from the rates). The rates are then needed only for "CE".

benchmark

the benchmark rate: NULL (default, the largest component rate), a column name, a number or one value per row of .data, in the units of the rates.

percent

logical; are the rates in percent (default TRUE) or decimal?

Value

An object of class c("dmai_moments", "dmai_result", "list"): moments (a data.table with the date, growth = 100\kappa_t, variance = 10^4K_t, sd, price_growth and price_variance) and settings. plot() draws the standard deviation over time.

Author(s)

Muhammad Yaseen (myaseen208@gmail.com)

References

Barnett, W. A. and Serletis, A. (1990). A dispersion-dependency diagnostic test for aggregation error: with applications to monetary economics and income distribution. Journal of Econometrics, 43(1–2), 5–34. doi:10.1016/0304-4076(90)90104-2

Theil, H. (1967). Economics and Information Theory. North-Holland, Amsterdam.

See Also

Other dmai analyses: dmai(), dmai_compare(), dmai_user_cost()

Examples

data(money_sim)
m <-
  dmai_moments(
      .data     = money_sim
    , benchmark = "rb"
    )
m
plot(x = m)

Notation of dmai

Description

The symbols used in the help pages and vignettes of dmai, with their meaning and the argument or result component that holds them. The notation follows one rule throughout: scalars are upper-case letters in normal face (P, R), indices lower-case italic (i, j), vectors lower-case bold (\mathbf{y}, \boldsymbol{\beta}) and matrices upper-case bold (\mathbf{X}, \boldsymbol{\Sigma}).

Usage

dmai_notation(format = c("table", "path", "tex"))

Arguments

format

"table" (default: a data.table with columns symbol (LaTeX), text (plain text), kind (scalar, index, vector, matrix, set, function, operator), meaning and argument), "path" (the path of notation.csv) or "tex" (the path of Notations.tex, the notation appendix used in the articles).

Value

See format.

Author(s)

Muhammad Yaseen (myaseen208@gmail.com)

See Also

Other dmai utilities: dmai_reference(), dmai_save(), dmai_theme()

Examples

dmai_notation(
    format = c("table", "path", "tex")[1]
  )

Published values used by the tests and vignettes

Description

Reads inst/extdata/reference.csv: one row per published number, with its source, the R call that recomputes it with this package (call), the expression that extracts the number from the result (extract, in terms of x), the printed value and the digits to compare. The same file drives the test of published values and the vignette that reproduces the published examples. Each distinct call is evaluated once.

Usage

dmai_reference(source = NULL, evaluate = FALSE, level = 1)

Arguments

source

optional regular expression; keep rows whose source matches.

evaluate

logical; evaluate the rows and add columns computed and agrees (default FALSE).

level

largest level evaluated (1 = fast rows, 2 = slow rows; default 1); rows above it get NA.

Value

A data.table with columns id, source, quantity, call, extract, value, digits, level, note (and computed, agrees).

Author(s)

Muhammad Yaseen (myaseen208@gmail.com)

See Also

Other dmai utilities: dmai_notation(), dmai_save(), dmai_theme()

Examples

ref <-
  dmai_reference(
      source   = NULL
    , evaluate = FALSE
    , level    = 1
    )
ref

dmai_reference(
    source   = "."
  , evaluate = TRUE
  , level    = 1
  )


Save a figure (vector PDF by default)

Description

A wrapper of ggsave with the defaults of the package: a vector PDF through cairo_pdf (embedded fonts, correct glyphs), A4 landscape (11.69 x 8.27 inches) and 600 dpi for raster formats. The device follows the file extension for other formats (.png, .svg, .tiff, ...).

Usage

dmai_save(
  plot = ggplot2::last_plot(),
  filename,
  path = NULL,
  width = 11.69,
  height = 8.27,
  units = c("in", "cm", "mm"),
  dpi = 600,
  scale = 1,
  device = NULL,
  limitsize = TRUE,
  ...
)

## Default S3 method:
dmai_save(
  plot = ggplot2::last_plot(),
  filename,
  path = NULL,
  width = 11.69,
  height = 8.27,
  units = c("in", "cm", "mm"),
  dpi = 600,
  scale = 1,
  device = NULL,
  limitsize = TRUE,
  ...
)

Arguments

plot

a ggplot object, for example the result of plot() on a dmai result (default: the last plot).

filename

file name; its extension chooses the format.

path

directory to save in (default NULL: the working directory or the path in filename).

width, height

size (default 11.69 x 8.27, A4 landscape, in units).

units

"in" (default), "cm" or "mm".

dpi

resolution for raster formats (default 600).

scale

multiplicative scaling factor (default 1).

device

NULL (default: cairo_pdf for .pdf, otherwise chosen from the extension) or a device function or name, passed to ggsave(). A file name ending in .webp gives a WebP image (drawn as PNG, then converted without loss by the suggested package magick; about half the size of the PNG).

limitsize

logical; refuse images larger than 50 x 50 inches (default TRUE).

...

passed to ggsave.

Value

The file name, invisibly.

Author(s)

Muhammad Yaseen (myaseen208@gmail.com)

See Also

Other dmai utilities: dmai_notation(), dmai_reference(), dmai_theme()

Examples

library(ggplot2)
p <-
  ggplot(data = data.frame(x = 1:10, y = (1:10)^2), mapping = aes(x = x, y = y)) +
  geom_line() +
  dmai_theme(
      base_size       = 11
    , base_family     = "serif"
    , ticks_inward    = TRUE
    , legend_position = "bottom"
    )
f <- tempfile(fileext = ".pdf")
dmai_save(
    plot      = p
  , filename  = f
  , path      = NULL
  , width     = 11.69
  , height    = 8.27
  , units     = c("in", "cm", "mm")[1]
  , dpi       = 600
  , scale     = 1
  , device    = NULL
  , limitsize = TRUE
  )
dmai_save(
    plot      = p
  , filename  = basename(f)
  , path      = tempdir()
  , width     = 11.69
  , height    = 8.27
  , units     = c("in", "cm", "mm")[1]
  , dpi       = 600
  , scale     = 1
  , device    = grDevices::cairo_pdf
  , limitsize = TRUE
  )
dmai_save(
    plot      = p
  , filename  = tempfile(fileext = ".png")
  , path      = NULL
  , width     = 6
  , height    = 4
  , units     = c("in", "cm", "mm")[1]
  , dpi       = 300
  , scale     = 1
  , device    = NULL
  , limitsize = TRUE
  )

ggplot2 theme of dmai

Description

The theme used by every plot() method of dmai (identical in all packages of the author): theme_classic with a serif font, black axis lines, ticks pointing inwards and no grid, close to the look of TikZ/pgfplots figures in LaTeX documents. The plot() methods also use scales::pretty_breaks(n = 10) on every continuous axis. Save figures with dmai_save.

Usage

dmai_theme(
  base_size = 11,
  base_family = "serif",
  ticks_inward = TRUE,
  legend_position = "bottom"
)

Arguments

base_size

base font size in points (default 11).

base_family

font family (default "serif"; for example "Latin Modern Roman" when installed, to match LaTeX documents).

ticks_inward

logical; ticks point into the panel, as in pgfplots (default TRUE).

legend_position

position of the legend (default "bottom").

Value

A ggplot2 theme.

Author(s)

Muhammad Yaseen (myaseen208@gmail.com)

See Also

Other dmai utilities: dmai_notation(), dmai_reference(), dmai_save()

Examples

library(ggplot2)
p <-
  ggplot(data = data.frame(x = 1:20, y = cumsum(sin(1:20))), mapping = aes(x = x, y = y)) +
  geom_line()
p +
  dmai_theme(
      base_size       = 11
    , base_family     = "serif"
    , ticks_inward    = TRUE
    , legend_position = "bottom"
    )
p +
  dmai_theme(
      base_size       = 12
    , base_family     = "serif"
    , ticks_inward    = FALSE
    , legend_position = "right"
    ) +
  scale_x_continuous(breaks = scales::pretty_breaks(n = 10))

User costs and expenditure shares of monetary assets

Description

dmai_user_cost() gives, for every date and component, the rate, the user cost \pi_{it} = (R_t - r_{it})/(1 + R_t) (Barnett 1978) and the share of the component in the expenditure on monetary services, the weights of the Divisia index.

Usage

dmai_user_cost(
  .data,
  date = "Date",
  x = NULL,
  r = NULL,
  benchmark = NULL,
  percent = TRUE
)

## Default S3 method:
dmai_user_cost(
  .data,
  date = "Date",
  x = NULL,
  r = NULL,
  benchmark = NULL,
  percent = TRUE
)

Arguments

.data

a data frame with one row per date: a date column and, for every component, a quantity column and a rate column (named x1, x2, ... and r1, r2, ... unless x and r are given).

date

name of the date column (default "Date").

x

names of the quantity columns (default NULL: x1, x2, ...).

r

names of the rate columns, in the order of x (default NULL: r1, r2, ...).

benchmark

the benchmark rate: NULL (default, the largest component rate), a column name, a number or one value per row of .data, in the units of the rates.

percent

logical; are the rates in percent (default TRUE) or decimal?

Value

An object of class c("dmai_user_cost", "dmai_result", "list"): components (date, component, quantity, rate, user cost, share), benchmark (the benchmark rate and whether the upper envelope raised it) and settings. plot() draws the shares over time.

Author(s)

Muhammad Yaseen (myaseen208@gmail.com)

References

Barnett, W. A. (1978). The user cost of money. Economics Letters, 1(2), 145–149. doi:10.1016/0165-1765(78)90051-4

See Also

Other dmai analyses: dmai(), dmai_compare(), dmai_moments()

Examples

data(money_sim)
uc <-
  dmai_user_cost(
      .data     = money_sim
    , date      = "Date"
    , x         = NULL
    , r         = NULL
    , benchmark = "rb"
    , percent   = TRUE
    )
uc
plot(x = uc)

Simulated monetary components and rates

Description

SIMULATED monthly data, January 2005 to December 2024, shaped like the components of a broad money aggregate of a central bank: quantities (billions) and rates of return (percent a year) of eight components, and a benchmark rate. The numbers are not real; they are drawn by data-raw/make-data.R in the source package (rates as autoregressive processes that follow a policy-type rate, quantities as trending series that respond to the spread between their own rate and the benchmark) to show the methods.

Usage

money_sim

Format

A data frame with 240 rows and 18 columns:

Date

first day of the month (class Date).

x1

currency in circulation.

x2

demand deposits.

x3

savings deposits.

x4

time deposits up to 3 months.

x5

time deposits of 3 to 6 months.

x6

time deposits of 6 months to 1 year.

x7

time deposits over 1 year.

x8

foreign currency deposits.

r1

the own rate of x1 in percent (zero).

r2

the own rate of x2 in percent (zero).

r3

the own rate of x3 in percent.

r4

the own rate of x4 in percent.

r5

the own rate of x5 in percent.

r6

the own rate of x6 in percent.

r7

the own rate of x7 in percent.

r8

the own rate of x8 in percent.

rb

the benchmark rate in percent (a long bond yield), above every component rate.

Source

Simulated; see data-raw/make-data.R.

See Also

Other dmai data: cpi_ch19

Examples

data(money_sim)
head(money_sim)