library("mvLSW")
P <- 3 ## Number of channels
T <- 1024 ## Time series length
J <- log2(T) ## Number of levels
Spec <- array(0, dim = c(P, P, J, T))
Spec[1, 1, 2, ] <- seq(from = 4, to = 20, length = T)
Spec[2, 2, 2, ] <- 6
Spec[3, 3, 2, ] <- seq(from = 20, to = 6, length = T)
Spec[1, 2, 2, ] <- Spec[2, 1, 2, ] <- seq(from = 2, to = 10, len = T)
Spec[1, 3, 2, ] <- Spec[3, 1, 2, ] <- seq(from = 2, to = 10, len = T)
Spec[2, 3, 2, ] <- Spec[3, 2, 2, ] <- seq(from = 1, to = 5, len = T)
True_mvEWS <- as.mvLSW(x = Spec, filter.number = 1, family = "DaubExPhase",
names = c("X1", "X2", "X3"))
plot(True_mvEWS, style = 2, info = 2, ylim = c(0, 20), lwd = 2)
suppressWarnings(RNGversion("3.5.0"))
set.seed(1)
X <- rmvLSW(Spectrum = True_mvEWS, noiseFN = rnorm)
plot(x = X, main = "Gaussian mvLSW time series")
EWS <- mvEWS(X = X, filter.number = 1, family = "DaubExPhase",
kernel.name = "daniell", kernel.param = sqrt(T), bias.correct = TRUE,
tol = 1e-10)
summary(EWS)
RHO <- coherence(object = EWS, partial = FALSE)
GAMMA <- coherence(object = EWS, partial = TRUE)
plot(x = RHO, style = 2, info = 2, diag = FALSE, ylim = c(-1, 1), lwd = 2,
ylab = "Coherence")
plot(x = GAMMA, style = 2, info = 2, diag = FALSE, ylim = c(-1, 1), lwd = 2,
ylab = "P. Coh.")
HaarACWIP <- AutoCorrIP(J = J, filter.number = 1, family = "DaubExPhase")
VAR <- varEWS(object = EWS, ACWIP = HaarACWIP)
CI <- ApxCI(object = EWS, var = VAR, alpha = 0.05)
plot(x = EWS, style = 2, info = 2, Interval = CI)
Bsamp <- array(NA, dim = c(P, P, J, T, 100))
for (b in seq_len(100)) {
X_boot <- rmvLSW(Spectrum = EWS, noiseFN = rnorm)
EWS_boot <- mvEWS(X = X_boot, filter.number = 1, family = "DaubExPhase",
kernel.name = "daniell", kernel.param = sqrt(T), bias.correct = TRUE)
Bsamp[, , , , b] <- EWS_boot$spectrum
}
Bl <- as.mvLSW(x = apply(Bsamp, 1:4, quantile, prob = 0.025))
Bm <- as.mvLSW(x = apply(Bsamp, 1:4, quantile, prob = 0.5))
Bu <- as.mvLSW(x = apply(Bsamp, 1:4, quantile, prob = 0.975))
BInt <- list(L = Bl, U = Bu)
plot(Bm, style = 2, info = 2, Interval = BInt, lwd = 2)
data("EuStockMarkets", package = "datasets")
T <- 1024
J <- log2(T)
N <- nrow(EuStockMarkets)
EU.lret <- diff(log(EuStockMarkets))
EU.lret <- window(EU.lret, start = c(1994, 186))
plot(x = EU.lret, main = "EU Log Returns", nc = 2)
EU.EWS <- mvEWS(X = EU.lret, family = "DaubExPhase", filter.number = 7,
kernel.name = "daniell", kernel.param = sqrt(T), bias.correct = TRUE)
ACWIP_FN7 <- AutoCorrIP(J = J, family = "DaubExPhase", filter.number = 7)
EU.VAR <- varEWS(object = EU.EWS, ACWIP = ACWIP_FN7)
EU.CI <- ApxCI(object = EU.EWS, var = EU.VAR, alpha = 0.05)
EU.R <- coherence(object = EU.EWS)
EU.G <- coherence(object = EU.EWS, partial = TRUE)
plot(x = EU.EWS, style = 2, info = 1, Interval = EU.CI)
plot(x = EU.EWS, style = 2, info = 2, Interval = EU.CI)
lim <- c(-1, 1)
lab1 <- "Coherence"
lab2 <- "P. Coh."
plot(x = EU.R, style = 2, info = 1, diag = F, ylim = lim, ylab = lab1)
plot(x = EU.R, style = 2, info = 2, diag = F, ylim = lim, ylab = lab1)
plot(x = EU.G, style = 2, info = 1, diag = F, ylim = lim, ylab = lab2)
plot(x = EU.G, style = 2, info = 2, diag = F, ylim = lim, ylab = lab2)