Yash
Yash

Reputation: 337

How come CCF function in R return different correlation for same vectors ie. corr(x,y) and corr(y,x)

set.seed(1)
sample = rnorm(20,mean = 5,1)
x=acf(ts.intersect(ts(sample),ts(sample+.5*sample)))

When we look at the output for the above code, x[1,2] , corr between x,y and x[2,1] corr between y,x , it gives a different answer.

x[1,2]!=x[2,1] ; what am I missing?

enter image description here

Upvotes: 1

Views: 318

Answers (1)

Julius Vainora
Julius Vainora

Reputation: 48251

In terms of the plot, perhaps you are missing the lag values: upper right plot has lags 0,...,10, while lower left one has lags -10,...,0. Then indeed i and -i lags coincide for i=0,...,10.

In terms of the x object,

x[2,1]

# Autocorrelations of series ‘ts.intersect(ts(sample), ts(sample + 0.5 * sample))’, by lag
#
#      2 
# -0.185 
x[1,2]

# Autocorrelations of series ‘ts.intersect(ts(sample), ts(sample + 0.5 * sample))’, by lag
#
#      1 
# -0.122 

so that the first one corresponds to lag ±2, while the second one is lag ±1.

Upvotes: 1

Related Questions