Hello everyone,
I try to build a loop with the ccf function, but unfortunately, I don't get very far. I have an Excel file ( external_data_train ) with 156 obs. of 50 variables. I would like to test the cross-correlation of each variable with the data set window$demand for 20 lags. I am therefore looking for a table output with lags in the header and each row for each variable. A nice add on would be a plot for each variable as well.
So far I used the following, but I it's not working at all:
k <- ncol(external_data_train)
ccf_mat <- matrix(0, nrow=37 , ncol= k)
for(i in 1:k) {
ccf_mat[,i] <- ccf(external_data_train[,i], window$demand)
}
instead of
ccfvalues1 = ccf(external_data_train$F1,window$demand, 20)
ccfvalues2 = ccf(external_data_train$F2,window$demand, 20)
ccfvalues3 = ccf(external_data_train$F3,window$demand, 20)
ccfvalues4 = ccf(external_data_train$F4,window$demand, 20)
ccfvalues5 = ccf(external_data_train$F5,window$demand, 20)
ccfvalues6 = ccf(external_data_train$F6,window$demand, 20)
ccfvalues7 = ccf(external_data_train$F7,window$demand, 20)
ccfvalues8 = ccf(external_data_train$F8,window$demand, 20)
ccfvalues9 = ccf(external_data_train$F9,window$demand, 20)
Thanks for your help!
Luke