correlation between cyclical variables

when the cycle is correct

a<-sin(seq(0,2*pi,0.001))
b<-cos(seq(0+0.5*pi,2*pi+.5*pi,0.001))
plot(a,type = "l")
lines(b,col="red")

cor(a,b)
## [1] -1

when one cycle lags behind the other

grid<-seq(0,2*pi,0.01)
a<-sin(grid)
b<-cos(grid)
plot(grid,a,type = "l")
lines(grid,b,col="red")

cor(a,b)
## [1] -3.447308e-06

it’s important to ensure that variables a properly lagged before calculating correlation