Dear Numpy/Scipy experts,
                                              Attached is a script which I made 
to test the numpy.correlate ( which is called py plt.xcorr) to see how the 
cross correlation is calculated. From this it appears the if i call 
plt.xcorr(x,y)
Y is slided back in time compared to x. ie if y is a process that causes a 
delayed response in x after 5 timesteps then there should be a high correlation 
at Lag 5. However in attached plot the response is seen in only -ve side of the 
lags.
Can any one advice me on how to see which way exactly the 2 series are slided 
back or forth.? and understand the cause result relation better?( I understand 
merely by correlation one cannot assume cause and result relation, but it is 
important to know which series is older in time at a given lag.


with best regards,
Sudheer   
 
***************************************************************
Sudheer Joseph 
Indian National Centre for Ocean Information Services
Ministry of Earth Sciences, Govt. of India
POST BOX NO: 21, IDA Jeedeemetla P.O.
Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),
Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
E-mail:sjo.in...@gmail.com;sudheer.jos...@yahoo.com
Web- http://oppamthadathil.tripod.com
***************************************************************
import numpy as np
import scipy as sp
from statsmodels.tsa.tsatools import lagmat
from matplotlib import pyplot as plt
x=sp.randn(100)
y=lagmat(x,5) # creating lag of 5 (this is a matrix of all lags up to 5)
yy=y[:,4].squeeze()
cc=plt.xcorr(x,yy,maxlags=20)
xcor=cc[1]
lags=cc[0]
plt.subplot(211)
plt.grid() 
plt.plot(x,'o')
plt.plot(x)
plt.plot(yy,'o')
plt.plot(yy)
plt.subplot(212)
plt.stem(lags,xcor)
plt.grid()
plt.show()


_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to