# How to determine the correlation between 2 time series while controlling for a 3rd?

I would like to determine the relationship between two variables after controlling for a third. Specifically, I want to know if the prices of mercury and gold over time are correlated with each other more than or less than they are correlated with a generic metals price index. Is there some special signal in the relationship between these commodities or are they just moving in line with the overall index?

I have a data set with 32 annual values (1980-2011) for mercury price, gold price, and metals index. I am using R.

Below I have posted time series plots of each of the three variables. • maybe it worth trying the Granger causality for your time series. It gives you an idea that how well two time series are correlated. – omidi Feb 4 '14 at 19:21

You can approach the problem within a VAR (vector autoregressive models) framework. Essentially, you would ask: after I take into account the past values of M, and the past values of IMF, is there some information in the past values of G that would help me improve my prediction for the current value of M (and similarly for the other variables in the system).

The vars package in R can be used to estimate VAR models.

Note that depending on the properties of the time series (e.g. stationarity), the VAR approach can be more or less appropriate. An alternative to consider is vector error-correction models. You can find this document useful: http://cran.r-project.org/web/packages/vars/vignettes/vars.pdf

• Thank you, Dimiter, for your answer. Will upvote when I get points. I am looking at the VAR approach, but it's taking me a while to get my head around it. In the meantime, I tried some more basic methods. I would love to know if these seem valid. Again, the aim is to determine the relationship of Hg prices and Au prices after taking into account a generic metals price index. I will explain my approach by answering my question below. – Caluchko Feb 18 '14 at 16:53

Before undertaking a more complex time series approach like VAR, I have attempted some more basic approaches. Again, the aim is to determine the relationship of Hg prices and Au prices after taking into account a generic metals price index.

First, I ran a cross-correlation of the mercury and gold price series. The highest correlation was a lag-0, so I decided to ignore time lags for now.

Then, I ran correlations (pearson) on each pair of variables (e.g. mercury~gold). I found that mercury and gold prices were correlated more strongly (~0.9) than either mercury or gold were correlated with the price index (~0.6 and ~0.5 respectively).

Next, I created 3 linear regression models: (hg~au), (hg~price index), and (hg~au + price index). The last mode showed the highest R2, with au contributing most to the fit, but the price index also making a statistically significant contribution.

I concluded that mercury and gold prices are correlated much more strongly to each other than to a generic price index, and that a linear model including both gold price and metals price index provided the best prediction for mercury prices.

I would be very grateful for any feedback or criticism. Would VAR add significant value to this?