[R] Granger-causality test using vars package

T.Riedle tr206 at kent.ac.uk
Mon Jan 23 13:25:33 CET 2017


Thank you for your reply. The code follows the example in the vignette and I changed it only a little as shown below.

library(vars)
data(Canada)
summary(Canada)
stat.desc(Canada,basic=FALSE)
plot(Canada, nc=2, xlab="")

# Testing for unit roots using ADF
adf1<-adf.test(Canada[,"prod"])
adf1
adf2<-adf.test(Canada[,"e"])
adf2
adf3<-adf.test(Canada[,"U"])
adf3
adf4<-adf.test(Canada[,"rw"])
adf4

# Use VAR to create a list of class varest
Canada<-Canada[, c("prod", "e", "U", "rw")]
p1ct<-VAR(Canada, p=1, type = "both")
p1ct
summary(p1ct, equation="e")
plot(p1ct, names = "e")

#Run Granger-causality test
causality(p1ct)

The Granger-causality test returns following output
$Granger

	Granger causality H0: prod do not Granger-cause e U rw

data:  VAR object p1ct
F-Test = 11.956, df1 = 3, df2 = 308, p-value = 1.998e-07


$Instant

	H0: No instantaneous causality between: prod and e U rw

data:  VAR object p1ct
Chi-squared = 3.7351, df = 3, p-value = 0.2915


Warning message:
In causality(p1ct) : 
Argument 'cause' has not been specified;
using first variable in 'x$y' (prod) as cause variable.

I am struggling with the result as it is not clear to me whether the variable prod Granger-causes e or U or rw. H0 is that prod does not Granger-cause e U rw. What does that mean? How can I find out if prod Granger-causes e, U and rw, respectively i.e. how can I determine that prod Granger-causes e, U and rw?

Thanks for your support in advance.
________________________________________
From: Pfaff, Bernhard Dr. <Bernhard_Pfaff at fra.invesco.com>
Sent: 23 January 2017 09:12
To: T.Riedle; R-help at r-project.org
Subject: AW:  [R] Granger-causality test using vars package

Dear T.Riedle,

you cannot assign *all* variables as a cause at once. Incidentally, in your example, you missed a 'data(Canada)'.
Having said this, you can loop over the variables names and extract the statistic/p-values. These are contained as named list elements 'statistic' and 'p.value' in the returned list object 'Granger' which is of informal class 'htest'.

Best wishes,
Bernhard

-----Ursprüngliche Nachricht-----
Von: R-help [mailto:r-help-bounces at r-project.org] Im Auftrag von T.Riedle
Gesendet: Sonntag, 22. Januar 2017 14:11
An: R-help at r-project.org
Betreff: [EXT] [R] Granger-causality test using vars package

Dear R-users,

I am trying to compute the test statistics for Granger-causality for a VAR(p) model using the "vars" package. I simply used the example proposed by the vars vignette and added the code for the Granger-causality. The code looks as follows



library(vars)

Canada<-Canada[, c("prod", "e", "U", "rw")] p1ct<-VAR(Canada, p=1, type = "both")

causality(p1ct, cause = c("prod","e","U","rw"))



Unfortunately I get the error

Error in `[<-`(`*tmp*`, i, w[i], value = 1) : subscript out of bounds



Does any body know what is wrong with the code? I would like to create a matrix containing the F-values and the corresponding significance. How can I do that?

        [[alternative HTML version deleted]]

______________________________________________
R-help at 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.
*****************************************************************
Confidentiality Note: The information contained in this ...{{dropped:11}}



More information about the R-help mailing list