<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 In this notebook we will show how to perform a Granger Causality analysis, and demonstrate how poorly it performs on our simulated data.
Step1:  Now compute Granger causality across all pairs of timeseries
<ASSISTANT_TASK:>
Python Code:
import os,sys
import numpy
%matplotlib inline
import matplotlib.pyplot as plt
import statsmodels.tsa.stattools
from dcm_sim import sim_dcm_dataset
sys.path.insert(0,'../')
from utils.graph_utils import show_graph_from_adjmtx,show_graph_from_pattern
# first we simulate some data using our DCM model, with the same HRF across all regions
_,data_conv,params=sim_dcm_dataset(verbose=True)
A=params['A']
B=params['B']
C=params['C']
data=data_conv[range(0,data_conv.shape[0],int(1./params['stepsize']))]
Explanation: In this notebook we will show how to perform a Granger Causality analysis, and demonstrate how poorly it performs on our simulated data.
End of explanation
gc=numpy.zeros(A.shape)
for i in range(A.shape[0]):
    for j in range(A.shape[0]):
        if i==j:  # don't compute self-connectivity
            continue
        result=statsmodels.tsa.stattools.grangercausalitytests(data[:,[i,j]],1)
        if result[1][0]['params_ftest'][1]<0.05:
            gc[i,j]=1
        
show_graph_from_adjmtx(gc,numpy.zeros(B.shape),numpy.zeros(C.shape),title='Granger')
show_graph_from_adjmtx(A,B,C,title='True model')
Explanation: Now compute Granger causality across all pairs of timeseries
End of explanation
<END_TASK>