NAG FL Interface
g13auf (uni_means)
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
Fortran Interface
Integer, Intent (In) 
:: 
n, m, ngrps 
Integer, Intent (Inout) 
:: 
ifail 
Real (Kind=nag_wp), Intent (In) 
:: 
z(n) 
Real (Kind=nag_wp), Intent (Out) 
:: 
y(ngrps), mean(ngrps) 
Character (1), Intent (In) 
:: 
rs 

C Header Interface
#include <nag.h>
void 
g13auf_ (const Integer *n, const double z[], const Integer *m, const Integer *ngrps, const char *rs, double y[], double mean[], Integer *ifail, const Charlen length_rs) 

C++ Header Interface
#include <nag.h> extern "C" {
void 
g13auf_ (const Integer &n, const double z[], const Integer &m, const Integer &ngrps, const char *rs, double y[], double mean[], Integer &ifail, const Charlen length_rs) 
}

The routine may be called by the names g13auf or nagf_tsa_uni_means.
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
Arguments

1:
$\mathbf{n}$ – Integer
Input

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

2:
$\mathbf{z}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) array
Input

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:
$\mathbf{m}$ – Integer
Input

On entry: $m$, the group size.
Constraint:
${\mathbf{m}}\ge 2$.

4:
$\mathbf{ngrps}$ – Integer
Input

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

5:
$\mathbf{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:
$\mathbf{y}\left({\mathbf{ngrps}}\right)$ – Real (Kind=nag_wp) array
Output

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:
$\mathbf{mean}\left({\mathbf{ngrps}}\right)$ – Real (Kind=nag_wp) array
Output

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:
$\mathbf{ifail}$ – Integer
Input/Output

On entry:
ifail must be set to
$0$,
$1\text{or}1$. If you are unfamiliar with this argument you should refer to
Section 4 in the Introduction to the NAG Library FL Interface 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 argument, 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}}=0$ or
$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{m}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{m}}\ge 2$.
On entry, ${\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$, ${\mathbf{m}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{ngrps}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{ngrps}}=\mathrm{int}{\mathbf{n}}/{\mathbf{m}}$.
On entry, ${\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{m}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{n}}\ge {\mathbf{m}}$.
 ${\mathbf{ifail}}=2$

On entry, ${\mathbf{rs}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{rs}}=\text{'R'}$ or $\text{'S'}$.
 ${\mathbf{ifail}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 7 in the Introduction to the NAG Library FL Interface for further information.
 ${\mathbf{ifail}}=399$
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library FL Interface for further information.
 ${\mathbf{ifail}}=999$
Dynamic memory allocation failed.
See
Section 9 in the Introduction to the NAG Library FL Interface for further information.
7
Accuracy
The computations are believed to be stable.
8
Parallelism and Performance
g13auf is not threaded in any implementation.
The time taken by g13auf is approximately proportional to $n$.
10
Example
The following program produces the statistics for a rangemean plot for a series of $100$ observations divided into groups of $8$.
10.1
Program Text
10.2
Program Data
10.3
Program Results