## A new correlation coefficient

For posting your own programs to share with others

Moderators: EViews Gareth, EViews Moderator

trubador
Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

### A new correlation coefficient

In a recent article, authors have proposed a new correlation coefficient for time series data that measures the distance between two subsequent data points by taking the lag difference into consideration. They demonstrate that the new correlation coefficient better captures the direction of the covariation of the two variables over time.

The code below shows the computation of new coefficient as well as the simulations outlined in the article (i.e. vis-a-vis the ordinary correlation):

Code: Select all

`'Reference: Erdem, O., Ceyhan, E. and Varli, Y. (2014). A new correlation coefficient for bivariate time-series data, Physica A, 414, pp. 274–284mode quiet!nobs = 100 '# observations!nsim = 10000 '# simulationswfcreate u !nobs 'create an unstructured workfile!case= 1 '(1 -> Stationary, 2 -> Random walk, 3- > Cointegrated)matrix(!nsim,2) compare 'store the results'generate null seriesseries xseries y'Run the simulationssmpl @first+1 @last!rho = 0for !i = 1 to !nsim  if !case = 1 then    x(1) = @rnorm 'random initialization    y(1) = @rnorm    x = @rnorm    y = @rnorm    else if !case = 2 then    x(1) = @rnorm    y(1) = @rnorm    x = x(-1) + @rnorm    y = y(-1) + @rnorm    else    x(1) = @rnorm    y(1) = @rnorm    !a=0.8    x = x(-1) + nrnd    y = !a*x + nrnd    endif endif  'Compute the ordinary correlation  compare(!i,1) = @cor(x,y)  'Compute the proposed new correlation  call newcor(x,y,!rho)  compare(!i,2) = !rho  'Watch the progress  statusline !i of !nsimnext'Histograms of simulated correlationsfreeze(mode=overwrite,histograms) compare.distplotshow histogramssmpl @all'Local subroutine that computes the proposed correlation coefficentsubroutine local newcor(series x,series y,scalar rho)series dx = d(x)series dy = d(y)series dxy = dx*dygroup g.add dx dylocal smplsmpl @all if @rnas(g)=0  'data may include missing values!Ax = @sqrt(@sumsq(dx)/@obssmpl)!Ay = @sqrt(@sumsq(dy)/@obssmpl)!Axy = @sum(dxy)/@obssmplrho = !Axy/(!Ax*!Ay)endsub`

Return to “Program Repository”

### Who is online

Users browsing this forum: No registered users and 2 guests