# NOT RUN {
data(denmark)
## Find the best ARDL order --------------------------------------------
# Up to 5 for the autoregressive order (p) and 4 for the rest (q1, q2, q3)
# Using the defaults search_type = "vertical", grid = FALSE and selection = "AIC"
# ("Not run" indications only for testing purposes)
# }
# NOT RUN {
model1 <- auto_ardl(LRM ~ LRY + IBO + IDE, data = denmark,
max_order = c(5,4,4,4))
model1$top_orders
## Same, with search_type = "horizontal" -------------------------------
model1_h <- auto_ardl(LRM ~ LRY + IBO + IDE, data = denmark,
max_order = c(5,4,4,4), search_type = "horizontal")
model1_h$top_orders
## Find the global optimum ARDL order ----------------------------------
# It may take more than 10 seconds
model_grid <- auto_ardl(LRM ~ LRY + IBO + IDE, data = denmark,
max_order = c(5,4,4,4), grid = TRUE)
## Different selection criteria ----------------------------------------
# Using BIC as selection criterion instead of AIC
model1_b <- auto_ardl(LRM ~ LRY + IBO + IDE, data = denmark,
max_order = c(5,4,4,4), selection = "BIC")
model1_b$top_orders
# Using other criteria like adjusted R squared (the bigger the better)
adjr2 <- function(x) { summary(x)$adj.r.squared }
model1_adjr2 <- auto_ardl(LRM ~ LRY + IBO + IDE, data = denmark,
max_order = c(5,4,4,4), selection = "adjr2",
selection_minmax = "max")
model1_adjr2$top_orders
# Using functions from other packages as selection criteria
if (requireNamespace("qpcR", quietly = TRUE)) {
library(qpcR)
model1_aicc <- auto_ardl(LRM ~ LRY + IBO + IDE, data = denmark,
max_order = c(5,4,4,4), selection = "AICc")
model1_aicc$top_orders
adjr2 <- function(x){ Rsq.ad(x) }
model1_adjr2 <- auto_ardl(LRM ~ LRY + IBO + IDE, data = denmark,
max_order = c(5,4,4,4), selection = "adjr2",
selection_minmax = "max")
model1_adjr2$top_orders
## DIfferent starting order --------------------------------------------
# The searching algorithm will start from the following starting orders:
# p q1 q2 q3
# 1 1 3 2
# 2 1 3 2
# 3 1 3 2
# 4 1 3 2
# 5 1 3 2
model1_so <- auto_ardl(LRM ~ LRY + IBO + IDE, data = denmark,
max_order = c(5,4,4,4), starting_order = c(1,1,3,2))
# Starting from p=3 (don't search for p=1 and p=2)
# Starting orders:
# p q1 q2 q3
# 3 1 3 2
# 4 1 3 2
# 5 1 3 2
model1_so_3 <- auto_ardl(LRM ~ LRY + IBO + IDE, data = denmark,
max_order = c(5,4,4,4), starting_order = c(3,1,3,2))
# If starting_order = NULL, the starting orders for each iteration will be:
# p q1 q2 q3
# 1 1 1 1
# 2 2 2 2
# 3 3 3 3
# 4 4 4 4
# 5 5 5 5
}
## Add constraints -----------------------------------------------------
# Restrict only the order of IBO to be 2
model1_ibo2 <- auto_ardl(LRM ~ LRY + IBO + IDE, data = denmark,
max_order = c(5,4,4,4), fixed_order = c(-1,-1,2,-1))
model1_ibo2$top_orders
# Restrict the order of LRM to be 3 and the order of IBO to be 2
model1_lrm3_ibo2 <- auto_ardl(LRM ~ LRY + IBO + IDE, data = denmark,
max_order = c(5,4,4,4), fixed_order = c(3,-1,2,-1))
model1_lrm3_ibo2$top_orders
## Set the starting date for the regression (data starts at "1974 Q1") -
# Set regression starting date to "1976 Q1"
model1_76q1 <- auto_ardl(LRM ~ LRY + IBO + IDE, data = denmark,
max_order = c(5,4,4,4), start = "1976 Q1")
start(model1_76q1$best_model)
# }
Run the code above in your browser using DataLab