Package {IMW}


Type: Package
Title: Incremental Moment Windows
Version: 1.1
Date: 2026-10-08
Description: Computes rolling statistics, including the mean, variance, skewness, and kurtosis, over moving windows. The package uses incremental algorithms to efficiently update statistics as new observations arrive, supporting both online computation and batch processing for time-series analysis and streaming data applications. Implemented in C++, the package provides a high-performance, header-only implementation that facilitates direct integration into other packages.
License: MIT + file LICENSE
Encoding: UTF-8
Imports: Rcpp (≥ 1.0.4.6)
LinkingTo: Rcpp
Config/roxygen2/version: 8.1.0
NeedsCompilation: yes
Packaged: 2026-10-22 12:25:55 UTC; svilsen
Author: Søren B. Vilsen [aut, cre]
Maintainer: Søren B. Vilsen <svilsen@mp.aau.dk>
Repository: CRAN
Date/Publication: 2026-11-04 20:10:02 UTC

IMW: Incremental Moment Windows

Description

Computes rolling statistics, including the mean, variance, skewness, and kurtosis, over moving windows. The package uses incremental algorithms to efficiently update statistics as new observations arrive, supporting both online computation and batch processing for time-series analysis and streaming data applications. Implemented in C++, the package provides a high-performance, header-only implementation that facilitates direct integration into other packages.

Author(s)

Maintainer: Søren B. Vilsen svilsen@mp.aau.dk

Authors:


Matrix Conversion

Description

Converts an object of imw-object to a matrix.

Usage

## S3 method for class 'imw'
as.matrix(x, ...)

Arguments

x

An imw-object.

...

Additional arguments; not used in this instance.

Value

A numeric matrix of rolling statistics.

Examples

N <- 100
x <- cumsum(rnorm(N))

k <- 10
mw <- imw(x, k)

as.matrix(mw)


Incremental Moment Windows

Description

Rolling estimates of moments given a fixed window size.

Usage

imw(x, k)

Arguments

x

Vector, or column matrix: The data used to estimate the moments.

k

Numeric: The window size.

Value

An imw-object.

Examples

N <- 100
x <- cumsum(rnorm(N))

k <- 10
imw(x, k)
 

An imw-object

Description

An imw-object is a list of class imw containing the following:

stats

Matrix: The rolling mean, variance, skewness, and kurtosis of data.

lagged

Vector: A vector of the incremental moments, as well as the number of observations used to calculate these moments, at the beginning of the last window.

total

Vector: A vector of the incremental moments, as well as the number of observations used to calculate these moments, at the end of the last window.

x

Matrix: The data used to estimate the moments.

k

Numeric: The size of the window used to calculate the four moments.


Rolling Kurtosis

Description

Returns the rolling kurtosis of an imw-object.

Usage

kurtosis(x, ...)

Arguments

x

An imw-object.

...

Additional arguments, see details.

Details

The only additional argument is type which takes the values 1, 2, 3, corresponding to the three methods discussed by Joanes and Gill (1998).

Value

The estimated rolling kurtosis.

References

D. N. Joanes and C. A. Gill (1998), Comparing measures of sample skewness and kurtosis. The Statistician, 47, 183–189.

Examples

N <- 100
x <- cumsum(rnorm(N))

k <- 10
mw <- imw(x, k)

kurtosis(mw)


Rolling Kurtosis

Description

Returns the rolling kurtosis of an imw-object.

Usage

## S3 method for class 'imw'
kurtosis(x, ...)

Arguments

x

An imw-object.

...

Additional arguments, see details.

Details

The only additional argument is type which takes the values 1, 2, 3, corresponding to the three methods discussed by Joanes and Gill (1998).

Value

The estimated rolling kurtosis.

References

D. N. Joanes and C. A. Gill (1998), Comparing measures of sample skewness and kurtosis. The Statistician, 47, 183–189.

Examples

N <- 100
x <- cumsum(rnorm(N))

k <- 10
mw <- imw(x, k)

kurtosis(mw)


Rolling Mean

Description

Returns the rolling mean of an imw-object.

Usage

## S3 method for class 'imw'
mean(x, ...)

Arguments

x

An imw-object.

...

Additional arguments; not used in this instance.

Value

The estimated rolling mean.

Examples

N <- 100
x <- cumsum(rnorm(N))

k <- 10
mw <- imw(x, k)

mean(mw)


Plot of rolling statistics

Description

Shows the four rolling statistics of an imw-object.

Usage

## S3 method for class 'imw'
plot(x, ...)

Arguments

x

An imw-object.

...

Additional arguments passed to the internal plot functions.

Value

An invisible NULL.

Examples

N <- 100
x <- cumsum(rnorm(N))

k <- 10
mw <- imw(x, k)

plot(mw)


Rolling Skewness

Description

Returns the rolling skewness of an imw-object.

Usage

skewness(x, ...)

Arguments

x

An imw-object.

...

Additional arguments, see details.

Details

The only additional argument is type which takes the values 1, 2, 3, corresponding to the three methods discussed by Joanes and Gill (1998).

Value

The estimated rolling skewness.

References

D. N. Joanes and C. A. Gill (1998), Comparing measures of sample skewness and kurtosis. The Statistician, 47, 183–189.

Examples

N <- 100
x <- cumsum(rnorm(N))

k <- 10
mw <- imw(x, k)

skewness(mw)


Rolling Skewness

Description

Returns the rolling skewness of an imw-object.

Usage

## S3 method for class 'imw'
skewness(x, ...)

Arguments

x

An imw-object.

...

Additional arguments, see details.

Details

The only additional argument is type which takes the values 1, 2, 3, corresponding to the three methods discussed by Joanes and Gill (1998).

Value

The estimated rolling skewness.

References

D. N. Joanes and C. A. Gill (1998), Comparing measures of sample skewness and kurtosis. The Statistician, 47, 183–189.

Examples

N <- 100
x <- cumsum(rnorm(N))

k <- 10
mw <- imw(x, k)

skewness(mw)


Update Incremental Moment Windows

Description

Update an imw-object with new data.

Usage

uimw(object, xnew)

Arguments

object

An imw-object.

xnew

Vector, or column matrix: The new data used to update the estimated moments.

Value

An imw-object.

Examples

# Initial data
N <- 100
x <- cumsum(rnorm(N))

k <- 10
mw <- imw(x, k)

# Additional data
M <- 20
y <- cumsum(c(tail(x, 1), rnorm(M)))[-1]

uimw(mw, y)


Rolling Variance

Description

Returns the rolling variance of an imw-object.

Usage

variance(x, ...)

Arguments

x

An imw-object.

...

Additional arguments, see details.

Details

The only additional argument is type which takes the values 1 and 2 corresponding to the population and sample variance, respectively.

Value

The estimated rolling variance.

Examples

N <- 100
x <- cumsum(rnorm(N))

k <- 10
mw <- imw(x, k)

variance(mw)


Rolling Variance

Description

Returns the rolling variance of an imw-object.

Usage

## S3 method for class 'imw'
variance(x, ...)

Arguments

x

An imw-object.

...

Additional arguments, see details.

Details

The only additional argument is type which takes the values 1 and 2 corresponding to the population and sample variance, respectively.

Value

The estimated rolling variance.

Examples

N <- 100
x <- cumsum(rnorm(N))

k <- 10
mw <- imw(x, k)

variance(mw)