NAG FL Interface
g13auf (uni_​means)

Settings help

FL Name Style:


FL Specification Language:


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 range-mean plots.

2 Specification

Fortran Interface
Subroutine g13auf ( n, z, m, ngrps, rs, y, mean, ifail)
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)
The routine may be called by the names g13auf or nagf_tsa_uni_means.

3 Description

Let Z1,Z2,,Zn 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, Mi, the range, Ri, and the standard deviation, Si, for the ith group are defined as
Mi=1mj=1mZl+m(i-1)+j Ri=max1jm{Zl+m(i-1)+j}-min1jm{Zl+m(i-1)+j}  
and
Si= (1m- 1 ) j= 1m(Zl+m(i-1)+j-Mi)2  
where l=n-km, the number of observations ignored.
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.

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: n Integer Input
On entry: n, the number of observations in the time series.
Constraint: nm.
2: z(n) Real (Kind=nag_wp) array Input
On entry: z(t) must contain the tth observation Zt, for t=1,2,,n.
3: m Integer Input
On entry: m, the group size.
Constraint: m2.
4: ngrps Integer Input
On entry: k, the number of groups.
Constraint: ngrps=int(n/m).
5: rs Character(1) Input
On entry: indicates whether ranges or standard deviations are to be calculated.
rs='R'
Ranges are calculated.
rs='S'
Standard deviations are calculated.
Constraint: rs='R' or 'S'.
6: y(ngrps) Real (Kind=nag_wp) array Output
On exit: y(i) contains the range or standard deviation, as determined by rs, of the ith group of observations, for i=1,2,,k.
7: mean(ngrps) Real (Kind=nag_wp) array Output
On exit: mean(i) contains the mean of the ith group of observations, for i=1,2,,k.
8: ifail Integer Input/Output
On entry: ifail must be set to 0, -1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of -1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value -1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry 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:
ifail=1
On entry, m=value.
Constraint: m2.
On entry, n=value, m=value and ngrps=value.
Constraint: ngrps=intn/m.
On entry, n=value and m=value.
Constraint: nm.
ifail=2
On entry, rs=value.
Constraint: rs='R' or 'S'.
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.
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.
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.

9 Further Comments

The time taken by g13auf is approximately proportional to n.

10 Example

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

10.1 Program Text

Program Text (g13aufe.f90)

10.2 Program Data

Program Data (g13aufe.d)

10.3 Program Results

Program Results (g13aufe.r)
GnuplotProduced by GNUPLOT 4.6 patchlevel 3 20 40 60 80 100 120 140 160 0 10 20 30 40 50 60 70 80 Range Mean Example Program Plot of Range vs Mean (Y vs Mean) gnuplot_plot_1