RunningCor {runstats} | R Documentation |
Fast Running Correlation Computation
Description
Computes running correlation between time-series x
and short-time pattern y
.
Usage
RunningCor(x, y, circular = FALSE)
Arguments
x |
A numeric vector. |
y |
A numeric vector, of equal or shorter length than |
circular |
logical; whether running correlation is computed assuming
circular nature of |
Details
Computes running correlation between time-series x
and short-time pattern y
.
The length of output vector equals the length of x
.
Parameter circular
determines whether x
time-series is assumed to have a circular nature.
Assume l_x
is the length of time-series x
, l_y
is the length of short-time pattern y
.
If circular
equals TRUE
then
first element of the output vector corresponds to sample correlation between
x[1:l_y]
andy
,last element of the output vector corresponds to sample correlation between
c(x[l_x], x[1:(l_y - 1)])
andy
.
If circular
equals FALSE
then
first element of the output vector corresponds to sample correlation between
x[1:l_y]
andy
,the
l_x - W + 1
-th element of the output vector corresponds to sample correlation betweenx[(l_x - l_y + 1):l_x]
,last
W-1
elements of the output vector are filled withNA
.
See runstats.demo(func.name = "RunningCor")
for a detailed presentation.
Value
A numeric vector.
Examples
x <- sin(seq(0, 1, length.out = 1000) * 2 * pi * 6)
y <- x[1:100]
out1 <- RunningCor(x, y, circular = TRUE)
out2 <- RunningCor(x, y, circular = FALSE)
plot(out1, type = "l"); points(out2, col = "red")