An R package for inflation analysis. Decompose headline inflation into component contributions, compute core measures (trimmed mean, weighted median, exclusion-based), estimate how persistent inflation is, fit Phillips curves, and extract the underlying trend from noisy price data.
install.packages("inflationkit")
# Or install the development version from GitHub
# install.packages("devtools")
devtools::install_github("charlescoverdale/inflationkit")library(inflationkit)
# Built-in sample data: 10 CPI components, 120 months
d <- ik_sample_data("components")
head(d)
#> date item weight price_change
#> 1 2015-01-01 Food 0.15 0.003218
#> 2 2015-01-01 Housing 0.25 0.004274
#> 3 2015-01-01 Transport 0.12 0.001893
#> ...
# What is driving inflation?
decomp <- ik_decompose(d)
plot(decomp)Headline inflation is noisy. Food and energy prices swing month to month, making it hard to tell whether inflation is genuinely rising or just reacting to a temporary shock. Central banks solve this by computing "core" measures (trimmed means, weighted medians, exclusion-based indices) and studying persistence, diffusion, and trend. These are standard tools in every central bank research department, but there is no general-purpose R package for any of them. The only CRAN package with "inflation" in its name (Inflation) is Brazil-specific and has not been updated since 2017.
inflationkit fills this gap. You bring CPI component data from any country, and the package handles decomposition, core measures, persistence estimation, Phillips curves, trend extraction, and forecast evaluation. Functions accept any column names, so you can plug in your own dataset without reshaping it first.
Decompose headline inflation into the weighted contribution of each component. This tells you how many percentage points each category (food, housing, transport, etc.) is adding to the total.
d <- ik_sample_data("components")
decomp <- ik_decompose(d)
decomp
#> -- Inflation Decomposition --
#> * Period: 2015-01-01 to 2024-12-01
#> * Number of items: 10
#> * Mean headline inflation: 0.25%
plot(decomp) # Stacked bar chart of contributions over timeCompare four core inflation measures side by side. The trimmed mean and weighted median are distribution-based (they let the data decide what to exclude each month). The exclusion method and asymmetric trim use fixed rules.
d <- ik_sample_data("components")
# Cleveland Fed style: symmetric 8% trim
tm <- ik_core(d, method = "trimmed_mean", trim = 0.08)
# Weighted median: 50th percentile of price changes
wm <- ik_core(d, method = "weighted_median")
# Exclusion: drop food and transport
ex <- ik_core(d, method = "exclusion", exclude = c("Food", "Transport"))
# Dallas Fed style: asymmetric trim (24% lower, 31% upper)
at <- ik_core(d, method = "asymmetric_trim")
# Compare all four on one chart
comp <- ik_compare(tm, wm, ex, at,
labels = c("Trimmed mean", "Weighted median",
"Ex food & transport", "Asymmetric trim"))
plot(comp)Measure how quickly inflation returns to its mean after a shock. High persistence means rate hikes take longer to bring inflation down.
d <- ik_sample_data("headline")
pers <- ik_persistence(d$inflation, method = "sum_ar")
pers
#> -- Inflation Persistence (Sum of AR Coefficients) --
#> * AR order: 4 (selected by BIC)
#> * Persistence value: 0.72
#> * Moderate persistence (sum of AR coefficients 0.5 to 0.8)
# Half-life: how many quarters until a shock decays by half?
pers_hl <- ik_persistence(d$inflation, method = "half_life")
pers_hl
#> -- Inflation Persistence (Half-Life) --
#> * Persistence value: 3.2 periodsEstimate the relationship between inflation and unemployment. A negative slope means higher unemployment is associated with lower inflation.
d <- ik_sample_data("headline")
pc <- ik_phillips(d$inflation, d$unemployment, type = "traditional", lags = 4)
pc
#> -- Phillips Curve (Traditional) --
#> * Slope estimate: -0.12 (p = 0.03)
#> * R-squared: 0.45
#> * Observations: 76
# Robust standard errors (Newey-West HAC)
pc_hac <- ik_phillips(d$inflation, d$unemployment,
type = "traditional", lags = 4, robust_se = "HAC")
plot(pc) # Scatter plot with fitted lineSeparate the permanent trend from transitory shocks using the Hodrick-Prescott filter or Beveridge-Nelson decomposition.
d <- ik_sample_data("headline")
hp <- ik_trend(d$inflation, method = "hp")
hp
#> -- Trend Inflation (Hodrick-Prescott) --
#> * Lambda: 1600
#> * Mean trend: 2.8
#> * Cycle volatility (SD): 0.5
plot(hp) # Original series with trend overlay
# Beveridge-Nelson decomposition (ARIMA-based)
bn <- ik_trend(d$inflation, method = "beveridge_nelson")
plot(bn)Test whether forecasts are unbiased (Mincer-Zarnowitz) or compare two competing forecasts (Diebold-Mariano).
actual <- c(2.1, 2.3, 2.5, 2.2, 2.8, 3.0, 2.7, 2.4)
forecast1 <- c(2.0, 2.2, 2.3, 2.1, 2.5, 2.8, 2.6, 2.3)
forecast2 <- c(1.8, 2.0, 2.6, 2.3, 2.4, 3.2, 2.5, 2.1)
# Bias test
bias <- ik_forecast_eval(actual, forecast1, test = "bias")
bias
#> -- Forecast Evaluation (Mincer-Zarnowitz Bias Test) --
#> * p-value: 0.42
#> * Cannot reject H0: no evidence of forecast bias.
# Diebold-Mariano: is forecast1 better than forecast2?
dm <- ik_forecast_eval(actual, forecast1, test = "dm", forecast2 = forecast2)
dm
#> -- Forecast Evaluation (Diebold-Mariano Test) --
#> * p-value: 0.08
#> * No significant difference in predictive accuracy.Most functions take a data frame with CPI components. Each row is one item in one period. The default column names are date, item, weight, and price_change:
| Column | What it is |
|---|---|
date |
Date of the observation (e.g. 2024-01-01) |
item |
Component name (e.g. "Food", "Housing", "Transport") |
weight |
CPI basket weight as a proportion (0.15 = 15%). Should sum to 1 within each date. If they do not, functions normalise them internally. |
price_change |
Period-on-period price change as a decimal (0.003 = 0.3% monthly inflation). Positive means prices are rising. |
If your data uses different column names, every function has date_col, item_col, weight_col, and change_col arguments so you can map them:
# Your data has columns: month, category, share, pct_change
ik_decompose(my_data,
date_col = "month", item_col = "category",
weight_col = "share", change_col = "pct_change")Some functions (ik_persistence, ik_phillips, ik_trend, ik_forecast_eval) take simple numeric vectors instead of a data frame.
The package includes sample datasets so you can try everything immediately:
library(inflationkit)
# Component-level data: 10 CPI items, 120 months
d <- ik_sample_data("components")
head(d)
#> date item weight price_change
#> 1 2015-01-01 Food 0.15 0.003218
#> 2 2015-01-01 Housing 0.25 0.004274
#> 3 2015-01-01 Transport 0.12 0.001893
# Headline data: monthly inflation + unemployment
h <- ik_sample_data("headline")
head(h)
#> date inflation unemployment
#> 1 2015-01-01 0.0025 0.055# 1. Install the data package (one time)
install.packages("ons")
# 2. Download CPI component series
library(ons)
cpi <- ons_cpi() # Returns monthly CPI index by component
# 3. Compute month-on-month price changes and reshape for inflationkit
library(inflationkit)
# Your data frame needs: date, item, weight, price_change
# See ons package documentation for component weights# 1. Install the data package (one time)
install.packages("fred")
# 2. Get a free API key from https://fred.stlouisfed.org/docs/api/api_key.html
library(fred)
fred_set_key("your_api_key_here")
# 3. Download CPI sub-indices
food <- fred_series("CPIFABSL") # Food
housing <- fred_series("CPIHOSSL") # Housing
transport <- fred_series("CPITRNSL") # Transportation
# 4. Compute month-on-month changes, assign weights, and stack into
# a data frame with columns: date, item, weight, price_change| Source | Coverage | How to get into R |
|---|---|---|
| ONS (UK CPI) | United Kingdom | ons |
| BLS (US CPI) | United States | fred |
| ECB (HICP) | Euro area | readecb |
| OECD | 38 countries | readoecd |
| World Bank | 200+ countries | WDI package |
| Statistics offices | Any country | Download CSV from national statistics website |
| Function | Description |
|---|---|
ik_decompose() |
Weighted contributions of CPI components to headline inflation |
ik_core() |
Core inflation (trimmed mean, weighted median, exclusion, asymmetric trim) |
ik_sticky_flexible() |
Sticky vs flexible price decomposition (Atlanta Fed methodology) |
ik_persistence() |
Inflation persistence (sum of AR coefficients, half-life, largest root) |
ik_diffusion() |
Diffusion index (fraction of items with rising prices) |
ik_phillips() |
Phillips curve estimation (traditional, expectations-augmented, hybrid) |
ik_breakeven() |
Breakeven inflation from nominal and real bond yields |
ik_trend() |
Trend extraction (HP filter, Beveridge-Nelson, exponential smoothing, moving average) |
ik_forecast_eval() |
Forecast evaluation (Mincer-Zarnowitz bias, Nordhaus efficiency, Diebold-Mariano) |
ik_compare() |
Compare multiple core inflation measures side by side |
ik_sample_data() |
Built-in sample CPI and macro data for examples |
All functions return S3 objects with print() and plot() methods.
The methods implemented in this package are based on:
- Bryan, M.F. & Cecchetti, S.G. (1994). "Measuring Core Inflation." In Monetary Policy, ed. N.G. Mankiw, University of Chicago Press, 195-219. (NBER Working Paper w4303)
- Bils, M. & Klenow, P.J. (2004). "Some Evidence on the Importance of Sticky Prices." Journal of Political Economy, 112(5), 947-985. doi:10.1086/422559
- Marques, C.R. (2004). "Inflation Persistence: Facts or Artefacts?" ECB Working Paper No. 371.
- Beveridge, S. & Nelson, C.R. (1981). "A New Approach to Decomposition of Economic Time Series." Journal of Monetary Economics, 7(2), 151-174.
- Diebold, F.X. & Mariano, R.S. (1995). "Comparing Predictive Accuracy." Journal of Business & Economic Statistics, 13(3), 253-263.
| Package | Description |
|---|---|
| inflateR | Adjust monetary values for inflation (simpler companion) |
| ons | UK Office for National Statistics data (CPI, RPI, GDP deflator) |
| fred | Federal Reserve Economic Data (includes US CPI) |
| readecb | European Central Bank data (includes HICP) |
| readoecd | OECD international price data |
| nowcast | Economic nowcasting (inflation nowcasts) |
| mpshock | Monetary policy shock series |
Found a bug or have a feature request? Open an issue at https://github.com/charlescoverdale/inflationkit/issues.
r, r-package, inflation, cpi, core-inflation, trimmed-mean, weighted-median, phillips-curve, macroeconomics, monetary-policy, price-index, beveridge-nelson, inflation-persistence