if (FALSE) {
####################################################
### Standard Nonparametric Vector Autoregression ###
####################################################
set.seed(123)
x <- rnorm(100) ; y <- rnorm(100) ; z <- rnorm(100)
A <- cbind(x = x, y = y, z = z)
### Using lags 1:4 for each variable
NNS.VAR(A, h = 12, tau = 4, status = TRUE)
### Using lag 1 for variable 1, lag 3 for variable 2 and lag 3 for variable 3
NNS.VAR(A, h = 12, tau = c(1,3,3), status = TRUE)
### Using lags c(1,2,3) for variables 1 and 3, while using lags c(4,5,6) for variable 2
NNS.VAR(A, h = 12, tau = list(c(1,2,3), c(4,5,6), c(1,2,3)), status = TRUE)
### PREDICTION INTERVALS
# Store NNS.VAR output
nns_estimate <- NNS.VAR(A, h = 12, tau = 4, status = TRUE)
# Create bootstrap replicates using NNS.meboot
replicates <- NNS.meboot(nns_estimate$ensemble[,1], rho = seq(-1,1,.25))["replicates",]
replicates <- do.call(cbind, replicates)
# Apply UPM.VaR and LPM.VaR for desired prediction interval...95 percent illustrated
# Tail percentage used in first argument per {LPM.VaR} and {UPM.VaR} functions
lower_CIs <- apply(replicates, 1, function(z) LPM.VaR(0.025, 0, z))
upper_CIs <- apply(replicates, 1, function(z) UPM.VaR(0.025, 0, z))
# View results
cbind(nns_estimate$ensemble[,1], lower_CIs, upper_CIs)
#########################################
### NOWCASTING with Mixed Frequencies ###
#########################################
library(Quandl)
econ_variables <- Quandl(c("FRED/GDPC1", "FRED/UNRATE", "FRED/CPIAUCSL"),type = 'ts',
order = "asc", collapse = "monthly", start_date = "2000-01-01")
### Note the missing values that need to be imputed
head(econ_variables)
tail(econ_variables)
NNS.VAR(econ_variables, h = 12, tau = 12, status = TRUE)
}
Run the code above in your browser using DataLab