sliding_window: Compute summary statistics on a sliding window

Description Usage Arguments Details Value Author(s) Examples

Description

Compute summary statistics on a sliding window along a vector containing data where the positions of the data points are stored in another vector.

Usage

1
2
sliding_window(x, pos, start, width, advance, stat = c("mean", "median",
  "min", "max", "sd"))

Arguments

x

A numeric vector containing the values.

pos

A incresingly sorted vector containing the corresponding positions.

start

A double. The starting point of the sliding window.

width

A double. The width of the sliding window.

advance

A double. The step size of the sliding window.

stat

A string. The summary statistic to be calculated.

Details

Note that only windows that fully fit into the range of pos are considered.

Value

A data.frame with columns start (start of the window), end (end of the window), stat (the computed summary statistic) and n (number of data points in the window).

Author(s)

Dominik Mueller (dominikmueller64@yahoo.de).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
set.seed(123L)
n <- 1000L
x <- arima.sim(n = n, list(ar = 0.99))
pos <- sort(runif(n))
plot(x = pos, y = x)
advance <- 0.01
width <- c(0.02, 0.1, 0.2)
colors <- c('red', 'green', 'blue')
for (i in seq_along(width)) {
  df <- sliding_window(x, pos, 0.0, width[i], advance, "mean")
  points(x = df$begin + width[i] / 2, df$stat, col = colors[i], pch = 19, lwd = 2.0, type = 'l')
}

DominikMueller64/LDtools documentation built on May 6, 2019, 2:51 p.m.