g13au calculates the range (or standard deviation) and the mean for groups of successive time series values. It is intended for use in the construction of range-mean plots.

# Syntax

C# |
---|

public static void g13au( int n, double[] z, int m, int ngrps, string rs, double[] y, double[] mean, out int ifail ) |

Visual Basic |
---|

Public Shared Sub g13au ( _ n As Integer, _ z As Double(), _ m As Integer, _ ngrps As Integer, _ rs As String, _ y As Double(), _ mean As Double(), _ <OutAttribute> ByRef ifail As Integer _ ) |

Visual C++ |
---|

public: static void g13au( int n, array<double>^ z, int m, int ngrps, String^ rs, array<double>^ y, array<double>^ mean, [OutAttribute] int% ifail ) |

F# |
---|

static member g13au : n : int * z : float[] * m : int * ngrps : int * rs : string * y : float[] * mean : float[] * ifail : int byref -> unit |

#### Parameters

- n
- Type: System..::..Int32
*On entry*: $n$, the number of observations in the time series.*Constraint*: ${\mathbf{n}}\ge {\mathbf{m}}$.

- z
- Type: array<System..::..Double>[]()[][]An array of size [n]
*On entry*: ${\mathbf{z}}\left[\mathit{t}-1\right]$ must contain the $\mathit{t}$th observation ${Z}_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,n$.

- m
- Type: System..::..Int32
*On entry*: $m$, the group size.*Constraint*: ${\mathbf{m}}\ge 2$.

- ngrps
- Type: System..::..Int32
*On entry*: $k$, the number of groups.*Constraint*: ${\mathbf{ngrps}}=\mathrm{int}\left({\mathbf{n}}/{\mathbf{m}}\right)$.

- rs
- Type: System..::..String
*On entry*: indicates whether ranges or standard deviations are to be calculated.- ${\mathbf{rs}}=\text{"R"}$
- Ranges are calculated.
- ${\mathbf{rs}}=\text{"S"}$
- Standard deviations are calculated.

*Constraint*: ${\mathbf{rs}}=\text{"R"}$ or $\text{"S"}$.

- y
- Type: array<System..::..Double>[]()[][]An array of size [ngrps]
*On exit*: ${\mathbf{y}}\left[\mathit{i}-1\right]$ contains the range or standard deviation, as determined by rs, of the $\mathit{i}$th group of observations, for $\mathit{i}=1,2,\dots ,k$.

- mean
- Type: array<System..::..Double>[]()[][]An array of size [ngrps]
*On exit*: ${\mathbf{mean}}\left[\mathit{i}-1\right]$ contains the mean of the $\mathit{i}$th group of observations, for $\mathit{i}=1,2,\dots ,k$.

- ifail
- Type: System..::..Int32%
*On exit*: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

Let ${Z}_{1},{Z}_{2},\dots ,{Z}_{n}$ denote $n$ successive observations in a time series. The series may be divided into groups of $m$ successive values and for each group the range or standard deviation (depending on a user-supplied option) and the mean are calculated. If $n$ is not a multiple of $m$ then groups of equal size $m$ are found starting from the end of the series of observations provided, and any remaining observations at the start of the series are ignored. The number of groups used, $k$, is the integer part of $n/m$. If you wish to ensure that no observations are ignored then the number of observations, $n$, should be chosen so that $n$ is divisible by $m$.

The mean, ${M}_{i}$, the range, ${R}_{i}$, and the standard deviation, ${S}_{i}$, for the $i$th group are defined as

and

where $l=n-km$, the number of observations ignored.

$$\begin{array}{c}{M}_{i}=\frac{1}{m}\sum _{j=1}^{m}{Z}_{l+m\left(i-1\right)+j}\\ \\ {R}_{i}={\mathrm{max}}_{1\le j\le m}\left\{{Z}_{l+m\left(i-1\right)+j}\right\}-{\mathrm{min}}_{1\le j\le m}\left\{{Z}_{l+m\left(i-1\right)+j}\right\}\end{array}$$ |

$${S}_{i}=\sqrt{\left(\frac{1}{m-1}\right)\sum _{j=1}^{m}{\left({Z}_{l+m\left(i-1\right)+j}-{M}_{i}\right)}^{2}}$$ |

For seasonal data it is recommended that $m$ should be equal to the seasonal period. For non-seasonal data the recommended group size is $8$.

A plot of range against mean or of standard deviation against mean is useful for finding a transformation of the series which makes the variance constant. If the plot appears random or the range (or standard deviation) seems to be constant irrespective of the mean level then this suggests that no transformation of the time series is called for. On the other hand an approximate linear relationship between range (or standard deviation) and mean would indicate that a log transformation is appropriate. Further details may be found in either Jenkins (1979) or McLeod (1982).

You have the choice of whether to use the range or the standard deviation as a measure of variability. If the group size is small they are both equally good but if the group size is fairly large (e.g., $m=12$ for monthly data) then the range may not be as good an estimate of variability as the standard deviation.

# References

Jenkins G M (1979)

*Practical Experiences with Modelling and Forecasting Time Series*GJP Publications, LancasterMcLeod G (1982)

*Box–Jenkins in Practice. 1: Univariate Stochastic and Single Output Transfer Function/Noise Analysis*GJP Publications, Lancaster# Error Indicators and Warnings

Errors or warnings detected by the method:

- ${\mathbf{ifail}}=1$
On entry, ${\mathbf{n}}<{\mathbf{m}}$, or ${\mathbf{m}}<2$, or ${\mathbf{ngrps}}\ne \text{}$ integer part of ${\mathbf{n}}/{\mathbf{m}}$.

- ${\mathbf{ifail}}=2$
On entry, rs is not equal to "R" or "S".

# Accuracy

The computations are believed to be stable.

# Parallelism and Performance

None.

# Further Comments

The time taken by g13au is approximately proportional to $n$.

# Example

The following program produces the statistics for a range-mean plot for a series of $100$ observations divided into groups of $8$.

Example program (C#): g13aue.cs