Description Usage Arguments Details References Examples
Functions for calculating different rolling aggregates.
1 | rolling.sum(x, w, type = "lag", na.rm = FALSE)
|
x |
An atomic vector of class numeric. |
w |
An integer value specifying the width of the windows over which to calculate the rolling aggregate. |
type |
Either one of "lag" (window ends with current observation), "mid" (current observation is in the middle of the window) or "lead" (window starts with current observation). |
na.rm |
A logical value indicating whether |
If na.rm
is set to TRUE
and there are no valid values inside a window, rolling.sum
will return the value 0.
rolling.var
returns the unbiased sample estimator Var(x) = (1 / (n - 1)) * sum_i (x_i - mu)^2.
rolling.sd
simply calls rolling.var
and returnes the square root of the rolling variances.
The skewness measures the direction and degree of a distrubution's asymmetry. A symmetric distribution has a skewness of zero, while a "left-skewed" (or "left-tailed") distribution (where the arithmetic mean is less than the median) has a negative skewness. The Fisher-Pearson standardised moment coefficient, as discussed by Joanes and Gill (1998) is used to calculate the rolling skewness:
(sqrt(n(n - 1))/(n(n - 2)) ((sum_i (x_i - mu)^3)/((1 / n) sum_i (x_i - mu)^2)^(3 / 2))
The kurtosis describes the "tailedness" of a distribution. Using s2 = sum_i (x_i - mu)^2, s4 = sum_i (x_i - mu)^4 and Var(x) = s2 / (n - 1), the kurtosis is defined as follows:
kurtosis = (n(n - 1) / ((n - 1)(n - 2)(n - 3))) (s4 / Var(x)^2) - 3(((n - 1)^2 / ((n - 2)(n - 3)))).
The formula is can be found in Sheskin (2000) and yields an expected kurtosis of zero for a Gaussian distribution.
Sheskin, D.J. (2000) Handbook of Parametric and Nonparametric Statistical Procedures, Second Edition. Boca Raton, Florida: Chapman & Hall/CRC.
Joanes, D. N. and Gill, C. A. (1998), Comparing measures of sample skewness and kurtosis. Journal of the Royal Statistical Society: Series D (The Statistician), 47: 183-189. doi:10.1111/1467-9884.00122
1 2 | x <- rnorm(100)
rolling.sum(x = x, w = 10)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.