I had no problem using svar () I think you should try the code examples in the var package PDF by the authors, the research has since been quoted successfully
------------ Amit Mittal PhD in Finance and Accounting (tbd) IIM Lucknow http://ssrn.com/author=2665511 *Top 10%, downloaded author since July 2017 ------------ Sent from my Outlook for Android https://aka.ms/ghei36 ________________________________ From: R-help <r-help-boun...@r-project.org> on behalf of John <miao...@gmail.com> Sent: Wednesday, October 24, 2018 6:25:17 AM To: William Dunlap Cc: r-help; bernh...@pfaffikus.de Subject: Re: [R] SVAR: error message If it is an A model, then should I just set B = NULL or skip the entry B? William Dunlap <wdun...@tibco.com> $B1w(B 2018$BG/(B10$B7n(B24$BF|(B $B=5;0(B $B>e8a(B4:14$BUmF;!'(B > 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. [[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.