-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b157a58
Showing
50 changed files
with
5,839 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
^.*\.Rproj$ | ||
^\.Rproj\.user$ | ||
^data-raw$ | ||
^README\.Rmd$ | ||
^cran-comments\.md$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData | ||
.Ruserdata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Version: 1.0 | ||
|
||
RestoreWorkspace: Default | ||
SaveWorkspace: Default | ||
AlwaysSaveHistory: Default | ||
|
||
EnableCodeIndexing: Yes | ||
UseSpacesForTab: Yes | ||
NumSpacesForTab: 4 | ||
Encoding: UTF-8 | ||
|
||
RnwWeave: Sweave | ||
LaTeX: pdfLaTeX | ||
|
||
AutoAppendNewline: Yes | ||
StripTrailingWhitespace: Yes | ||
|
||
BuildType: Package | ||
PackageUseDevtools: Yes | ||
PackageCheckArgs: --as-cran | ||
PackageRoxygenize: rd,collate,namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Package: ARDL | ||
Type: Package | ||
Title: Autoregressive Distributed Lag Models, Error Correction Models and | ||
Bounds-Test for Cointegration | ||
Description: Creates complex Autoregressive Distributed Lag models providing | ||
just the order and automatically constructs the underlying unrestricted and | ||
restricted ECM. It also performs the bounds-test for cointegration and | ||
provides the multipliers and the cointegrating equation. | ||
Version: 0.1.0 | ||
Authors@R: c( | ||
person("Kleanthis", "Natsiopoulos", | ||
email = "klnatsio@gmail.com", role = c("aut", "cre", "dis"), | ||
comment = c(ORCID = "0000-0003-1180-2984")), | ||
person("Nickolaos", "Tzeremes", | ||
email = "bus9nt@econ.uth.gr", role = "ths", | ||
comment = c(ORCID = "0000-0002-6938-3404")), | ||
person("University of Thessaly, Department of Economics", role = "dgg")) | ||
License: GPL-3 | file LICENSE | ||
URL: https://github.com/Natsiopoulos | ||
Encoding: UTF-8 | ||
LazyData: true | ||
Depends: | ||
R (>= 3.2.0) | ||
Suggests: | ||
qpcR, | ||
xts | ||
Imports: | ||
aod, | ||
dplyr, | ||
dynlm, | ||
lmtest, | ||
msm, | ||
stringr, | ||
zoo | ||
RoxygenNote: 7.1.0 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
S3method(coint_eq,default) | ||
S3method(coint_eq,recm) | ||
S3method(multipliers,ardl) | ||
S3method(multipliers,uecm) | ||
S3method(uecm,ardl) | ||
S3method(uecm,default) | ||
export(ardl) | ||
export(auto_ardl) | ||
export(bounds_f_test) | ||
export(bounds_t_test) | ||
export(coint_eq) | ||
export(multipliers) | ||
export(recm) | ||
export(uecm) | ||
importFrom(dplyr,"%>%") | ||
importFrom(zoo,merge.zoo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# ARDL v0.1.0 (29 Mar 2020) | ||
|
||
## Released to CRAN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#' ARDL: ARDL, ECM and Bounds-Test for Cointegration | ||
"_PACKAGE" | ||
|
||
#' | ||
#' @keywords internal | ||
#' @docType package | ||
#' @name ARDL-package | ||
#' | ||
#' @importFrom dplyr %>% | ||
#' @importFrom zoo merge.zoo | ||
#' | ||
# no visible binding for global variable '.' (solution line) | ||
globalVariables(c(".")) | ||
|
||
.onAttach <- function(libname, pkgname) { | ||
local_version = paste("R package version", utils::packageVersion('ARDL')) | ||
year <- sub("-.*", "", utils::packageDate('ARDL')) | ||
packageStartupMessage('To cite ARDL in publications use: | ||
\nKleanthis Natsiopoulos and Nickolaos Tzeremes (', year, '). ARDL: ARDL, ECM and Bounds-Test for | ||
Cointegration. ', local_version,'. University of Thessaly, Department of Economics. https://github.com/Natsiopoulos.') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#' ARDL model regression | ||
#' | ||
#' A simple way to construct complex ARDL specifications prodiving just the | ||
#' model order additional to the model formula. It uses | ||
#' \code{\link[dynlm]{dynlm}} under the hood. | ||
#' | ||
#' The \code{formula} should contain only variables that exist in the data | ||
#' privided through \code{data} plus some additional functions supported by | ||
#' \code{\link[dynlm]{dynlm}} (i.e., \code{trend()}). | ||
#' | ||
#' You can also specify fixed variables that are not supposed to be lagged (e.g. | ||
#' dummies etc.) simply by placing them after \code{|}. For example, \code{y ~ | ||
#' x1 + x2 | z1 + z2} where \code{z1} and \code{z2} are the fixed variables and | ||
#' should not be considered in \code{order}. Note that the \code{|} notion | ||
#' should not be confused with the same notion in \code{dynlm} where it | ||
#' introduces instrumental variables. | ||
#' | ||
#' @param formula A "formula" describing the linear model. Details for model | ||
#' specification are given under 'Details'. | ||
#' @param data A time series object (e.g., "ts", "zoo" or "zooreg") or a data | ||
#' frame containing the variables in the model. In the case of a data frame, | ||
#' it is coerced into a \code{\link[stats]{ts}} object with \code{start = 1}, | ||
#' \code{end = nrow(data)} and \code{frequency = 1}. If not found in data, the | ||
#' variables are NOT taken from any environment. | ||
#' @param order A specification of the order of the ARDL model. A numeric vector | ||
#' of the same length as the total number of variables (excluding the fixed | ||
#' ones, see 'Details'). It should only contain positive integers or 0. An | ||
#' integer could be provided if all variables are of the same order. | ||
#' @param start Start of the time period which should be used for fitting the | ||
#' model. | ||
#' @param end End of the time period which should be used for fitting the model. | ||
#' @param ... Additional arguments to be passed to the low level regression | ||
#' fitting functions. | ||
#' | ||
#' @return \code{ardl} returns an object of \code{\link[base]{class}} | ||
#' \code{c("dynlm", "lm", "ardl")}. In addition, attributes 'order', 'data', | ||
#' 'parsed_formula' and 'full_formula' are provided. | ||
#' | ||
#' @seealso \code{\link{uecm}}, \code{\link{recm}} | ||
#' @author Kleanthis Natsiopoulos, \email{klnatsio@@gmail.com} | ||
#' @keywords models ts | ||
#' @export | ||
#' @examples | ||
#' data(denmark) | ||
#' | ||
#' ## Estimate an ARDL(3,1,3,2) model ------------------------------------- | ||
#' | ||
#' ardl_3132 <- ardl(LRM ~ LRY + IBO + IDE, data = denmark, order = c(3,1,3,2)) | ||
#' summary(ardl_3132) | ||
#' | ||
#' ## Add dummies or other variables that should stay fixed --------------- | ||
#' | ||
#' d_74Q1_75Q3 <- ifelse(time(denmark) >= 1974 & time(denmark) <= 1975.5, 1, 0) | ||
#' | ||
#' # the date can also be setted as below | ||
#' d_74Q1_75Q3_ <- ifelse(time(denmark) >= "1974 Q1" & time(denmark) <= "1975 Q3", 1, 0) | ||
#' identical(d_74Q1_75Q3, d_74Q1_75Q3_) | ||
#' den <- cbind(denmark, d_74Q1_75Q3) | ||
#' ardl_3132_d <- ardl(LRM ~ LRY + IBO + IDE | d_74Q1_75Q3, | ||
#' data = den, order = c(3,1,3,2)) | ||
#' summary(ardl_3132_d) | ||
#' compare <- data.frame(AIC = c(AIC(ardl_3132), AIC(ardl_3132_d)), | ||
#' BIC = c(BIC(ardl_3132), BIC(ardl_3132_d))) | ||
#' rownames(compare) <- c("no ummy", "with dummy") | ||
#' compare | ||
#' | ||
#' ## Estimate an ARDL(3,1,3,2) model with a linear trend ----------------- | ||
#' | ||
#' ardl_3132_tr <- ardl(LRM ~ LRY + IBO + IDE + trend(LRM), | ||
#' data = denmark, order = c(3,1,3,2)) | ||
#' | ||
#' # Alternative time trend specifications: | ||
#' # time(LRM) 1974 + (0, 1, ..., 55)/4 time(data) | ||
#' # trend(LRM) (1, 2, ..., 55)/4 (1:n)/freq | ||
#' # trend(LRM, scale = FALSE) (1, 2, ..., 55) 1:n | ||
#' | ||
#' ## Subsample ARDL regression (start after 1975 Q4) --------------------- | ||
#' | ||
#' ardl_3132_sub <- ardl(LRM ~ LRY + IBO + IDE, data = denmark, | ||
#' order = c(3,1,3,2), start = "1975 Q4") | ||
#' | ||
#' # the date can also be setted as below | ||
#' ardl_3132_sub2 <- ardl(LRM ~ LRY + IBO + IDE, data = denmark, | ||
#' order = c(3,1,3,2), start = c(1975,4)) | ||
#' identical(ardl_3132_sub, ardl_3132_sub2) | ||
#' summary(ardl_3132_sub) | ||
#' | ||
#' ## Ease of use --------------------------------------------------------- | ||
#' | ||
#' # The model specification of the ardl_3132 model can be created as easy as order=c(3,1,3,2) | ||
#' # or else, it could be done using the dynlm package as: | ||
#' library(dynlm) | ||
#' m <- dynlm(LRM ~ L(LRM, 1) + L(LRM, 2) + L(LRM, 3) + LRY + L(LRY, 1) + IBO + L(IBO, 1) + | ||
#' L(IBO, 2) + L(IBO, 3) + IDE + L(IDE, 1) + L(IDE, 2), data = denmark) | ||
#' identical(m$coefficients, ardl_3132$coefficients) | ||
#' | ||
#' # The full formula can be extracted from the ARDL model, and this is equal to | ||
#' ardl_3132$full_formula | ||
#' m2 <- dynlm(ardl_3132$full_formula, data = ardl_3132$data) | ||
#' identical(m$coefficients, m2$coefficients) | ||
|
||
ardl <- function(formula, data, order, start = NULL, end = NULL, ...) { | ||
if (!any(c("ts", "zoo", "zooreg") %in% class(data))) { | ||
data <- stats::ts(data, start = 1, end = nrow(data), frequency = 1) | ||
} | ||
|
||
parsed_formula <- parse_formula(formula = formula, colnames_data = colnames(data)) | ||
order <- parse_order(orders = order, order_name = "order", kz = parsed_formula$kz) | ||
ardl_formula <- build_ardl_formula(parsed_formula = parsed_formula, order = order) | ||
|
||
full_formula <- formula(ardl_formula$full) | ||
ardl_model <- dynlm::dynlm(full_formula, data = data, start = start, end = end, ...) | ||
# for model compatibility in the global env | ||
attr(ardl_model$terms, ".Environment") <- .GlobalEnv | ||
attr(attr(ardl_model$model, "terms"), ".Environment") <- .GlobalEnv | ||
attr(full_formula, ".Environment") <- .GlobalEnv | ||
|
||
ardl_model$order <- order | ||
ardl_model$data <- data | ||
ardl_model$parsed_formula <- parsed_formula | ||
ardl_model$full_formula <- full_formula | ||
|
||
attr(ardl_model, "class") <- c(class(ardl_model), "ardl") | ||
|
||
return(ardl_model) | ||
} |
Oops, something went wrong.