-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
a832ecc
commit ba0f58c
Showing
11 changed files
with
227 additions
and
9 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 |
---|---|---|
|
@@ -6,10 +6,15 @@ Authors@R: | |
family = "Karakas", | ||
role = c("aut", "cre"), | ||
email = "[email protected]") | ||
Description: Automating time series stationarity tests. This package automates Kwiatkowski–Phillips–Schmidt–Shin (KPSS), Augmented Dickey–Fuller (ADF) and Phillips–Perron (PP) unit root tests and saves the results as a dataframe. | ||
Description: Automating time series stationarity tests. This package automates Kwiatkowski–Phillips–Schmidt–Shin (KPSS), Augmented Dickey–Fuller (ADF) and Phillips–Perron (PP) unit root tests by calculating every possible situation for lag length, type and significance level (1%, 2.5%, 5% and 10%) and saves the results as a dataframe. | ||
Encoding: UTF-8 | ||
LazyData: true | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.1.1 | ||
Depends: R (>= 4.0.0), dplyr, urca | ||
Imports: dplyr,urca | ||
Language:en-US | ||
License: GPL-2 | ||
Suggests: | ||
testthat (>= 3.0.0) | ||
Config/testthat/edition: 3 |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(summary_stationarity) | ||
S3method(summary,adf) | ||
S3method(summary,all) | ||
S3method(summary,kpss) | ||
S3method(summary,pp) |
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,45 @@ | ||
#' @title ADF Test Results. | ||
#' | ||
#' @description | ||
#' This function computes ADF statistics and critical values and aggregate them in one dataframe for all possible situations. | ||
#' | ||
#' @param model fitted \code{lm(y ~ x)} object | ||
#' @param lag Integer lag length. For example, if the value is \code{10}, results will come for lag lengths of \code{1:10}. | ||
#' @export | ||
#' @examples | ||
#' summary.adf(ts_model,10) | ||
|
||
summary.adf <- function(model,lag) { | ||
|
||
if (lag>20) { | ||
stop("Lag can not be greater than 20.") | ||
} | ||
|
||
variables <-c(as.data.frame(model$model),as.data.frame(model$residuals)) %>% as.data.frame() | ||
|
||
adf_type <- c("none","drift","trend") | ||
adf = list() | ||
for (variable in names(variables)) { | ||
for (type in adf_type) { | ||
for (i in 1:10) { | ||
adf_new <- ur.df(variables[[variable]],type = type, lags = i) | ||
adf_result <- as.data.frame(cbind(Test="ADF",Type=type,Variable=variable,Lag=i,"Statistic"=adf_new@teststat[1],as.data.frame(adf_new@cval)[1,])) %>% | ||
mutate(Statistic=as.numeric(.data[["Statistic"]]), | ||
"1pct"=as.numeric(.data[["1pct"]]), | ||
"5pct"=as.numeric(.data[["5pct"]]), | ||
"10pct"=as.numeric(.data[["10pct"]])) | ||
row.names(adf_result) <- NULL | ||
adf_result <- adf_result %>% mutate("2.5pct"="Not avaiable for ADF") %>% relocate("2.5pct", .before = "10pct") | ||
adf_result["10% result"] <- ifelse(abs(adf_result[["Statistic"]])>abs(adf_result[["10pct"]]),"pass","fail") | ||
adf_result["5% result"] <- ifelse(abs(adf_result[["Statistic"]])>abs(adf_result[["5pct"]]),"pass","fail") | ||
adf_result["2.5% result"] <- "Not available for ADF" | ||
adf_result["1% result"] <- ifelse(abs(adf_result[["Statistic"]])>abs(adf_result[["1pct"]]),"pass","fail") | ||
adf[[paste0(i,type,variable)]] <- adf_result # add it to list | ||
} | ||
} | ||
} | ||
adf_full <- do.call(rbind, adf) | ||
row.names(adf_full) <- NULL | ||
return(adf_full) | ||
|
||
} |
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
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,45 @@ | ||
#' @title KPSS Test result. | ||
#' | ||
#' @description | ||
#' This function computes KPSS statistics and critical values and aggregate them in one dataframe for all possible situations. | ||
#' | ||
#' @param model fitted \code{lm(y ~ x)} object | ||
#' @param lag Integer lag length. For example, if the value is \code{10}, results will come for lag lengths of \code{1:10}. | ||
#' @export | ||
#' @examples | ||
#' summary.kpss(ts_model,10) | ||
|
||
summary.kpss <- function(model,lag) { | ||
|
||
if (lag>20) { | ||
stop("Lag can not be greater than 20.") | ||
} | ||
|
||
variables <-c(as.data.frame(model$model),as.data.frame(model$residuals)) %>% as.data.frame() | ||
|
||
kpss_type <-c("mu","tau") | ||
kpss = list() | ||
for (variable in names(variables)) { | ||
for (type in kpss_type) { | ||
for (i in 1:lag) { | ||
kpss_new <- ur.kpss(variables[[variable]],type = type, use.lag=i) | ||
kpss_result <- as.data.frame(cbind(Test="KPSS",Type=type,Variable=variable,Lag=i,"Statistic"=kpss_new@teststat[1],kpss_new@cval)) %>% | ||
mutate(Statistic=as.numeric(.data[["Statistic"]]), | ||
"1pct"=as.numeric(.data[["1pct"]]), | ||
"5pct"=as.numeric(.data[["5pct"]]), | ||
"10pct"=as.numeric(.data[["10pct"]])) | ||
row.names(kpss_result) <- NULL | ||
kpss_result[["Type"]] <- ifelse(kpss_result[["Type"]]=="mu","constant","trend") | ||
kpss_result["10% result"] <- ifelse(kpss_result[["Statistic"]]<kpss_result[["10pct"]],"pass","fail") | ||
kpss_result["5% result"] <- ifelse(kpss_result[["Statistic"]]<kpss_result[["5pct"]],"pass","fail") | ||
kpss_result["2.5% result"] <- ifelse(kpss_result[["Statistic"]]<kpss_result[["2.5pct"]],"pass","fail") | ||
kpss_result["1% result"] <- ifelse(kpss_result[["Statistic"]]<kpss_result[["1pct"]],"pass","fail") | ||
kpss[[paste0(i,type,variable)]] <- kpss_result # add it to list | ||
} | ||
} | ||
} | ||
kpss_full <- do.call(rbind, kpss) | ||
row.names(kpss_full) <- NULL | ||
return(kpss_full) | ||
|
||
} |
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,46 @@ | ||
#' @title PP Test Results. | ||
#' | ||
#' @description | ||
#' This function computes PP statistics and critical values and aggregate them in one dataframe for all possible situations. | ||
#' | ||
#' @param model fitted \code{lm(y ~ x)} object | ||
#' @param lag Integer lag length. For example, if the value is \code{10}, results will come for lag lengths of \code{1:10}. | ||
#' @export | ||
#' @examples | ||
#' summary.pp(ts_model,10) | ||
|
||
summary.pp <- function(model,lag) { | ||
|
||
if (lag>20) { | ||
stop("Lag can not be greater than 20.") | ||
} | ||
|
||
variables <-c(as.data.frame(model$model),as.data.frame(model$residuals)) %>% as.data.frame() | ||
|
||
pp_type <- c("constant","trend") | ||
pp = list() | ||
for (variable in names(variables)) { | ||
for (type in pp_type) { | ||
for (i in 1:10) { | ||
pp_new <- ur.pp(variables[[variable]],type = c("Z-tau"), model=type, use.lag=i) | ||
pp_result <- as.data.frame(cbind(Test="PP",Type=type,Variable=variable,Lag=i,"Statistic" = pp_new@teststat,pp_new@cval)) %>% | ||
mutate(Statistic=as.numeric(.data[["Statistic"]]), | ||
"1pct"=as.numeric(.data[["1pct"]]), | ||
"5pct"=as.numeric(.data[["5pct"]]), | ||
"10pct"=as.numeric(.data[["10pct"]])) | ||
row.names(pp_result) <- NULL | ||
pp_result <- pp_result %>% mutate("2.5pct"="Not avaiable for PP") %>% relocate("2.5pct", .before = "10pct") | ||
pp_result["10% result"] <- ifelse(abs(pp_result[["Statistic"]])>abs(pp_result[["10pct"]]),"pass","fail") | ||
pp_result["5% result"] <- ifelse(abs(pp_result[["Statistic"]])>abs(pp_result[["5pct"]]),"pass","fail") | ||
pp_result["2.5% result"] <- "Not available for PP" | ||
pp_result["1% result"] <- ifelse(abs(pp_result[["Statistic"]])>abs(pp_result[["1pct"]]),"pass","fail") | ||
pp[[paste0(i,type,variable)]] <- pp_result # add it to list | ||
} | ||
} | ||
} | ||
pp_full <- do.call(rbind, pp) | ||
row.names(pp_full) <- NULL | ||
|
||
return(pp_full) | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,17 @@ | ||
Version: 1.0 | ||
|
||
RestoreWorkspace: Default | ||
SaveWorkspace: Default | ||
AlwaysSaveHistory: Default | ||
|
||
EnableCodeIndexing: Yes | ||
UseSpacesForTab: Yes | ||
NumSpacesForTab: 2 | ||
Encoding: UTF-8 | ||
|
||
RnwWeave: Sweave | ||
LaTeX: pdfLaTeX | ||
|
||
BuildType: Package | ||
PackageUseDevtools: Yes | ||
PackageInstallArgs: --no-multiarch --with-keep.source |