| Title: | Johansen Cointegration Test with Fourier-Type Smooth Nonlinear Trends |
|---|---|
| Description: | Implements the Johansen cointegration test with Fourier-type smooth nonlinear deterministic trends restricted to cointegrating relations, as developed by Kurita and Shintani (2025) <doi:10.1080/07474938.2025.2530640>. Six model variants are supported: CNR (constant plus nonlinear, restricted in the cointegrating space), LNR (linear plus nonlinear, restricted), CNU (constant restricted, nonlinear unrestricted), LNU (linear restricted, nonlinear unrestricted), plus the standard constant- and linear-trend restricted Johansen models. The package also bundles the feasible generalised least squares (FGLS) Wald test of Perron, Shintani and Yabu (2017) <doi:10.1111/obes.12169> used as a frequency-selection pre-step, together with bundled critical-value tables, a vectorised simulator for the limiting distribution, publication-quality table exports (LaTeX and HTML) and 'ggplot2' figures matching those of the paper. |
| Authors: | Merwan Roudane [aut, cre] |
| Maintainer: | Merwan Roudane <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-06-02 18:56:42 UTC |
| Source: | https://github.com/cran/fjohansen |
Implements the Johansen cointegration test with Fourier-type smooth nonlinear deterministic trends restricted to cointegrating relations, as developed by Kurita and Shintani (2025, Econometric Reviews). Also bundles the FGLS Wald test of Perron, Shintani and Yabu (2017) as a frequency-selection pre-step.
johansen_fourier – the trace test.
select_frequencies – pick the number of Fourier
frequencies via PSY 2021.
psy_wald_test – the univariate Wald test.
simulate_limit_distribution – limit distribution
of Proposition 3.1 of the paper.
| Author: | Merwan Roudane [email protected] |
| Repository: | https://github.com/merwanroudane/fjohansen |
| License: | MIT |
Maintainer: Merwan Roudane [email protected]
Kurita, T. and Shintani, M. (2025). Johansen test with Fourier-type smooth nonlinear trends in cointegrating relations. Econometric Reviews, 44(10), 1589-1616. doi:10.1080/07474938.2025.2530640
Perron, P., Shintani, M. and Yabu, T. (2017). Testing for flexible nonlinear trends with an integrated or stationary noise component. Oxford Bulletin of Economics and Statistics, 79, 822-850. doi:10.1111/obes.12169
Useful links:
Report bugs at https://github.com/merwanroudane/fjohansen/issues
Build Z0, Z1, Z2 design matrices for the reduced-rank regression
build_design_matrices(X, k, n, model = "CNR")build_design_matrices(X, k, n, model = "CNR")
X |
T x p numeric matrix (levels). |
k |
VAR order in levels (>= 1). |
n |
Number of Fourier frequencies (0 disables them). |
model |
One of "CNR","LNR","CNU","LNU","constant","linear". |
A list with elements Z0, Z1, Z2, info.
Clear the in-memory simulation cache.
clear_jf_cache()clear_jf_cache()
Invisible integer = number of cached entries cleared.
Named-list keyed by string "p_minus_r,n". Values are numeric vectors with names
q90, q95, q975, q99, mean, var.
CNR_TABLE_B1CNR_TABLE_B1
An object of class list of length 35.
Constructs the matrix
for t = t_start, ..., t_start + T - 1.
fourier_basis(T_len, n, t_start = 1)fourier_basis(T_len, n, t_start = 1)
T_len |
Sample size used in the denominator (typically the full sample T). |
n |
Number of frequencies (>= 0). 0 returns a matrix with 0 columns. |
t_start |
First time index (default 1). |
A numeric matrix of shape T_len x (2 n).
Data-generating processes from Section 5 of Kurita & Shintani (2025)
generate_nf_dgp1(T = 400L, seed = 0L, ...) generate_nf_dgp2(T = 400L, seed = 0L, ...) generate_nf_dgp3(T = 400L, seed = 0L, ...) generate_nf_dgp4(T = 400L, seed = 0L, ...) generate_f_dgp1(T = 400L, seed = 0L) generate_f_dgp2(T = 400L, seed = 0L)generate_nf_dgp1(T = 400L, seed = 0L, ...) generate_nf_dgp2(T = 400L, seed = 0L, ...) generate_nf_dgp3(T = 400L, seed = 0L, ...) generate_nf_dgp4(T = 400L, seed = 0L, ...) generate_f_dgp1(T = 400L, seed = 0L) generate_f_dgp2(T = 400L, seed = 0L)
T |
Sample length. |
seed |
RNG seed (integer). |
... |
Additional arguments forwarded to the internal skeleton
(e.g. |
A data.frame with two or four numeric columns.
Mean and variance of the limit distribution
jf_moments( p_minus_r, n, model = "CNR", n_sims = 4000, grid_size = 250, seed = 12345 )jf_moments( p_minus_r, n, model = "CNR", n_sims = 4000, grid_size = 250, seed = 12345 )
p_minus_r |
Common stochastic trends p - r (>= 1). |
n |
Number of Fourier frequencies (>= 0). |
model |
One of "CNR","LNR","CNU","LNU","CONSTANT","LINEAR". |
n_sims |
Replications used if the cell is not tabulated. |
grid_size |
Discretisation of the unit interval (only used in simulation). |
seed |
RNG seed (only used in simulation). |
Numeric vector of length 2: c(mean, var).
Gamma-approximation p-value of an observed trace statistic
jf_p_value(stat, p_minus_r, n, model = "CNR", ...)jf_p_value(stat, p_minus_r, n, model = "CNR", ...)
stat |
Observed value of -2 log LR. |
p_minus_r |
Common stochastic trends p - r (>= 1). |
n |
Number of Fourier frequencies (>= 0). |
model |
One of "CNR","LNR","CNU","LNU","CONSTANT","LINEAR". |
... |
Additional arguments forwarded to |
Numeric scalar in [0,1].
For tabulated CNR cells and the 90/95/97.5/99 percentiles the paper's hard-coded values are returned. Otherwise the Gamma approximation (Doornik 1998) is used.
jf_quantile(level, p_minus_r, n, model = "CNR", ...)jf_quantile(level, p_minus_r, n, model = "CNR", ...)
level |
Probability (0 < level < 1) or one of "90%","95%","97.5%","99%". |
p_minus_r |
Common stochastic trends p - r (>= 1). |
n |
Number of Fourier frequencies (>= 0). |
model |
One of "CNR","LNR","CNU","LNU","CONSTANT","LINEAR". |
... |
Additional arguments forwarded to |
Numeric scalar.
Helpers that turn a fitted johansen_fourier result into a printable
table in three different formats.
format_trace_table(x) format_trace_latex(x, caption = NULL, label = NULL) format_trace_html(x, caption = NULL)format_trace_table(x) format_trace_latex(x, caption = NULL, label = NULL) format_trace_html(x, caption = NULL)
x |
A |
caption |
Optional caption. |
label |
Optional label. |
Each function returns a single character scalar containing the formatted table:
format_trace_table() – plain-text (ASCII) table suitable
for cat() or message().
format_trace_latex() – a LaTeX tabular environment
(booktabs style) wrapped in a table float.
format_trace_html() – a self-contained HTML fragment
with inline CSS, suitable for use in R Markdown / Quarto.
Performs the reduced-rank regression of Kurita & Shintani (2025) for a cointegrated VAR(k) with restricted Fourier-type smooth nonlinear trends in the cointegrating space.
johansen_fourier( data, k, n = 1L, model = "CNR", sig_level = 0.05, select_rank = TRUE, n_sims = 5000L )johansen_fourier( data, k, n = 1L, model = "CNR", sig_level = 0.05, select_rank = TRUE, n_sims = 5000L )
data |
T x p numeric matrix or data.frame of levels. |
k |
VAR order in levels (>= 1). Uses |
n |
Number of Fourier frequencies (0 = standard Johansen). |
model |
One of |
sig_level |
Significance level for the sequential rank rule. |
select_rank |
Logical; sequentially pick the cointegrating rank. |
n_sims |
Replications used to simulate cells not in the bundled tables. |
An S3 object of class johansen_fourier with fields:
spec – model spec
eigenvalues – generalised eigenvalues, descending
trace_stats – data.frame, one row per H_0
selected_rank – chosen r
alpha, beta, delta, gamma_const, gamma_trend, Gamma
Sigma, residuals, fitted_long_run
series_names, t_index
Kurita, T., Shintani, M. (2025). Econometric Reviews, 44(10), 1589-1616.
## Small fast example (tabulated critical-value cell, no simulation): set.seed(1) data <- sample_jgb_data(T = 60) res <- johansen_fourier(data, k = 2, n = 1, model = "CNR", n_sims = 200, select_rank = FALSE) print(res) ## Full paper-style call (slower because of the limit-distribution ## simulation when the requested cell is not in the bundled tables): data <- sample_jgb_data(T = 108) res <- johansen_fourier(data, k = 3, n = 3, model = "CNR") summary(res) plot(res)## Small fast example (tabulated critical-value cell, no simulation): set.seed(1) data <- sample_jgb_data(T = 60) res <- johansen_fourier(data, k = 2, n = 1, model = "CNR", n_sims = 200, select_rank = FALSE) print(res) ## Full paper-style call (slower because of the limit-distribution ## simulation when the requested cell is not in the bundled tables): data <- sample_jgb_data(T = 108) res <- johansen_fourier(data, k = 3, n = 3, model = "CNR") summary(res) plot(res)
johansen_fourier
A list of S3-tagged model specs with the following fields:
code : canonical name
label : human-readable description
z1_constant : restricted constant in cointegrating space
z1_trend : restricted linear trend in cointegrating space
z1_fourier : restricted Fourier in cointegrating space
z2_constant : unrestricted constant
z2_fourier : unrestricted Fourier
model_specsmodel_specs
An object of class list of length 6.
Use one of "CNR", "LNR", "CNU", "LNU", "constant", "linear".
Bar plot of the Johansen eigenvalues
plot_eigenvalues(x)plot_eigenvalues(x)
x |
A |
A ggplot bar-chart object.
Plot the limit-distribution density (paper's Figs. 1-2)
plot_limit_density( p_minus_r, n_values = 0:4, model = "CNR", n_sims = 4000L, grid_size = 300L, title = NULL )plot_limit_density( p_minus_r, n_values = 0:4, model = "CNR", n_sims = 4000L, grid_size = 300L, title = NULL )
p_minus_r |
Number of common stochastic trends (>= 1). |
n_values |
Integer vector of n values to compare. |
model |
One of "CNR","LNR","CNU","LNU","CONSTANT","LINEAR". |
n_sims |
Number of Monte-Carlo replications. |
grid_size |
Grid size of |
title |
Optional plot title. |
A ggplot object showing one kernel-density curve per
value of n.
## Fast preview with reduced Monte-Carlo size: plot_limit_density(p_minus_r = 2, n_values = 0:2, n_sims = 400, grid_size = 80)## Fast preview with reduced Monte-Carlo size: plot_limit_density(p_minus_r = 2, n_values = 0:2, n_sims = 400, grid_size = 80)
Plot estimated cointegrating relations
plot_long_run(x)plot_long_run(x)
x |
A |
A ggplot object showing one panel per cointegrating
relation (the fitted beta' X_t series).
Returns a ggplot showing standardised residuals only (a single panel per equation). Use directly with patchwork::wrap_plots to combine with other diagnostic graphics.
plot_residual_diagnostics(x, max_lag = 14L)plot_residual_diagnostics(x, max_lag = 14L)
x |
A |
max_lag |
Number of ACF lags to show. |
A ggplot object with one panel of standardised residuals
per equation and +/- 2 reference bands.
Plot a (T x p) data set as multi-panel time series (Fig. 11 of the paper)
plot_series(data, title = NULL, index = NULL)plot_series(data, title = NULL, index = NULL)
data |
data.frame or matrix. |
title |
Optional title. |
index |
Optional vector of x-axis values. |
A ggplot object (one facet per series). Can be further
modified with + like any other ggplot.
df <- sample_jgb_data(T = 36) p <- plot_series(df, title = "JGB yields")df <- sample_jgb_data(T = 36) p <- plot_series(df, title = "JGB yields")
Tests for the presence of Fourier-type nonlinear components in a
univariate series. Robust to both and noise via
Prais-Winsten transformation with a super-efficient + Roy-Fuller
bias-corrected AR(1) estimator.
psy_wald_test( y, k_freqs, p_d = 1, subset_freq = NULL, version = "upper-biased", p_T_max = NULL )psy_wald_test( y, k_freqs, p_d = 1, subset_freq = NULL, version = "upper-biased", p_T_max = NULL )
y |
Numeric vector (length T). |
k_freqs |
Integer vector of frequencies. |
p_d |
Polynomial trend order (0 or 1). |
subset_freq |
If supplied, test only that one frequency's two coefficients. |
version |
"upper-biased" or "median-unbiased". |
p_T_max |
Upper bound for the augmentation lag. |
An object of class psy_wald.
Synthetic JGB-yield surrogate (Section 6 illustration)
sample_jgb_data(T = 108L, seed = 7L)sample_jgb_data(T = 108L, seed = 7L)
T |
Sample length (default 108, matching the paper's monthly sample). |
seed |
RNG seed. |
A data.frame with six columns (i_20yr, i_10yr, i_5yr, i_3yr, i_1yr, i_call) and a Date attribute starting 1986-12.
Each column is tested independently and the final n is the maximum
across columns – the same recipe as in Kurita & Shintani (2025).
select_frequencies( data, n_max = 5L, p_d = 1L, sig_level = 0.1, version = "upper-biased" )select_frequencies( data, n_max = 5L, p_d = 1L, sig_level = 0.1, version = "upper-biased" )
data |
Numeric matrix or data.frame. |
n_max |
Upper bound on the number of frequencies. |
p_d |
Polynomial trend order. |
sig_level |
Significance level for stopping the loop. |
version |
"upper-biased" or "median-unbiased". |
A freq_selection object.
General-to-specific frequency selection for a univariate series
select_frequencies_univariate( y, n_max = 5L, p_d = 1L, sig_level = 0.1, version = "upper-biased" )select_frequencies_univariate( y, n_max = 5L, p_d = 1L, sig_level = 0.1, version = "upper-biased" )
y |
Numeric vector. |
n_max |
Upper bound on the number of frequencies. |
p_d |
Polynomial trend order. |
sig_level |
Significance level for stopping the loop. |
version |
"upper-biased" or "median-unbiased". |
A freq_selection object.
Apply the paper-style ggplot2 theme (sunny palette)
set_paper_theme()set_paper_theme()
Invisibly returns the ggplot2 theme object that has been
installed as the global default via ggplot2::theme_set().
Called primarily for its side effect.
Vectorised across replications. Results are kept in a per-session in-memory
cache; clear it with clear_jf_cache().
simulate_limit_distribution( p_minus_r, n, model = "CNR", n_sims = 5000, grid_size = 300, seed = 12345 )simulate_limit_distribution( p_minus_r, n, model = "CNR", n_sims = 5000, grid_size = 300, seed = 12345 )
p_minus_r |
Number of common stochastic trends (>= 1). |
n |
Number of Fourier frequencies (>= 0). |
model |
One of "CNR","LNR","CNU","LNU","CONSTANT","LINEAR". |
n_sims |
Number of Monte-Carlo replications. |
grid_size |
Grid size of |
seed |
RNG seed. |
Numeric vector of length n_sims.
Simulate moments of the limiting distribution
simulate_limit_moments( p_minus_r, n, model = "CNR", n_sims = 5000, grid_size = 300, seed = 12345 )simulate_limit_moments( p_minus_r, n, model = "CNR", n_sims = 5000, grid_size = 300, seed = 12345 )
p_minus_r |
Number of common stochastic trends (>= 1). |
n |
Number of Fourier frequencies (>= 0). |
model |
One of "CNR","LNR","CNU","LNU","CONSTANT","LINEAR". |
n_sims |
Number of Monte-Carlo replications. |
grid_size |
Grid size of |
seed |
RNG seed. |
List with elements mean, var, draws.