R/phillips.perron.test.R

#' @title Phillips-Perron (PP) Stationarity Test
#'
#' @description
#' Phillips-Perron 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 tseries pp.test
#' 
phillips.perron.test <- function(data, alpha){
  p <- NULL
  tryCatch(p <- pp.test(data, alternative="stationary")$p.value,
      error=function(e){return(NA)})
  
  if(!is.null(p) && !is.na(p)){
    if(p <= alpha){
      return(STATIONARY)
    } else {
      return(NONSTATIONARY)
    }
  }
  return(NA)
}
gnardin/stationarity documentation built on May 17, 2019, 7:29 a.m.