R/ADCV.R

Defines functions ADCV

Documented in ADCV

ADCV <- function(x, MaxLag = 15, unbiased = FALSE) {

  n <- length(x)
  if ( is.matrix(x) ) {
    if ( dim(x)[2] > 1 ) {
     stop( "Univariate time series only." )
    } else  x <- x[, 1]
  }
  if ( !is.numeric(x) )  stop( "'x' must be numeric." )
  if ( !all( is.finite(x) ) )  stop( "Missing or infitive values." )
  if ( ( MaxLag < 0 )  |  ( MaxLag > n - 1 ) )  stop( "'MaxLag' must be in the range of 0 and (n-1)." )
  if ( ( unbiased )  &&  ( n < 3 ) )  stop( "Sample size must be larger than 3." )

  adcv <- matrix(0, 1, MaxLag + 1, dimnames = list("  ", paste("lag", 0:MaxLag) ) )

  if ( unbiased ) {
    for ( k in seq(0, MaxLag, by = 1 ) ) {
      xA <- x[ 1:(n - k) ]
      xB <- x[ (1 + k):n ]
      adcv[, (k + 1)] <- dcov::dcov2d(xA, xB, type = "U")
    }
  } else {
    for ( k in seq(0, MaxLag, by = 1 ) ) {
      xA <- x[ 1:(n - k) ]
      xB <- x[ (1 + k):n ]
      adcv[, (k + 1)] <- dcov::dcov2d(xA, xB)
    }
    adcv <- sqrt(adcv)
  }

  return(adcv)
}








# ADCV <- function(x,MaxLag=15,unbiased=FALSE){
#     n <- length(x)
#     if (is.matrix(x)) {
#         if (!NCOL(x) == 1)
#             stop("Univariate time series only")
#     }
#     else {
#         x <- c(x)
#     }
#     if (!is.numeric(x))
#         stop("'x' must be numeric")
#     if (!all(is.finite(x)))
#         stop("Missing or infitive values")
#     if((MaxLag<0) | (MaxLag>(n-1)))stop("'MaxLag' must be in the range of 0 and (n-1)")
#     if ((unbiased==TRUE) && (n<3))stop("Sample size must be larger than 3")
#     adcv <- matrix(0, 1,MaxLag+1,dimnames=list("  ",paste("lag",0:MaxLag)))
#     for (k in seq(0,MaxLag,by=1)){
#      xA <- x[1:(n-k)]
#      xB <- x[(1+k):n]
#      if (unbiased) {
#       adcv[,(k+1)] <- round(dcovU(xA,xB),4)
#      }
#      else {
#       adcv[,(k+1)] <- round(dcov(xA,xB),4)
#      }
#      }
#     return(adcv)
# }


  #

Try the dCovTS package in your browser

Any scripts or data that you put into this service are public.

dCovTS documentation built on Sept. 29, 2023, 1:06 a.m.