set.seed(0)
lambda <- c(rep(0.001, 4500), seq(0.001, 10, length = 500),
seq(10, 0.001, length = 500))
xRle <- Rle(rpois(1e7, lambda))
yRle <- Rle(rpois(1e7, lambda[c(251:length(lambda), 1:250)]))
cor(xRle, yRle)
shifts <- seq(235, 265, by=3)
corrs <- shiftApply(shifts, yRle, xRle, FUN=cor)
cor(xRle, yRle)
shiftApply(249:251, yRle, xRle,
FUN=function(x, y) var(x, y) / (sd(x) * sd(y)))
Run the code above in your browser using DataLab