Title: | Fast Computation of Running Statistics for Time Series |
---|---|
Description: | Provides methods for fast computation of running sample statistics for time series. These include: (1) mean, (2) standard deviation, and (3) variance over a fixed-length window of time-series, (4) correlation, (5) covariance, and (6) Euclidean distance (L2 norm) between short-time pattern and time-series. Implemented methods utilize Convolution Theorem to compute convolutions via Fast Fourier Transform (FFT). |
Authors: | Marta Karas [aut, cre] |
Maintainer: | Marta Karas <[email protected]> |
License: | GPL-3 |
Version: | 1.1.0 |
Built: | 2025-03-02 03:18:53 UTC |
Source: | https://github.com/martakarass/runstats |
Computes running correlation between time-series x
and short-time pattern y
.
RunningCor(x, y, circular = FALSE)
RunningCor(x, y, circular = FALSE)
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 |
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 is the length of time-series
x
, 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]
and y
,
last element of the output vector corresponds to sample correlation between c(x[l_x], x[1:(l_y - 1)])
and y
.
If circular
equals FALSE
then
first element of the output vector corresponds to sample correlation between x[1:l_y]
and y
,
the -th element of the output vector corresponds to sample correlation between
x[(l_x - l_y + 1):l_x]
,
last W-1
elements of the output vector are filled with NA
.
See runstats.demo(func.name = "RunningCor")
for a detailed presentation.
A numeric vector.
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")
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")
Computes running covariance between time-series x
and short-time pattern y
.
RunningCov(x, y, circular = FALSE)
RunningCov(x, y, circular = FALSE)
x |
A numeric vector. |
y |
A numeric vector, of equal or shorter length than |
circular |
Logical; whether running variance is computed assuming
circular nature of |
Computes running covariance 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 is the length of time-series
x
, is the length of short-time pattern
y
.
If circular
equals TRUE
then
first element of the output vector corresponds to sample covariance between x[1:l_y]
and y
,
last element of the output vector corresponds to sample covariance between c(x[l_x], x[1:(l_y - 1)])
and y
.
If circular
equals FALSE
then
first element of the output vector corresponds to sample covariance between x[1:l_y]
and y
,
the -th last element of the output vector corresponds to sample covariance between
x[(l_x - l_y + 1):l_x]
,
last W-1
elements of the output vector are filled with NA
.
See runstats.demo(func.name = "RunningCov")
for a detailed presentation.
A numeric vector.
x <- sin(seq(0, 1, length.out = 1000) * 2 * pi * 6) y <- x[1:100] out1 <- RunningCov(x, y, circular = TRUE) out2 <- RunningCov(x, y, circular = FALSE) plot(out1, type = "l"); points(out2, col = "red")
x <- sin(seq(0, 1, length.out = 1000) * 2 * pi * 6) y <- x[1:100] out1 <- RunningCov(x, y, circular = TRUE) out2 <- RunningCov(x, y, circular = FALSE) plot(out1, type = "l"); points(out2, col = "red")
Computes running L2 norm between between time-series x
and short-time pattern y
.
RunningL2Norm(x, y, circular = FALSE)
RunningL2Norm(x, y, circular = FALSE)
x |
A numeric vector. |
y |
A numeric vector, of equal or shorter length than |
circular |
logical; whether running L2 norm is computed assuming
circular nature of |
Computes running L2 norm between 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 is the length of time-series
x
, is the length of short-time pattern
y
.
If circular
equals TRUE
then
first element of the output vector corresponds to sample L2 norm between x[1:l_y]
and y
,
last element of the output vector corresponds to sample L2 norm between c(x[l_x], x[1:(l_y - 1)])
and y
.
If circular
equals FALSE
then
first element of the output vector corresponds to sample L2 norm between x[1:l_y]
and y
,
the -th element of the output vector corresponds to sample L2 norm between
x[(l_x - l_y + 1):l_x]
,
last W-1
elements of the output vector are filled with NA
.
See runstats.demo(func.name = "RunningL2Norm")
for a detailed presentation.
A numeric vector.
## Ex.1. x <- sin(seq(0, 1, length.out = 1000) * 2 * pi * 6) y1 <- x[1:100] + rnorm(100) y2 <- rnorm(100) out1 <- RunningL2Norm(x, y1) out2 <- RunningL2Norm(x, y2) plot(out1, type = "l"); points(out2, col = "blue") ## Ex.2. x <- sin(seq(0, 1, length.out = 1000) * 2 * pi * 6) y <- x[1:100] + rnorm(100) out1 <- RunningL2Norm(x, y, circular = TRUE) out2 <- RunningL2Norm(x, y, circular = FALSE) plot(out1, type = "l"); points(out2, col = "red")
## Ex.1. x <- sin(seq(0, 1, length.out = 1000) * 2 * pi * 6) y1 <- x[1:100] + rnorm(100) y2 <- rnorm(100) out1 <- RunningL2Norm(x, y1) out2 <- RunningL2Norm(x, y2) plot(out1, type = "l"); points(out2, col = "blue") ## Ex.2. x <- sin(seq(0, 1, length.out = 1000) * 2 * pi * 6) y <- x[1:100] + rnorm(100) out1 <- RunningL2Norm(x, y, circular = TRUE) out2 <- RunningL2Norm(x, y, circular = FALSE) plot(out1, type = "l"); points(out2, col = "red")
Computes running sample mean of a time-series x
in a fixed length window.
RunningMean(x, W, circular = FALSE)
RunningMean(x, W, circular = FALSE)
x |
A numeric vector. |
W |
A numeric scalar; length of |
circular |
Logical; whether running sample mean is computed assuming
circular nature of |
The length of output vector equals the length of x
vector.
Parameter circular
determines whether x
time-series is assumed to have a circular nature.
Assume is the length of time-series
x
, W
is a fixed length of x
time-series window.
If circular
equals TRUE
then
first element of the output time-series corresponds to sample mean of x[1:W]
,
last element of the output time-series corresponds to sample mean of c(x[l_x], x[1:(W - 1)])
.
If circular
equals FALSE
then
first element of the output time-series corresponds to sample mean of x[1:W]
,
-th element of the output time-series corresponds to
sample mean of
x[(l_x - W + 1):l_x]
,
last W-1
elements of the output time-series are filled with NA
.
See runstats.demo(func.name = "RunningMean")
for a detailed presentation.
A numeric vector.
x <- rnorm(10) RunningMean(x, 3, circular = FALSE) RunningMean(x, 3, circular = TRUE)
x <- rnorm(10) RunningMean(x, 3, circular = FALSE) RunningMean(x, 3, circular = TRUE)
Computes running sample standard deviation of a time-series x
in a fixed length window.
RunningSd(x, W, circular = FALSE)
RunningSd(x, W, circular = FALSE)
x |
A numeric vector. |
W |
A numeric scalar; length of |
circular |
Logical; whether running sample standard deviation is computed assuming
circular nature of |
The length of output vector equals the length of x
vector.
Parameter circular
determines whether x
time-series is assumed to have a circular nature.
Assume is the length of time-series
x
, W
is a fixed length of x
time-series window.
If circular
equals TRUE
then
first element of the output time-series corresponds to sample standard deviation of x[1:W]
,
last element of the output time-series corresponds to sample standard deviation of c(x[l_x], x[1:(W - 1)])
.
If circular
equals FALSE
then
first element of the output time-series corresponds to sample standard deviation of x[1:W]
,
the -th element of the output time-series corresponds to sample standard deviation of
x[(l_x - W + 1):l_x]
,
last W-1
elements of the output time-series are filled with NA
.
See runstats.demo(func.name = "RunningSd")
for a detailed presentation.
A numeric vector.
x <- rnorm(10) RunningSd(x, 3, circular = FALSE) RunningSd(x, 3, circular = FALSE)
x <- rnorm(10) RunningSd(x, 3, circular = FALSE) RunningSd(x, 3, circular = FALSE)
Computes running sample variance of a time-series x
in a fixed length window.
RunningVar(x, W, circular = FALSE)
RunningVar(x, W, circular = FALSE)
x |
A numeric vector. |
W |
A numeric scalar; length of |
circular |
Logical; whether running sample variance is computed assuming
circular nature of |
The length of output vector equals the length of x
vector.
Parameter circular
determines whether x
time-series is assumed to have a circular nature.
Assume is the length of time-series
x
, W
is a fixed length of x
time-series window.
If circular
equals TRUE
then
first element of the output time-series corresponds to sample variance of x[1:W]
,
last element of the output time-series corresponds to sample variance of c(x[l_x], x[1:(W - 1)])
.
If circular
equals FALSE
then
first element of the output time-series corresponds to sample variance of x[1:W]
,
the -th element of the output time-series corresponds to sample variance of
x[(l_x - W + 1):l_x]
,
last W-1
elements of the output time-series are filled with NA
.
See runstats.demo(func.name = "RunningVar")
for a detailed presentation.
A numeric vector.
x <- rnorm(10) RunningVar(x, W = 3, circular = FALSE) RunningVar(x, W = 3, circular = TRUE)
x <- rnorm(10) RunningVar(x, W = 3, circular = FALSE) RunningVar(x, W = 3, circular = TRUE)
Generates demo visualization of output of methods for computing running statistics.
runstats.demo(func.name = "RunningCov")
runstats.demo(func.name = "RunningCov")
func.name |
Character value; one of the following:
|
NULL
## Not run: runstats.demo(func.name = "RunningMean") runstats.demo(func.name = "RunningSd") runstats.demo(func.name = "RunningVar") runstats.demo(func.name = "RunningCov") runstats.demo(func.name = "RunningCor") runstats.demo(func.name = "RunningL2Norm") ## End(Not run)
## Not run: runstats.demo(func.name = "RunningMean") runstats.demo(func.name = "RunningSd") runstats.demo(func.name = "RunningVar") runstats.demo(func.name = "RunningCov") runstats.demo(func.name = "RunningCor") runstats.demo(func.name = "RunningL2Norm") ## End(Not run)