hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_tsa_uni_means (g13au)


    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example


nag_tsa_uni_means (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.


[y, mean_p, ifail] = g13au(z, m, rs, 'n', n)
[y, mean_p, ifail] = nag_tsa_uni_means(z, m, rs, 'n', n)


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+mi-1+j Ri=max1jmZl+mi-1+j-min1jmZl+mi-1+j  
Si= 1m- 1 j= 1mZl+mi- 1+j-Mi2  
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.


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


Compulsory Input Parameters

1:     zn – double array
zt must contain the tth observation Zt, for t=1,2,,n.
2:     m int64int32nag_int scalar
m, the group size.
Constraint: m2.
3:     rs – string (length ≥ 1)
Indicates whether ranges or standard deviations are to be calculated.
Ranges are calculated.
Standard deviations are calculated.
Constraint: rs='R' or 'S'.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the dimension of the array z.
n, the number of observations in the time series.
Constraint: nm.

Output Parameters

1:     yngrps – double array
yi contains the range or standard deviation, as determined by rs, of the ith group of observations, for i=1,2,,k.
2:     mean_pngrps – double array
mean_pi contains the mean of the ith group of observations, for i=1,2,,k.
3:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
On entry,n<m,
orngrps integer part of n/m.
On entry,rs is not equal to 'R' or 'S'.
An unexpected error has been triggered by this routine. Please contact NAG.
Your licence key may have expired or may not have been installed correctly.
Dynamic memory allocation failed.


The computations are believed to be stable.

Further Comments

The time taken by nag_tsa_uni_means (g13au) is approximately proportional to n.


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

fprintf('g13au example results\n\n');

% Data
z = [101;  82;  66;  35;  31;   6;  20;  90; 154; 125;
      85;  68;  38;  23;  10;  24;  83; 133; 131; 118;
      90;  67;  60;  47;  41;  21;  16;   6;   4;   7;
      14;  34;  45;  43;  49;  42;  28;  10;   5;   2;
       0;   1;   3;  12;  14;  35;  47;  41;  30;  24;
      16;   7;   4;   2;   8;  13;  36;  50;  62;  67;
      72;  48;  29;   8;  13;  57; 122; 139; 103;  86;
      63;  37;  26;  11;  15;  40;  62;  98; 124;  96;
      65;  64;  54;  39;  21;   7;   4;  23;  53;  94;
      96;  77;  59;  44;  47;  30;  16;   7;  37;  74];

% Number of groups
m = int64(8);

% Calculate summary statistic
rs = 'RANGE';
[y, mean_p, ifail] = g13au( ...
                            z, m, rs);

% Display results
fprintf('     Mean      Range\n');
fprintf('   -------------------\n');
fprintf('%11.3f%11.3f\n', [mean_p y]');

fig1 = figure;
title('Plot of Range vs Mean (Y vs Mean)');

g13au example results

     Mean      Range
     72.375    148.000
     70.000    123.000
     43.500     84.000
     29.750     45.000
      7.625     28.000
     26.750     40.000
     30.250     65.000
     61.000    131.000
     47.625     92.000
     75.250     85.000
     46.875     92.000
     39.250     67.000

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015