R/kolmogorov.smirnov.test.R

#' @title Kolmogorov-Smirnov stability algorithm
#'
#' @description
#' Procedure to test for time series stability described using the
#' Kolmorov-Smirnov test
#' 
#' @param data Time series data
#' @param alpha Value of alpha for the statistics test
#' 
#' @return 0: Non-Stationary, 1: Stationary
#' 
#' @importFrom stats ks.test
#' 
kolmogorov.smirnov.test <- function(data, alpha) {
  center <- as.integer(length(data) / 2)
  x1 <- data[1:center]
  x2 <- data[(center + 1):length(data)]
  
  test <- ks.test(x1, x2)
  
  decision <- ifelse(test$p.value > alpha, STATIONARY, NONSTATIONARY)
  
  return(decision)
}
gnardin/stationarity documentation built on May 17, 2019, 7:29 a.m.