ewmMean
Syntax
ewmMean(X, [com], [span], [halfLife], [alpha], [minPeriods=0], [adjust=true], [ignoreNA=false])
Details
Calculate exponentially weighted moving average.
Exactly one of the parameters com, span, halfLife and alpha must be specified.
Arguments
X is a numeric vector.
com is a nonnegative floating number and specifies decay in terms of center of mass. alpha=1/(1+com) where alpha is the decay factor.
span is a positive floating number larger than 1 and specifies decay in terms of span. alpha=2/(span+1).
halfLife is a positive floating number and specifies decay in terms of half-life. alpha=1-exp(log(0.5)/halfLife).
alpha is a floating number between 0 and 1 and directly specifies decay.
minPeriods is an integer indicating the minimum number of observations in window required to have a value (otherwise result is NULL). The default value is 0.
adjust is a Boolean value. The default value is true.
If adjust=true, the weights are (1-alpha)^(n-1), (1-alpha)^(n-2), …, 1-alpha, 1 divided by their sum.
If adjust=false, the weights are (1-alpha)^(n-1), (1-alpha)^(n-2)*alpha, (1-alpha)^(n-3)*alpha^2,…, (1-alpha)*alpha, alpha.
ignoreNA is a Boolean value indicating whether to ignore missing values. The defaut value is false.
Examples
$ a=[0,1,2,int(),4]
$ ewmMean(X=a,com=0.5);
[0,0.75,1.615385,1.615385,3.670213]
$ ewmMean(X=a,com=0.5,ignoreNA=true);
[0,0.75,1.615385,1.615385,3.225]