R/elliot.rothenberg.stock.test.R

#' @title Elliot-Rothenberg-Stock (ERS) Stationarity Test
#'
#' @description
#' Elliot-Rothenberg-Stock stationarity test.
#' 
#' @param data Time series data
#' @param alpha Value of alpha for the statistics test
#' 
#' @return 0: Non-Stationary, 1: Stationary, NA: Unable to test
#' 
#' @importFrom urca ur.ers
#' 
elliot.rothenberg.stock.test <- function(data, alpha){
  p <- NULL
  tryCatch(p <- ur.ers(data, type="DF-GLS", model="constant"),
      error=function(e){return(NA)})
  
  if(!is.null(p)){
    if(!is.null(p@teststat) && !is.na(p@teststat)){
      if(p@teststat <= p@cval[2]){
        return(STATIONARY)
      } else {
        return(NONSTATIONARY)
      }
    }
  }
  return(NA)
}
gnardin/stationarity documentation built on May 17, 2019, 7:29 a.m.