NAG Library Routine Document
G13AUF
1 Purpose
G13AUF 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 rangemean plots.
2 Specification
INTEGER 
N, M, NGRPS, IFAIL 
REAL (KIND=nag_wp) 
Z(N), Y(NGRPS), MEAN(NGRPS) 
CHARACTER(1) 
RS 

3 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 usersupplied 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=nkm$, the number of observations ignored.
For seasonal data it is recommended that $m$ should be equal to the seasonal period. For nonseasonal 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.
4 References
Jenkins G M (1979) Practical Experiences with Modelling and Forecasting Time Series GJP Publications, Lancaster
McLeod G (1982) Box–Jenkins in Practice. 1: Univariate Stochastic and Single Output Transfer Function/Noise Analysis GJP Publications, Lancaster
5 Parameters
 1: N – INTEGERInput
On entry: $n$, the number of observations in the time series.
Constraint:
${\mathbf{N}}\ge {\mathbf{M}}$.
 2: Z(N) – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{Z}}\left(\mathit{t}\right)$ must contain the $\mathit{t}$th observation ${Z}_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,n$.
 3: M – INTEGERInput
On entry: $m$, the group size.
Constraint:
${\mathbf{M}}\ge 2$.
 4: NGRPS – INTEGERInput
On entry: $k$, the number of groups.
Constraint:
${\mathbf{NGRPS}}=\mathrm{int}\left({\mathbf{N}}/{\mathbf{M}}\right)$.
 5: RS – CHARACTER(1)Input
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'}$.
 6: Y(NGRPS) – REAL (KIND=nag_wp) arrayOutput
On exit:
${\mathbf{Y}}\left(\mathit{i}\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$.
 7: MEAN(NGRPS) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{MEAN}}\left(\mathit{i}\right)$ contains the mean of the $\mathit{i}$th group of observations, for $\mathit{i}=1,2,\dots ,k$.
 8: IFAIL – INTEGERInput/Output

On entry:
IFAIL must be set to
$0$,
$1\text{ or}1$. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
$1\text{ or}1$ is recommended. If the output of error messages is undesirable, then the value
$1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
$0$.
When the value $\mathbf{1}\text{ or}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit:
${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${{\mathbf{1}}}$, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
 ${\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'. 
7 Accuracy
The computations are believed to be stable.
The time taken by G13AUF is approximately proportional to $n$.
If you wish to obtain a plot of the group ranges or standard deviations against the group means then
G01AGF may be used. The plot is output to the unit defined by
X04ABF. You should note that
G01AGF sorts the data to be plotted on the
$y$ axis (in this case the ranges or standard deviations). If required you may use
M01EAF to rearrange the data into their original order.
9 Example
The following program produces the statistics for a rangemean plot for a series of $100$ observations divided into groups of $8$.
9.1 Program Text
Program Text (g13aufe.f90)
9.2 Program Data
Program Data (g13aufe.d)
9.3 Program Results
Program Results (g13aufe.r)