PDF version (NAG web site
, 64-bit version, 64-bit version)
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
Description
Let denote successive observations in a time series. The series may be divided into groups of successive values and for each group the range or standard deviation (depending on a user-supplied option) and the mean are calculated. If is not a multiple of then groups of equal size 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, , is the integer part of . If you wish to ensure that no observations are ignored then the number of observations, , should be chosen so that is divisible by .
The mean,
, the range,
, and the standard deviation,
, for the
th group are defined as
and
where
, the number of observations ignored.
For seasonal data it is recommended that should be equal to the seasonal period. For non-seasonal data the recommended group size is .
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., 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:
– double array
-
must contain the th observation , for .
- 2:
– int64int32nag_int scalar
-
, the group size.
Constraint:
.
- 3:
– string (length ≥ 1)
-
Indicates whether ranges or standard deviations are to be calculated.
- Ranges are calculated.
- Standard deviations are calculated.
Constraint:
or .
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
z.
, the number of observations in the time series.
Constraint:
.
Output Parameters
- 1:
– double array
-
.
contains the range or standard deviation, as determined by
rs, of the
th group of observations, for
.
- 2:
– double array
-
.
contains the mean of the th group of observations, for .
- 3:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
On entry, | , |
or | , |
or | integer part of . |
-
-
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.
Accuracy
The computations are believed to be stable.
Further Comments
The time taken by nag_tsa_uni_means (g13au) is approximately proportional to .
Example
The following program produces the statistics for a range-mean plot for a series of observations divided into groups of .
Open in the MATLAB editor:
g13au_example
function g13au_example
fprintf('g13au example results\n\n');
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);
fprintf(' Mean Range\n');
fprintf(' -------------------\n');
fprintf('%11.3f%11.3f\n', [mean_p y]');
fig1 = figure;
plot(mean_p,y,'+','Color','Red');
xlabel('Mean');
ylabel('Range');
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)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015