Skip to content
Prev 316439 / 398513 Next

ccf (cross correlation function) problems

Your question and your English are just fine!

If I were you, I would not mess around with the ccf() function but
would attack the question "directly" using the cor.test() function, with
sub-vectors of your x vector. Personally I find the notion of "lag" in acf()
and ccf() highly confusing and I always make "parity errors" --- i.e. I get
things backwards!

Moreover, the ccf() function is throwing information away; it truncates
the x vector to have the same length as y, i.e. 21, and so never uses
x[22:29] --- which have useful content in respect of lags less than 8.
You haven't a lot of data, so it is prudent not to be wasteful.

What I would do:

OP <- par(mfrow=c(3,3))
for(i in 1:9) {
CT <- cor.test(x[i:(20+i)],y,alternative="less")
PV <- CT$p.value
cat("lag =",9-i,"p-value =",PV,"\n")
COR <- sprintf("%1.3f",CT$estimate)
plot(x[i:(20+i)],y,xlab="x",main=paste("lag =",9-i,"corr =",COR))
}
par(OP)

HTH

cheers,

Rolf Turner
On 01/29/2013 11:26 PM, Larissa Modica wrote: