-----Urspr?ngliche Nachricht-----
Von: ivan [mailto:i.petzev at gmail.com]
Gesendet: Freitag, 15. April 2011 10:46
An: Pfaff, Bernhard Dr.
Cc: r-help at r-project.org
Betreff: Re: [R] Automatically extract info from Granger
causality output
Dear Bernhard,
thank you very much for the response. Yes, I am using the
packsges "vars" with fuchrions VAR() and causality().
1)Giving colnames to the objects does unfortunately not
change anything.
2) I am not sure if I understood you right. Did you mean to
insert Countml$Granger$p.value rather than
Count$ml$Granger$p.value? This
returns: Error: Object 'Countms' not found.
By the way, str(Count) produces the following:
List of 4
$ ml:List of 2
..$ Granger:List of 5
.. ..$ statistic: num [1, 1] 0.277
.. .. ..- attr(*, "names")= chr "F-Test"
.. ..$ parameter: Named num [1:2] 1 122
.. .. ..- attr(*, "names")= chr [1:2] "df1" "df2"
.. ..$ p.value : num [1, 1] 0.6
.. ..$ method : chr "Granger causality H0: y1 do not
Granger-cause x"
.. ..$ data.name: chr "VAR object x"
.. ..- attr(*, "class")= chr "htest"
..$ Instant:List of 5
.. ..$ statistic: num [1, 1] 19.7
.. .. ..- attr(*, "names")= chr "Chi-squared"
.. ..$ parameter: Named int 1
.. .. ..- attr(*, "names")= chr "df"
.. ..$ p.value : num [1, 1] 8.86e-06
.. ..$ method : chr "H0: No instantaneous causality
between: y1 and x"
.. ..$ data.name: chr "VAR object x"
.. ..- attr(*, "class")= chr "htest"
$ jp:List of 2
.
.
.
.
Best Regards,
Ivan
On Fri, Apr 15, 2011 at 10:13 AM, Pfaff, Bernhard Dr.
<Bernhard_Pfaff at fra.invesco.com> wrote:
Dear Ivan,
first, it would pay-off in terms of readability to employ
line breaks and second to provide a reproducable code snippet
and third which package you have used. Now to your questions:
1) What happens if you provide colnames for your objects?
2) What happens if you omit the $ after count?
Best,
Bernhard
ps: the function seems to have been ported from the package
'vars'. In this package the function causality() is included
which returns a named list with elements of class htest.
-----Urspr?ngliche Nachricht-----
Von: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] Im Auftrag von ivan
Gesendet: Donnerstag, 14. April 2011 19:37
An: r-help at r-project.org
Betreff: [R] Automatically extract info from Granger
Dear Community,
this is my first programming in R and I am stuck with a problem. I
have the following code which automatically calculates Granger
causalities from a variable, say e.g. "bs"
as below, to all other variables in the data frame:
log.returns<-as.data.frame( lapply(daten, function(x)
diff(log(ts(x))))) y1<-log.returns$bs
y2<- log.returns[,!(names(log.returns) %in% "bs")]
Granger<- function(y1,y2) {models=lapply(y2, function(x)
VAR(cbind(x,y1),ic="SC") ); results=lapply(models,function(x)
causality(x,cause="y1")); print(results)}
Count<-Granger(y1,y2)
which produces the following output (I have printed only
(for Granger causality of bs on ml)):
$ml
$ml$Granger
? ? ? ? Granger causality H0: y1 do not Granger-cause x
data: ?VAR object x
F-Test = 0.2772, df1 = 1, df2 = 122, p-value = 0.5995
$ml$Instant
? ? ? ? H0: No instantaneous causality between: y1 and x
data: ?VAR object x
Chi-squared = 19.7429, df = 1, p-value = 8.859e-06
My questions:
1)How can I edit the function above so that the output writes:
Granger causality H0: bs do not Granger-cause ml ? rather than ?
Granger causality H0: y1 do not Granger-cause x?
2) I want to extract the p-values of the tests into a data
instance. The problem is that the output has a 3 layer structure.
Thus, for the above p-value I need to write
count$ml$Granger$p.value.
I thought of a loop of something like for(i in
1:length(count)) {z=count$[[i]]$Granger$p.value} but it
Thank you very much for your help.
Best Regards.