The immediate problem is in svartype=="AB-model" part of SVAR: pos <- which(is.na(rb)) cols <- length(pos) Rb <- matrix(0, nrow = Ksq, ncol = cols) for (i in 1:cols) Rb[pos[i], i] <- 1
Your Bmat has no NA's, so cols is 0. Then 1:cols is c(1,0), causing an error in the for loop when it tries to reference column 1 of a 0-column matrix. The code should use seq_len(cols) instead of 1:cols (or give an error telling the user that Bmat should contain some NA's). This is the sort of question one should send to the maintainer of the package that SVAR is in: > maintainer("vars") [1] "Bernhard Pfaff <bernh...@pfaffikus.de>" Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Oct 22, 2018 at 8:15 PM, John <miao...@gmail.com> wrote: > Hi, > > I have a bi-variate VAR model and would like to convert it to SVAR but > get an error message. Could someone pinpoint anything wrong and correct my > code? Thanks, > > John > > > amat <- matrix(c(NA, 0, NA, NA), nrow = 2, ncol = 2, byrow = TRUE) > df1<-data.frame(x=c(1,4,5,6,7,8,9,3,5,3), y=c(4,7,1,2,3,9,3,4,5,7)) > var1<-VAR(df1, type = "const", ic="BIC") > svar2<-SVAR(x = var1, estmethod = "scoring", Amat = amat, Bmat = diag(2), > max.iter = 100, conv.crit = 0.1e-6, maxls = 1000) > > > amat <- matrix(c(NA, 0, NA, NA), nrow = 2, ncol = 2, byrow = TRUE) > > df1<-data.frame(x=c(1,4,5,6,7,8,9,3,5,3), y=c(4,7,1,2,3,9,3,4,5,7)) > > var1<-VAR(df1, type = "const", ic="BIC") > > svar2<-SVAR(x = var1, estmethod = "scoring", Amat = amat, Bmat = diag(2), > + max.iter = 100, conv.crit = 0.1e-6, maxls = 1000) > Error in `[<-`(`*tmp*`, pos[i], i, value = 1) : subscript out of bounds > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/ > posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.