Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
karakastarik committed Aug 25, 2021
1 parent d3c469e commit b79e259
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 34 deletions.
22 changes: 17 additions & 5 deletions R/assert.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
#Assert function
assert <- function(model,lag) {
#Assert lag
assert_lag <- function(lag) {
if (lag>20 || typeof(lag) != "double") {
stop("Lag value can not be greater than 20 and it must be integer.")
stop("lag value can not be greater than 20 and it must be integer.")
}

}

#Assert model
assert_model <- function(model) {
if (as.character(model$call[[1]])!="lm") {
stop("model must be lm(y ~ x) object.")
}
}
}

#Assert difference
assert_difference <- function(difference) {
if (typeof(difference) != "double" || difference < 1) {
stop("difference value must be integer and greater than 1.")
}
}


7 changes: 7 additions & 0 deletions R/df_diff.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#Take difference of the model data

df_diff <- function(model,diff_value){
df <-data.frame(diff(as.matrix(model$model),differences = diff_value))
print(paste0("Unit root tests results prepared for difference: ",diff_value))
return(df)
}
13 changes: 8 additions & 5 deletions R/summary-adf.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
#' @examples
#' summary_adf(ts_model,10)

summary_adf <- function(model,lag) {
summary_adf <- function(model,lag=5,difference=NA) {

if (lag>20) {
stop("Lag can not be greater than 20.")
}
assert_lag(lag)
assert_model(model)

variables <-c(as.data.frame(model$model),as.data.frame(model$residuals)) %>% as.data.frame()
if (!is.na(difference)) {
variables <- df_diff(model,difference)
} else {
variables <-c(as.data.frame(model$model),as.data.frame(model$residuals)) %>% as.data.frame()
}

adf_type <- c("none","drift","trend")
adf = list()
Expand Down
13 changes: 9 additions & 4 deletions R/summary-all.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
#' @examples
#' summary_all(ts_model,10)

summary_all <- function(model,lag) {
summary_all <- function(model,lag,difference=NA) {

if (lag>20) {
stop("Lag can not be greater than 20.")
assert_lag(lag)
assert_model(model)

if (!is.na(difference)) {
variables <- df_diff(model,difference)
} else {
variables <-c(as.data.frame(model$model),as.data.frame(model$residuals)) %>% as.data.frame()
}

kpss_type <-c("mu","tau")
variables <-c(as.data.frame(model$model),as.data.frame(model$residuals)) %>% as.data.frame()

#loop for kpss
kpss = list()
Expand Down
19 changes: 8 additions & 11 deletions R/summary-kpss.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#' @title KPSS Test result.
#'
#' @description
Expand All @@ -10,18 +9,16 @@
#' @examples
#' summary_kpss(ts_model,10)

summary_kpss <- function(model,lag) {
summary_kpss <- function(model,lag=5,difference=NA) {

# if (lag>20 || typeof(lag) != "double") {
# stop("Lag value can not be greater than 20 and it must be integer.")
# }
#
# if (as.character(model$call[[1]])!="lm") {
# stop("model must be lm(y ~ x) object.")
# }
assert(model,lag)
assert_lag(lag)
assert_model(model)

variables <-c(as.data.frame(model$model),as.data.frame(model$residuals)) %>% as.data.frame()
if (!is.na(difference)) {
variables <- df_diff(model,difference)
} else {
variables <-c(as.data.frame(model$model),as.data.frame(model$residuals)) %>% as.data.frame()
}

kpss_type <-c("mu","tau")
kpss = list()
Expand Down
13 changes: 8 additions & 5 deletions R/summary-pp.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
#' @examples
#' summary_pp(ts_model,10)

summary_pp <- function(model,lag) {
summary_pp <- function(model,lag=5,difference=NA) {

if (lag>20) {
stop("Lag can not be greater than 20.")
}
assert_lag(lag)
assert_model(model)

variables <-c(as.data.frame(model$model),as.data.frame(model$residuals)) %>% as.data.frame()
if (!is.na(difference)) {
variables <- df_diff(model,difference)
} else {
variables <-c(as.data.frame(model$model),as.data.frame(model$residuals)) %>% as.data.frame()
}

pp_type <- c("constant","trend")
pp = list()
Expand Down
2 changes: 1 addition & 1 deletion man/summary_adf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/summary_all.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/summary_kpss.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/summary_pp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b79e259

Please sign in to comment.