A new correlation coefficient

For posting your own programs to share with others

Moderators: EViews Gareth, EViews Moderator

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

A new correlation coefficient

Postby trubador » Fri Aug 29, 2014 4:46 am

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–284

mode quiet
!nobs = 100 '# observations
!nsim = 10000 '# simulations

wfcreate u !nobs 'create an unstructured workfile

!case= 1 '(1 -> Stationary, 2 -> Random walk, 3- > Cointegrated)
matrix(!nsim,2) compare 'store the results

'generate null series
series x
series y

'Run the simulations
smpl @first+1 @last
!rho = 0
for !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
    x(1) = @rnorm
    y(1) = @rnorm
    x = x(-1) + nrnd
    y = !a*x + nrnd
  '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 !nsim

'Histograms of simulated correlations
freeze(mode=overwrite,histograms) compare.distplot
show histograms

smpl @all

'Local subroutine that computes the proposed correlation coefficent
subroutine local newcor(series x,series y,scalar rho)
series dx = d(x)
series dy = d(y)
series dxy = dx*dy
group g.add dx dy
local smpl
smpl @all if @rnas(g)=0  'data may include missing values
!Ax = @sqrt(@sumsq(dx)/@obssmpl)
!Ay = @sqrt(@sumsq(dy)/@obssmpl)
!Axy = @sum(dxy)/@obssmpl
rho = !Axy/(!Ax*!Ay)

Return to “Program Repository”

Who is online

Users browsing this forum: No registered users and 4 guests