running_quantile: Running Quantile Calculation

View source: R/vec-running-quantile.R

running_quantileR Documentation

Running Quantile Calculation

Description

The running_quantile function calculates the quantile of a vector over a sliding window, allowing for various alignment and rule options.

Usage

running_quantile(
  .x,
  .window,
  .probs = 0.5,
  .type = 7,
  .rule = "quantile",
  .align = "center"
)

Arguments

.x

A numeric vector for which the running quantile is to be calculated.

.window

An integer specifying the size of the sliding window.

.probs

A numeric value between 0 and 1 indicating the desired quantile probability (default is 0.50).

.type

An integer from 1 to 9 specifying the quantile algorithm type (default is 7).

.rule

A character string indicating the rule to apply at the edges of the window. Possible choices are:

  • "quantile": Standard quantile calculation.

  • "trim": Trims the output to remove values outside the window.

  • "keep": Keeps the original values at the edges of the window.

  • "constant": Fills the edges with the constant value from the nearest valid quantile.

  • "NA": Fills the edges with NA values.

  • "func": Applies a custom function to the values in the window (default is "quantile").

.align

A character string specifying the alignment of the window ("center", "left", or "right"; default is "center").

Details

This function computes the running quantile of a numeric vector using a specified window size and probability.

Value

A numeric vector containing the running quantile values.

Author(s)

Steven P. Sanderson II, MPH

See Also

Other Utility Functions: convert_snake_to_title_case(), generate_caption(), get_attributes(), rand_walk_helper(), std_cum_max_augment(), std_cum_mean_augment(), std_cum_min_augment(), std_cum_prod_augment(), std_cum_sum_augment()

Examples

# Example usage of running_quantile
set.seed(123)
data <- cumsum(rnorm(50))
result <- running_quantile(data, .window = 3, .probs = 0.5)
print(result)

plot(data, type = "l")
lines(result, col = "red")


RandomWalker documentation built on Oct. 23, 2024, 5:07 p.m.