wbnicholson / BigVAR

Dimension Reduction Methods for Multivariate Time Series
56 stars 17 forks source link

last model fit by cv.BigVAR? #3

Closed bdemeshev closed 7 years ago

bdemeshev commented 7 years ago

First, thank you for the package! :)

Why the functions cv.BigVAR and BigVAR.est give different estimates of beta for the same lambda? Or am I missing something with the training sample?

library(BigVAR)

data(Y)
y_st <- apply(Y, 2, FUN = scale)

model_spec <- constructModel(y_st, p = 6, 
                             struct = "OwnOther", 
                             ownlambdas = TRUE,
                             gran = 10, 
                             verbose = TRUE, 
                             VARX = list())

model_cv <- cv.BigVAR(model_spec)
model_est <- BigVAR.est(model_spec)

b11_est <- model_est$B[1, 1, 1]
b11_cv <- model_cv@betaPred[1, 1]

b11_est
b11_cv
wbnicholson commented 7 years ago

I looked into this issue. There is no difference in the data across the two scenarios. However, in cv.BigVAR the most recent coefficient matrix for beta as well as the most recent "active set" is used as an initialization whereas in BigVAR.est it starts from a coefficient matrix of zeros. If you remove the initialization by adding the code:

beta <- array(0,dim=c(k,p*k+1,1)) activeset <- rep(list(rep(rep(list(0), length(kk)))), gran2) before line 877 in BigVARSupportFunctions.R, both functions will return identical results.

As another potential alternative, reducing the optimization tolerance (currently .0001) would decrease this discrepancy.

bdemeshev commented 7 years ago

That's perfect! I think I will close the issue and open a new one in some minutes ;)