mboeck11 / BGVAR

Toolbox for the estimation of Bayesian Global Vector Autoregressions in R.
27 stars 20 forks source link

Error including exogenous variables #7

Closed danfer21 closed 2 years ago

danfer21 commented 2 years ago

When we include a list or matrix of exogenous variables, we get the following error:

[1] "Error in cbind(X, Exraw) : object 'X' not found\n" attr(,"class") [1] "try-error" attr(,"condition") <simpleError in cbind(X, Exraw): object 'X' not found> Error in .BVAR_linear_wrapper(cc = cc, cN = cN, xglobal = xglobal, gW = gW, :

It seems the error comes from the function .BVAR_linear_R, at the line: if (texo) Xraw <- cbind(X, Exraw)

because X has not been defined before. So we need a definition for X.

mboeck11 commented 2 years ago

Can you please provide an example code with the testdata set and some artifically data in Ex to reproduce the error?

Then I am happy to look into this.

danfer21 commented 2 years ago

Sure, here it goes:

tempEx = as.matrix(eerData$US[,'poil']) colnames(tempEx) = "EA.poil" model.1<-bgvar(Data=eerData, W=W.trade0012, Ex=tempEx, draws=100, burnin=100, plag=1, prior="NG", hyperpara=NULL, SV=TRUE, thin=1, trend=TRUE, hold.out=0, eigen=1 )

Thank you

mboeck11 commented 2 years ago

Hi,

thanks for spotting the bug. I've fixed and the new version is on GitHub. We just updated the package to version 2.4.3, thus it will be included in the next package version on CRAN which will only be updated in a few months.

library(BGVAR)
set.seed(123)

data(eerData)

# as matrix
tempEx = as.matrix(eerData$US[,'poil'])
colnames(tempEx) = "EA.poil"

model.1<-bgvar(Data=eerData,
               W=W.trade0012,
               Ex=tempEx,
               draws=200,
               burnin=200,
               plag=1,
               prior="NG",
               hyperpara=NULL,
               SV=TRUE,
               thin=1,
               trend=TRUE,
               hold.out=0,
               eigen=TRUE
)

# as list
tempEx <- list(tempEx); names(tempEx)<-c("EA")
colnames(tempEx$EA)<-"poil"

model.1<-bgvar(Data=eerData,
               W=W.trade0012,
               Ex=tempEx,
               draws=200,
               burnin=200,
               plag=1,
               prior="NG",
               hyperpara=NULL,
               SV=TRUE,
               thin=1,
               trend=TRUE,
               hold.out=0,
               eigen=TRUE
)

Please note that I've adjusted the eigen argument from being equal to one to TRUE (this implies a value of 1.05).

Hope this works for you now!

danfer21 commented 2 years ago

Thanks a lot for the quick resolution!

However, I see that when hold.out > 0 it stills throws an error:

cbind(Xraw, Exraw): the number of rows of both matrices must be equal

mboeck11 commented 2 years ago

Oh thank you for spotting this! The devil is in the details :-) should be fixed now!

danfer21 commented 2 years ago

It works!. Thank you very much