# Moving Window Computation of Skewness and Kurtosis

I would like to be able to calculate Skewness and Kurtosis from a sliding window dataset in a computationally efficient manner. The dataset shall be a specified quantity with new elements replacing old (eg. FIFO queue).

The answer for a similar question regarding variance by mjqxxx appears to be the required approach where a sum of squares is incrementally maintained. The advantage is that old elements leaving the queue can easily decrement the sum of squares figure, thus allowing for the moving window.

The poster suggests that a similar approach can be used to derive Skewness and Kurtosis.

What is the formula for Skewness and Kurtosis using the suggested approach?

• have you figured this out? – toriningen May 23 at 20:43

I did some research. Turns out that $$T_\alpha$$ notation is closely related to Central moments, so results can be replicated as follows:

## Prerequisites

$$\mu_\alpha' = \frac{\sum_{i=0}^n x_i^\alpha}{n}$$

$$\mu_1 = \mu_1'$$ $$\mu_2 = \mu_2' - \mu_1^2$$ $$\mu_3 = \mu_3' - 3\mu_1'\mu_2' + 2\mu_1'^3$$ $$\mu_4 = \mu_4' - 4\mu_1'\mu_3' + 6\mu_1'^2\mu_2' - 3\mu_1'^4$$

## Mean

$$\bar{x} = \mu_1$$

## Population variance

$$\sigma^2 = \mu_2$$

Computed by numpy.var(xs, ddof=0)

## Sample variance

$$s^2 = \frac{\mu_2 n}{n - 1}$$

Computed by numpy.var(xs, ddof=1)

## Population standard deviation

$$\sigma = \sqrt{\mu_2}$$

Computed by numpy.std(xs, ddof=0)

## Sample standard deviation

$$s = \sqrt{\mu_2}$$

Computed by numpy.std(xs, ddof=1)

## Population skewness

$$\tilde{\mu}_3 = \frac{\mu_3}{\sqrt{\mu_2^3}}$$

Computed by scipy.stats.skew(xs, bias=True)

## Sample skewness

$$b_1 = \tilde{\mu}_3 \frac{\sqrt{n(n - 1)}}{n - 2}$$

Computed by scipy.stats.skew(xs, bias=False)

## Population kurtosis

$$\kappa = \frac{\mu_4}{\mu_2 ^ 2}$$

Computed by scipy.stats.kurtosis(xs, bias=False, fisher=False)

## Population excess kurtosis

$$p = \kappa - 3$$

Computed by scipy.stats.kurtosis(xs, bias=False, fisher=True)

## Sample excess kurtosis

$$g_2 = \frac{(n^2 - 1)\kappa - 3(n - 1)^2}{(n - 2)(n - 3)}$$

Computed by scipy.stats.kurtosis(xs, bias=True, fisher=True)