r - Rolling Granger Causality -


i using msbvar package in r calculate granger causality between 2 variables. data , commands same used in package:

data(israelpalestineconflict) granger.test(israelpalestineconflict, p=6) 

it gives following results:

              f-statistic  p-value p2i -> i2p    17.63100     0.000000e+00 i2p -> p2i    10.91235     7.134737e-12 

i want apply loop/rollapply function , want save results in file. tried after watching past answers on rollapply new r don't know how make work.

rollapply(zoo(israelpalestineconflict),width=1275,           fun = function(t)            { t = granger.test(israelpalestineconflict, p=6);            },           by.column=false, align="right") 

but gives same results first column replaced years , dont know how can save results of f-statistics , p-values rollapply.

             f-statistic  p-value 2003.8077    17.63100     0.000000e+00 2003.8269    10.91235     7.134737e-12 

kind answer requested, please.

perhaps want this:

granger.test.c <- function(x) c(granger.test(x, p = 6)) rollapplyr(israelpalestineconflict, 1275, granger.test.c, by.column = false ) 

this creates list of above p = 2, 3, 4, 5:

granger.test.c <- function(x, p) c(granger.test(x, p = p)) p <- 2:5 roll <- function(p, df) rollapplyr(df, 1275, granger.test.c, by.column = false, p = p ) l <- lapply(p, roll, df = israelpalestineconflict) names(l) <- p 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -