Skip to content

Compute exponentially-weighted moving sum

Source code

Description

[Experimental]

Usage

<Expr>$ewm_sum(
  ...,
  com = NULL,
  span = NULL,
  half_life = NULL,
  alpha = NULL,
  min_samples = 1,
  ignore_nulls = FALSE
)

Arguments

… These dots are for future extensions and must be empty.
com Specify decay in terms of center of mass, *γ*, with

$\alpha = \frac{1}{1 + \gamma} \\ \forall \\ \gamma \geq 0$ .

span Specify decay in terms of span, *θ*, with

$\alpha = \frac{2}{\theta + 1} \\ \forall \\ \theta \geq 1$

half_life Specify decay in terms of half-life, *λ*, with

= 1 - { } ; ; \> 0

alpha Specify smoothing factor alpha directly, 0 \< .
min_samples Minimum number of non-null observations required before returning a result.
ignore_nulls Ignore missing values when calculating weights. If FALSE (default), weights are based on absolute positions. If TRUE, weights are based on the relative positions of non-null values.

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(a = 1:3)
df$select(pl$col("a")$ewm_sum(alpha = 0.5))
#> shape: (3, 1)
#> ┌──────┐
#> │ a    │
#> │ ---  │
#> │ f64  │
#> ╞══════╡
#> │ 1.0  │
#> │ 2.5  │
#> │ 4.25 │
#> └──────┘