Skip to contents

A larger value of alpha will assign larger weights to more recent observations.

Usage

weights_exponential(alpha, n)

Arguments

alpha

A value between 0 and 1 that determines how quick the exponential decay in the weights is

n

The number of weights to create; this is usually equal to the number of observations in a time series

Value

A monotonically increasing numeric vector of n values between 0 and 1 that sum up to 1

Examples

weights_exponential(alpha = 0.25, n = 5)
#> [1] 0.1037132 0.1382843 0.1843790 0.2458387 0.3277849
weights_exponential(alpha = 1, n = 7)
#> [1] 0 0 0 0 0 0 1
weights_exponential(alpha = 0, n = 4)
#> [1] 0.25 0.25 0.25 0.25

# zooming into an exponential series again gives an exponential series
identical(
  weights_exponential(alpha = 0.75, n = 5)[1:4] /
    sum(weights_exponential(alpha = 0.75, n = 5)[1:4]),
  weights_exponential(alpha = 0.75, n = 4)
)
#> [1] TRUE