# NAG CL Interfaceg13auc (uni_​means)

## 1Purpose

g13auc 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.

## 2Specification

 #include
 void g13auc (Integer n, const double z[], Integer m, Nag_RangeStat rs, double y[], double mean[], NagError *fail)
The function may be called by the names: g13auc, nag_tsa_uni_means or nag_tsa_mean_range.

## 3Description

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 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, ${M}_{i}$, the range, ${R}_{i}$, and the standard deviation, ${S}_{i}$, for the $i$th group are defined as
 $Mi=1m∑j=1mZl+mi-1+j Ri=max1≤j≤mZl+mi-1+j-min1≤j≤mZl+mi-1+j$
and
 $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

## 5Arguments

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]$const double Input
On entry: ${\mathbf{z}}\left[\mathit{t}-1\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{rs}$Nag_RangeStat Input
On entry: indicates whether ranges or standard deviations are to be calculated.
${\mathbf{rs}}=\mathrm{Nag_UseRange}$
Ranges are calculated.
${\mathbf{rs}}=\mathrm{Nag_UseSD}$
Standard deviations are calculated.
Constraint: ${\mathbf{rs}}=\mathrm{Nag_UseRange}$ or $\mathrm{Nag_UseSD}$.
5: $\mathbf{y}\left[\mathit{dim}\right]$double Output
On exit: ${\mathbf{y}}\left[\mathit{i}-1\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$.
6: $\mathbf{mean}\left[\mathit{dim}\right]$double Output
On exit: ${\mathbf{mean}}\left[\mathit{i}-1\right]$ contains the mean of the $\mathit{i}$th group of observations, for $\mathit{i}=1,2,\dots ,k$.
7: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m}}\ge 2$.
NE_INT_2
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$ and ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge {\mathbf{m}}$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.

## 7Accuracy

The computations are believed to be stable.

## 8Parallelism and Performance

g13auc is not threaded in any implementation.

The time taken by g13auc is approximately proportional to $n$.

## 10Example

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

### 10.1Program Text

Program Text (g13auce.c)

### 10.2Program Data

Program Data (g13auce.d)

### 10.3Program Results

Program Results (g13auce.r)