| Title: | Inflation Decomposition, Core Measures, and Trend Estimation |
|---|---|
| Description: | Tools for analysing inflation dynamics. Computes weighted contributions of price index components, core inflation measures (trimmed mean, weighted median, exclusion-based) following Bryan and Cecchetti (1994), inflation persistence via sum-of-AR-coefficients, diffusion indices, Phillips curve estimation, breakeven inflation, and trend inflation using the Beveridge-Nelson decomposition and Hodrick-Prescott filter. All functions are pure computation and work with price data from any source. |
| Authors: | Charles Coverdale [aut, cre] |
| Maintainer: | Charles Coverdale <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-30 15:07:06 UTC |
| Source: | https://github.com/charlescoverdale/inflationkit |
Calculates breakeven inflation as the spread between nominal and real (inflation-linked) bond yields. This provides a market-based measure of inflation expectations.
ik_breakeven(nominal_yield, real_yield, maturity = NULL)ik_breakeven(nominal_yield, real_yield, maturity = NULL)
nominal_yield |
Numeric vector. Nominal bond yields. |
real_yield |
Numeric vector. Real (inflation-linked) bond yields, same
length as |
maturity |
Numeric vector or |
Note: breakeven inflation is a simplified measure that does not account for inflation risk premium or liquidity premium. It should be interpreted as a rough proxy for inflation expectations, not a precise measure.
An S3 object of class "ik_breakeven" with elements:
If maturity is provided, a data.frame with columns:
maturity, nominal, real, breakeven. Otherwise, a numeric vector of
breakeven rates.
The maturity vector (or NULL).
# Breakeven term structure be <- ik_breakeven( nominal_yield = c(4.2, 4.5, 4.8, 5.0), real_yield = c(1.8, 2.0, 2.3, 2.5), maturity = c(2, 5, 10, 30) ) print(be) plot(be) # Simple breakeven (no maturity) be2 <- ik_breakeven(nominal_yield = 4.5, real_yield = 2.0) print(be2)# Breakeven term structure be <- ik_breakeven( nominal_yield = c(4.2, 4.5, 4.8, 5.0), real_yield = c(1.8, 2.0, 2.3, 2.5), maturity = c(2, 5, 10, 30) ) print(be) plot(be) # Simple breakeven (no maturity) be2 <- ik_breakeven(nominal_yield = 4.5, real_yield = 2.0) print(be2)
Takes multiple ik_core objects and facilitates side-by-side comparison.
Produces summary statistics and a multi-line chart of all measures.
ik_compare(..., labels = NULL)ik_compare(..., labels = NULL)
... |
One or more objects of class |
labels |
Character vector or |
An S3 object of class "ik_comparison" with elements:
List of ik_core objects.
Character vector of labels.
data <- ik_sample_data("components") core_tm <- ik_core(data, method = "trimmed_mean") core_wm <- ik_core(data, method = "weighted_median") core_ex <- ik_core(data, method = "exclusion", exclude = c("Food", "Transport")) comp <- ik_compare(core_tm, core_wm, core_ex) print(comp) plot(comp)data <- ik_sample_data("components") core_tm <- ik_core(data, method = "trimmed_mean") core_wm <- ik_core(data, method = "weighted_median") core_ex <- ik_core(data, method = "exclusion", exclude = c("Food", "Transport")) comp <- ik_compare(core_tm, core_wm, core_ex) print(comp) plot(comp)
Estimates core (underlying) inflation using one of three standard methods: trimmed mean, weighted median, or exclusion-based. These measures aim to strip out transitory price movements and reveal the persistent trend.
ik_core( data, method = c("trimmed_mean", "weighted_median", "exclusion", "asymmetric_trim"), trim = 0.08, trim_lower = 0.24, trim_upper = 0.31, exclude = NULL, date_col = "date", item_col = "item", change_col = "price_change", weight_col = "weight" )ik_core( data, method = c("trimmed_mean", "weighted_median", "exclusion", "asymmetric_trim"), trim = 0.08, trim_lower = 0.24, trim_upper = 0.31, exclude = NULL, date_col = "date", item_col = "item", change_col = "price_change", weight_col = "weight" )
data |
A data.frame containing component-level inflation data. |
method |
Character. One of |
trim |
Numeric. Fraction to trim from each tail (for |
trim_lower |
Numeric. Fraction to trim from the lower tail (for
|
trim_upper |
Numeric. Fraction to trim from the upper tail (for
|
exclude |
Character vector. Items to exclude (for |
date_col |
Character. Name of the date column. Default |
item_col |
Character. Name of the item/component column. Default
|
change_col |
Character. Name of the price change column. Default
|
weight_col |
Character. Name of the weight column. Default |
An S3 object of class "ik_core" with elements:
data.frame with columns: date, core_inflation.
Character. The method used.
Numeric. The trim fraction (if applicable).
Character vector. Excluded items (if applicable).
data.frame with columns: date, headline.
Bryan, M. F. and Cecchetti, S. G. (1993). "The Consumer Price Index as a Measure of Inflation." NBER Working Paper No. 4505.
Bryan, M. F. and Cecchetti, S. G. (1994). "Measuring Core Inflation." In Monetary Policy, University of Chicago Press.
data <- ik_sample_data("components") # Trimmed mean (default) core_tm <- ik_core(data, method = "trimmed_mean") print(core_tm) # Weighted median core_wm <- ik_core(data, method = "weighted_median") print(core_wm) # Exclusion-based core_ex <- ik_core(data, method = "exclusion", exclude = c("Food", "Transport")) print(core_ex)data <- ik_sample_data("components") # Trimmed mean (default) core_tm <- ik_core(data, method = "trimmed_mean") print(core_tm) # Weighted median core_wm <- ik_core(data, method = "weighted_median") print(core_wm) # Exclusion-based core_ex <- ik_core(data, method = "exclusion", exclude = c("Food", "Transport")) print(core_ex)
Computes the weighted contribution of each CPI component to headline
inflation. The contribution of item i is weight_i * price_change_i, and
headline inflation is the sum of all contributions for each period.
ik_decompose( data, date_col = "date", item_col = "item", change_col = "price_change", weight_col = "weight" )ik_decompose( data, date_col = "date", item_col = "item", change_col = "price_change", weight_col = "weight" )
data |
A data.frame containing component-level inflation data. |
date_col |
Character. Name of the date column. Default |
item_col |
Character. Name of the item/component column. Default
|
change_col |
Character. Name of the price change column. Default
|
weight_col |
Character. Name of the weight column. Default |
An S3 object of class "ik_decomposition" with elements:
data.frame with columns: date, item, weight, price_change, contribution.
data.frame with columns: date, headline_inflation.
data <- ik_sample_data("components") decomp <- ik_decompose(data) print(decomp) plot(decomp)data <- ik_sample_data("components") decomp <- ik_decompose(data) print(decomp) plot(decomp)
Measures the breadth of price increases across CPI components. For each period, computes the (weighted or unweighted) fraction of items with price changes exceeding a threshold. A diffusion index above 0.5 indicates that more than half of items are experiencing above-threshold price increases.
ik_diffusion( data, threshold = c("zero", "mean", "target"), target = 0.02, weighted = TRUE, date_col = "date", item_col = "item", change_col = "price_change", weight_col = "weight" )ik_diffusion( data, threshold = c("zero", "mean", "target"), target = 0.02, weighted = TRUE, date_col = "date", item_col = "item", change_col = "price_change", weight_col = "weight" )
data |
A data.frame containing component-level inflation data. |
threshold |
Character. The threshold rule: |
target |
Numeric. Annualised inflation target (for |
weighted |
Logical. If |
date_col |
Character. Name of the date column. Default |
item_col |
Character. Name of the item/component column. Default
|
change_col |
Character. Name of the price change column. Default
|
weight_col |
Character. Name of the weight column. Default |
An S3 object of class "ik_diffusion" with elements:
data.frame with columns: date, diffusion_index.
Character. The threshold type used.
Logical. Whether weights were used.
data <- ik_sample_data("components") # Fraction of items with rising prices d <- ik_diffusion(data, threshold = "zero") print(d) plot(d)data <- ik_sample_data("components") # Fraction of items with rising prices d <- ik_diffusion(data, threshold = "zero") print(d) plot(d)
Runs standard forecast evaluation tests. The bias test (Mincer-Zarnowitz) checks whether forecasts are unbiased. The efficiency test (Nordhaus) checks whether forecast errors are autocorrelated. The Diebold-Mariano test compares predictive accuracy of two competing forecasts.
ik_forecast_eval( actual, forecast, test = c("bias", "efficiency", "dm"), forecast2 = NULL, horizon = 1L, alternative = c("two.sided", "less", "greater") )ik_forecast_eval( actual, forecast, test = c("bias", "efficiency", "dm"), forecast2 = NULL, horizon = 1L, alternative = c("two.sided", "less", "greater") )
actual |
Numeric vector. Realised inflation values. |
forecast |
Numeric vector. Forecast values, same length as |
test |
Character. One of |
forecast2 |
Numeric vector or |
horizon |
Integer. Forecast horizon (used for Newey-West bandwidth in
the DM test). Default |
alternative |
Character. Alternative hypothesis for the DM test:
|
An S3 object of class "ik_forecast_eval" with elements:
Character. The test performed.
Numeric. The test statistic.
Numeric. The p-value.
Named numeric vector (for bias and efficiency tests).
Character. A plain-language summary of the result.
Diebold, F. X. and Mariano, R. S. (1995). "Comparing Predictive Accuracy." Journal of Business and Economic Statistics, 13(3), 253-263.
set.seed(42) data <- ik_sample_data("headline") actual <- data$inflation[5:80] forecast1 <- data$inflation[4:79] + rnorm(76, 0, 0.2) forecast2 <- data$inflation[4:79] + rnorm(76, 0, 0.4) # Mincer-Zarnowitz bias test bias <- ik_forecast_eval(actual, forecast1, test = "bias") print(bias) # Diebold-Mariano test dm <- ik_forecast_eval(actual, forecast1, test = "dm", forecast2 = forecast2) print(dm)set.seed(42) data <- ik_sample_data("headline") actual <- data$inflation[5:80] forecast1 <- data$inflation[4:79] + rnorm(76, 0, 0.2) forecast2 <- data$inflation[4:79] + rnorm(76, 0, 0.4) # Mincer-Zarnowitz bias test bias <- ik_forecast_eval(actual, forecast1, test = "bias") print(bias) # Diebold-Mariano test dm <- ik_forecast_eval(actual, forecast1, test = "dm", forecast2 = forecast2) print(dm)
Estimates the degree of persistence in an inflation series using one of three methods: sum of AR coefficients, half-life, or largest autoregressive root.
ik_persistence( x, method = c("sum_ar", "half_life", "largest_root"), ar_order = NULL, max_order = 12L, ic = c("bic", "aic") )ik_persistence( x, method = c("sum_ar", "half_life", "largest_root"), ar_order = NULL, max_order = 12L, ic = c("bic", "aic") )
x |
Numeric vector. An inflation time series. |
method |
Character. One of |
ar_order |
Integer or |
max_order |
Integer. Maximum AR order to consider when selecting
automatically. Default |
ic |
Character. Information criterion for order selection: |
An S3 object of class "ik_persistence" with elements:
Numeric. The persistence measure.
Character. The method used.
Integer. The AR order fitted.
Numeric vector. The estimated AR coefficients.
Character. A plain-language interpretation ("High persistence", "Moderate persistence", or "Low persistence").
Andrews, D. W. K. and Chen, H.-Y. (1994). "Approximately Median-Unbiased Estimation of Autoregressive Models." Journal of Business and Economic Statistics, 12(2), 187-204.
Marques, C. R. (2004). "Inflation Persistence: Facts or Artefacts?" ECB Working Paper No. 371.
data <- ik_sample_data("headline") p <- ik_persistence(data$inflation, method = "sum_ar") print(p) p_hl <- ik_persistence(data$inflation, method = "half_life") print(p_hl)data <- ik_sample_data("headline") p <- ik_persistence(data$inflation, method = "sum_ar") print(p) p_hl <- ik_persistence(data$inflation, method = "half_life") print(p_hl)
Fits a Phillips curve relating inflation to an economic slack measure (output gap or unemployment rate). Supports traditional, expectations- augmented, and hybrid specifications.
ik_phillips( inflation, slack, expectations = NULL, type = c("traditional", "expectations_augmented", "hybrid"), lags = 4L, robust_se = FALSE )ik_phillips( inflation, slack, expectations = NULL, type = c("traditional", "expectations_augmented", "hybrid"), lags = 4L, robust_se = FALSE )
inflation |
Numeric vector. Inflation rate series. |
slack |
Numeric vector. Slack measure (output gap or unemployment rate),
same length as |
expectations |
Numeric vector or |
type |
Character. Phillips curve specification: |
lags |
Integer. Number of lagged inflation terms to include. Default
|
robust_se |
Logical or character. If |
An S3 object of class "ik_phillips" with elements:
Named numeric vector of estimated coefficients.
Named numeric vector of standard errors.
Named numeric vector of p-values.
Numeric. R-squared of the regression.
Character. The Phillips curve type.
Numeric. The estimated slope on the slack variable.
Integer. Number of observations used.
Numeric vector. Regression residuals.
data <- ik_sample_data("headline") pc <- ik_phillips(data$inflation, data$unemployment, type = "traditional") print(pc) plot(pc)data <- ik_sample_data("headline") pc <- ik_phillips(data$inflation, data$unemployment, type = "traditional") print(pc) plot(pc)
Creates synthetic data for testing and demonstrating inflationkit functions. Two types are available: component-level CPI data and headline macro data.
ik_sample_data(type = c("components", "headline"))ik_sample_data(type = c("components", "headline"))
type |
Character. Either |
A data.frame. For "components": columns date, item, weight,
price_change (120 months, 10 items, 1200 rows). For "headline":
columns date, inflation, output_gap, unemployment (80 quarterly
observations).
comp <- ik_sample_data("components") head(comp) macro <- ik_sample_data("headline") head(macro)comp <- ik_sample_data("components") head(comp) macro <- ik_sample_data("headline") head(macro)
Splits CPI components into sticky-price and flexible-price categories based on a user-provided classification, then computes separate weighted inflation measures for each group. This follows the Atlanta Fed methodology.
ik_sticky_flexible( data, classification, date_col = "date", item_col = "item", change_col = "price_change", weight_col = "weight" )ik_sticky_flexible( data, classification, date_col = "date", item_col = "item", change_col = "price_change", weight_col = "weight" )
data |
A data.frame containing component-level inflation data. |
classification |
A named logical vector or a data.frame. If a named
logical vector, names correspond to item names and |
date_col |
Character. Name of the date column. Default |
item_col |
Character. Name of the item/component column. Default
|
change_col |
Character. Name of the price change column. Default
|
weight_col |
Character. Name of the weight column. Default |
An S3 object of class "ik_sticky_flex" with elements:
data.frame with columns: date, sticky, flexible, headline.
Named logical vector mapping items to sticky/flexible.
Bils, M. and Klenow, P. J. (2004). "Some Evidence on the Importance of Sticky Prices." Journal of Political Economy, 112(5), 947-985.
data <- ik_sample_data("components") # Classify items class_vec <- c( Food = FALSE, Housing = TRUE, Transport = FALSE, Clothing = FALSE, Health = TRUE, Education = TRUE, Communication = TRUE, Recreation = FALSE, Restaurants = TRUE, Other = FALSE ) sf <- ik_sticky_flexible(data, classification = class_vec) print(sf) plot(sf)data <- ik_sample_data("components") # Classify items class_vec <- c( Food = FALSE, Housing = TRUE, Transport = FALSE, Clothing = FALSE, Health = TRUE, Education = TRUE, Communication = TRUE, Recreation = FALSE, Restaurants = TRUE, Other = FALSE ) sf <- ik_sticky_flexible(data, classification = class_vec) print(sf) plot(sf)
Extracts the trend component from an inflation series using one of four methods: Hodrick-Prescott filter, Beveridge-Nelson decomposition, exponential smoothing, or centred moving average.
ik_trend( x, method = c("hp", "beveridge_nelson", "exponential_smooth", "moving_average"), frequency = c("quarterly", "monthly", "annual"), lambda = NULL, window = NULL )ik_trend( x, method = c("hp", "beveridge_nelson", "exponential_smooth", "moving_average"), frequency = c("quarterly", "monthly", "annual"), lambda = NULL, window = NULL )
x |
Numeric vector. An inflation time series. |
method |
Character. One of |
frequency |
Character. Data frequency: |
lambda |
Numeric or |
window |
Integer or |
An S3 object of class "ik_trend" with elements:
Numeric vector. The estimated trend component.
Numeric vector. The cyclical component (original minus trend).
Character. The method used.
Numeric. HP filter lambda (if applicable).
Integer. Moving average window (if applicable).
Numeric. Exponential smoothing parameter (if applicable).
Numeric vector. The original series.
Hodrick, R. J. and Prescott, E. C. (1997). "Postwar U.S. Business Cycles: An Empirical Investigation." Journal of Money, Credit and Banking, 29(1), 1-16.
Ravn, M. O. and Uhlig, H. (2002). "On Adjusting the Hodrick-Prescott Filter for the Frequency of Observations." Review of Economics and Statistics, 84(2), 371-376.
data <- ik_sample_data("headline") tr <- ik_trend(data$inflation, method = "hp") print(tr) plot(tr) tr_ma <- ik_trend(data$inflation, method = "moving_average", window = 4) print(tr_ma)data <- ik_sample_data("headline") tr <- ik_trend(data$inflation, method = "hp") print(tr) plot(tr) tr_ma <- ik_trend(data$inflation, method = "moving_average", window = 4) print(tr_ma)