### extend basic example in "urca" ###
library("urca")
library("vars")
data("denmark")
sjd = denmark[, c("LRM", "LRY", "IBO", "IDE")]
# use the single lag-order p=2 to determine only the break period #
R.vars = VAR(sjd, type="both", p=1, season=4)
R.speci = speci.VAR(R.vars, lag_set=2, dim_m=1, trim=3, add_dummy=FALSE)
library("ggfortify")
autoplot(ts(R.speci$df[3:5], start=1+R.speci$args_speci$trim),
main="For a single 'p', all IC just reflect the variation of det(UU').")
print(R.speci)
# perform cointegration test procedure with detrending #
R.t_D = list(t_shift=8, n.season=4)
R.coint = coint.SL(sjd, dim_p=2, type_SL="SL_trend", t_D=R.t_D)
summary(R.coint)
# m=1: line plot #
library("ggplot2")
R.speci1 = speci.VAR(R.vars, lag_set=1:5, dim_m=1, trim=6)
R.values = c("#BDD7E7", "#6BAED6", "#3182BD", "#08519C", "#08306B")
F.line = ggplot(R.speci1$df) +
geom_line( aes(x=tau_1, y=HQC, color=as.factor(p), group=as.factor(p))) +
geom_point(aes(x=tau_1, y=HQC, color=as.factor(p), group=as.factor(p))) +
geom_point(x=R.speci1$selection["tau_1", "HQC"],
y=min(R.speci1$df$HQC), color="red") +
scale_x_continuous(limits=c(1, nrow(sjd))) +
scale_color_manual(values=R.values) +
labs(x=expression(tau), y="HQ Criterion", color="Lag order", title=NULL) +
theme_bw()
plot(F.line)
# m=2: discrete heat map #
R.speci2 = speci.VAR(R.vars, lag_set=2, dim_m=2, trim=3)
dim_T = nrow(sjd) # total sample size
F.heat = ggplot(R.speci2$df) +
geom_point(aes(x=tau_1, y=tau_2, color=AIC), size=3) +
geom_abline(intercept=0, slope=-1, color="grey") +
scale_x_continuous(limits=c(1, dim_T), expand=c(0, 0)) +
scale_y_reverse(limits=c(dim_T, 1), expand=c(0, 0)) +
scale_color_continuous(type="viridis") +
labs(x=expression(tau[1]), y=expression(tau[2]), color="AIC", title=NULL) +
theme_bw()
plot(F.heat)
Run the code above in your browser using DataLab