SVAR: error message

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

SVAR: error message

miao
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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: SVAR: error message

R help mailing list-2
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 <[hidden email]>"



Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, Oct 22, 2018 at 8:15 PM, John <[hidden email]> 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]]
>
> ______________________________________________
> [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: SVAR: error message

miao
If it is an A model, then should I just set B = NULL or skip the entry B?
William Dunlap <[hidden email]> 於 2018年10月24日 週三 上午4:14寫道:

> 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 <[hidden email]>"
>
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> On Mon, Oct 22, 2018 at 8:15 PM, John <[hidden email]> 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]]
>>
>> ______________________________________________
>> [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: SVAR: error message

prof.amit.mittal
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 <[hidden email]> on behalf of John <[hidden email]>
Sent: Wednesday, October 24, 2018 6:25:17 AM
To: William Dunlap
Cc: r-help; [hidden email]
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 <[hidden email]> $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 <[hidden email]>"
>
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> On Mon, Oct 22, 2018 at 8:15 PM, John <[hidden email]> 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]]
>>
>> ______________________________________________
>> [hidden email] 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]]

______________________________________________
[hidden email] 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]]

______________________________________________
[hidden email] 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.