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)

Purpose

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.

Syntax

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

Description

Let Z1,Z2,,ZnZ1,Z2,,Zn denote nn successive observations in a time series. The series may be divided into groups of mm successive values and for each group the range or standard deviation (depending on a user-supplied option) and the mean are calculated. If nn is not a multiple of mm then groups of equal size mm 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, kk, is the integer part of n / mn/m. If you wish to ensure that no observations are ignored then the number of observations, nn, should be chosen so that nn is divisible by mm.
The mean, MiMi, the range, RiRi, and the standard deviation, SiSi, for the iith group are defined as
Mi = 1/mj = 1mZl + m(i1) + j
Ri = max1jm{Zl + m(i1) + j}min1jm{Zl + m(i1) + j}
Mi=1mj=1mZl+m(i-1)+j Ri=max1jm{Zl+m(i-1)+j}-min1jm{Zl+m(i-1)+j}
and
Si = sqrt( (1/(m 1)) j = 1m(Zl + m(i1) + jMi)2 )
Si= (1m- 1 ) j= 1m(Zl+m(i- 1)+j-Mi)2
where l = nkml=n-km, the number of observations ignored.
For seasonal data it is recommended that mm should be equal to the seasonal period. For non-seasonal data the recommended group size is 88.
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 = 12m=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, Lancaster
McLeod G (1982) Box–Jenkins in Practice. 1: Univariate Stochastic and Single Output Transfer Function/Noise Analysis GJP Publications, Lancaster

Parameters

Compulsory Input Parameters

1:     z(n) – double array
n, the dimension of the array, must satisfy the constraint nmnm.
z(t)zt must contain the ttth observation ZtZt, for t = 1,2,,nt=1,2,,n.
2:     m – int64int32nag_int scalar
mm, the group size.
Constraint: m2m2.
3:     rs – string (length ≥ 1)
Indicates whether ranges or standard deviations are to be calculated.
rs = 'R'rs='R'
Ranges are calculated.
rs = 'S'rs='S'
Standard deviations are calculated.
Constraint: rs = 'R'rs='R' or 'S''S'.

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array z.
nn, the number of observations in the time series.
Constraint: nmnm.

Input Parameters Omitted from the MATLAB Interface

ngrps

Output Parameters

1:     y(ngrps) – double array
ngrps = int(n / m)ngrps=int(n/m).
y(i)yi contains the range or standard deviation, as determined by rs, of the iith group of observations, for i = 1,2,,ki=1,2,,k.
2:     mean(ngrps) – double array
ngrps = int(n / m)ngrps=int(n/m).
mean(i)meani contains the mean of the iith group of observations, for i = 1,2,,ki=1,2,,k.
3:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,n < mn<m,
orm < 2m<2,
orngrpsngrps integer part of n / mn/m.
  ifail = 2ifail=2
On entry,rs is not equal to 'R' or 'S'.

Accuracy

The computations are believed to be stable.

Further Comments

The time taken by nag_tsa_uni_means (g13au) is approximately proportional to nn.
If you wish to obtain a plot of the group ranges or standard deviations against the group means then nag_stat_plot_scatter_2var (g01ag) may be used. The plot is output to the unit defined by nag_file_set_unit_advisory (x04ab). You should note that nag_stat_plot_scatter_2var (g01ag) sorts the data to be plotted on the yy axis (in this case the ranges or standard deviations). If required you may use nag_sort_realvec_rank_rearrange (m01ea) to re-arrange the data into their original order.

Example

function nag_tsa_uni_means_example
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];
m = int64(8);
rs = 'RANGE';
[y, mean_p, ifail] = nag_tsa_uni_means(z, m, rs)
 

y =

   148
   123
    84
    45
    28
    40
    65
   131
    92
    85
    92
    67


mean_p =

   72.3750
   70.0000
   43.5000
   29.7500
    7.6250
   26.7500
   30.2500
   61.0000
   47.6250
   75.2500
   46.8750
   39.2500


ifail =

                    0


function g13au_example
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];
m = int64(8);
rs = 'RANGE';
[y, mean_p, ifail] = g13au(z, m, rs)
 

y =

   148
   123
    84
    45
    28
    40
    65
   131
    92
    85
    92
    67


mean_p =

   72.3750
   70.0000
   43.5000
   29.7500
    7.6250
   26.7500
   30.2500
   61.0000
   47.6250
   75.2500
   46.8750
   39.2500


ifail =

                    0



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–2013