# NOT RUN {
set.seed(1)
eps <- rnorm(100)
spectral_entropy(eps)
phi.v <- seq(-0.95, 0.95, by = 0.1)
kMethods <- c("mvspec", "pgram")
SE <- matrix(NA, ncol = length(kMethods), nrow = length(phi.v))
for (ii in seq_along(phi.v)) {
xx.tmp <- arima.sim(n = 200, list(ar = phi.v[ii]))
for (mm in seq_along(kMethods)) {
SE[ii, mm] <- spectral_entropy(xx.tmp, spectrum.control =
list(method = kMethods[mm]))
}
}
matplot(phi.v, SE, type = "l", col = seq_along(kMethods))
legend("bottom", kMethods, lty = seq_along(kMethods),
col = seq_along(kMethods))
# AR vs MA
SE.arma <- matrix(NA, ncol = 2, nrow = length(phi.v))
SE.arma[, 1] <- SE[, 2]
for (ii in seq_along(phi.v)){
yy.temp <- arima.sim(n = 1000, list(ma = phi.v[ii]))
SE.arma[ii, 2] <-
spectral_entropy(yy.temp, spectrum.control = list(method = "mvspec"))
}
matplot(phi.v, SE.arma, type = "l", col = 1:2, xlab = "parameter (phi or theta)",
ylab = "Spectral entropy")
abline(v = 0, col = "blue", lty = 3)
legend("bottom", c("AR(1)", "MA(1)"), lty = 1:2, col = 1:2)
# }
Run the code above in your browser using DataLab