R/PcdiffSingleUnitRoot.R

Defines functions pcdiff.piar1unit

Documented in pcdiff.piar1unit

#' @title Periodically differenced data when there is a single unit root in original data
#' @description  Periodically differenced data when there is a single unit root in original data
#' @param pcts the original time series (assumed there is a single unit root)
#' @param parameters the parameters of first order differencing filter $(1-\alpha_sL)$
#' @param d period
#' @details The function provides the (periodic) stationary data. The original data is with
#' a single unit root, and after imposing the filter $(1-\alpha_sL)$, the perioically differenced
#' data can be derived.
#' @return Periodically differenced data
#' @export
#'
#' @examples
#' library(pcts)
#' library(mcompanion)
#' set.seed(123)
#' F <- sim_mc(dim = 4, mo = 4, mo.col = 1, eigval = c(1), len.block = c(1))
#' phi <- new("MultiFilter", mc =  mCompanion(F$mat, mo = 4, mo.col = 1))
#' pc.sim <- sim_pc(model = list(phi = phi[], p = 1, period = 4), n = 500)
#' icoef <- piar1unit(Xsim = F$eigvec, d = 4, eigval = 1)
#' pcdiff.pc.sim <- pcdiff.piar1unit(pcts = pc.sim, parameters = icoef, d=4)

pcdiff.piar1unit <- function(pcts, parameters, d) {
  YT <- matrix(c(pcts), nrow = d)
  YTmin1 <- cbind(rep(0, d), YT[, 1:(ncol(YT) - 1)])
  Theta0 <- matrix(0, nrow = d, ncol = d)
  diag(Theta0) <- c(rep(1, d))
  Theta0.sub <- Theta0[2:(d), 1:(d - 1)]
  diag(Theta0.sub) <- c(-parameters$alpha[2:d])
  e1 <- c(1, rep(0, (d - 2)))
  ed <- c(rep(0, (d - 2)), 1)
  Theta0 <- rbind(cbind(t(e1), 0), cbind(Theta0.sub, ed))
  Theta1 <- matrix(0, nrow = d, ncol = d)
  Theta1[1, d] <- parameters$alpha[1]
  pcdiff <- Theta0 %*% YT - Theta1 %*% YTmin1
  return(pcdiff)
}
YueyunZhu/UnitRootsofPIAR documentation built on Feb. 13, 2020, 12:32 a.m.