# Pearson correlation coefficient between two time series

How do i compare two time series:(Pearson correlation coefficient) 1st time series is generated by google trends for search term "India" 2nd time series is Foreign Tourist Arrivals(absolute value of arrivals) to India each month.

• Are you sure you want a simple correlation? What kind of comparison do you want? What would you like to know about how they're related? Eg, do you want to know if values in 1 ts predict subsequent values in the other? Do you want to know if they are cointegrated? Commented Dec 1, 2015 at 22:03

The simple way to compute it is to pair up all observations at the same time and compute the sample Pearson's correlation (this is what Google Correlate does)

For example, Let's say you want to correlate the time series $S_1$ and $S_2$:

time S_1     S_2
t_1  20.4400 19.7450
t_2  19.0750 20.3300
t_3  20.0650 20.1700
..   ..      ..

Which might look like this when plotted:

You just have to use this formula: $$r(S_1,S_2) \triangleq \frac{ \sum_{k=1}^n (S_1(t_k) - \bar{S_1})(S_2(t_k) - \bar{S_2}) }{ \sqrt{ \sum_{k=1}^n (S_1(t_k)- \bar{S_1})^2 \sum_{k=1}^n (S_2(t_k) - \bar{S_2})^2 }}$$ where $S_1(t_k)$ is a particular value of the time series $S_1$ at time $t_k$, and $\bar{S_1}$ is the average value of $S_1$.

(Just look at the formula of the sample Pearson's correlation between two variables $X$ and $Y$, from wikipedia)

As Gung said, there are different approaches to tackle this problem. Pearson's correlation is good if you are interested in linear correlations, which are very intuitive. There are other measures of dependencies which identify non-linear relationships. I can point you out to a presentation I prepared (hope it is not too shameful to add something of mine here)

• Hey Simone, My hypothesis is to use google trends to improve traditional forecast of FTA to India . TO narrow down the search queries , i want to choose queries which are correlated to the monthly FTA time series. Additionally , How can we aggregate weekly google trends data to get monthly data. Commented Dec 3, 2015 at 15:13
• I think that averaging week values would work fine Commented Dec 3, 2015 at 21:58
• I really appreciate you posting your presentation. It's helpful, not promotional. Commented Feb 9, 2016 at 19:22