# NAG CL Interfaceg13amc (uni_​smooth_​exp)

Settings help

CL Name Style:

## 1Purpose

g13amc performs exponential smoothing using either single exponential, double exponential or a Holt–Winters method.

## 2Specification

 #include
 void g13amc (Nag_InitialValues mode, Nag_ExpSmoothType itype, Integer p, const double param[], Integer n, const double y[], Integer k, double init[], Integer nf, double fv[], double fse[], double yhat[], double res[], double *dv, double *ad, double r[], NagError *fail)
The function may be called by the names: g13amc, nag_tsa_uni_smooth_exp or nag_tsa_exp_smooth.

## 3Description

Exponential smoothing is a relatively simple method of short term forecasting for a time series. g13amc provides five types of exponential smoothing; single exponential, Brown's double exponential, linear Holt (also called double exponential smoothing in some references), additive Holt–Winters and multiplicative Holt–Winters. The choice of smoothing method used depends on the characteristics of the time series. If the mean of the series is only slowly changing then single exponential smoothing may be suitable. If there is a trend in the time series, which itself may be slowly changing, then double exponential smoothing may be suitable. If there is a seasonal component to the time series, e.g., daily or monthly data, then one of the two Holt–Winters methods may be suitable.
For a time series ${y}_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,n$, the five smoothing functions are defined by the following:
• Single Exponential Smoothing
 $mt = α yt + (1-α) mt-1 y^t+f = mt var(y^t+f) = var(εt) (1+(f-1)α2)$
• Brown Double Exponential Smoothing
 $mt = α yt + (1-α) mt-1 rt = α (mt-mt-1) + (1-α) rt-1 y^ t+f = mt + ((f-1)+1/α) rt var( y^ t+f ) = var(εt) (1+∑ i=0 f-1 (2α+(i-1)α2) 2 )$
• Linear Holt Smoothing
 $mt = α yt + (1-α) (mt-1+ϕrt-1) rt = γ (mt-mt-1) + (1-γ) ϕ rt-1 y^ t+f = mt + ∑ i=1 f ϕi rt var( y^ t+f ) = var(εt) (1+∑ i=1 f-1 (α+ α γ ϕ (ϕi-1) (ϕ-1) ) 2 )$
• Multiplicative Holt–Winters Smoothing
 $mt = α yt / s t-p + (1-α) ( m t-1 +ϕ r t-1 ) rt = γ (mt- m t-1 ) + (1-γ) ϕ r t-1 st = β yt / mt + (1-β) s t-p y^ t+f = (mt+∑ i=1 f ϕirt) × s t-p var( y^ t+f) = var(εt) (∑ i=0 ∞ ∑ j=0 p-1 ( ψ j+ip s t+f s t+f-j ) 2 )$
and $\psi$ is defined as in the additive Holt–Winters smoothing,
where ${m}_{t}$ is the mean, ${r}_{t}$ is the trend and ${s}_{t}$ is the seasonal component at time $t$ with $p$ being the seasonal order. The $f$-step ahead forecasts are given by ${\stackrel{^}{y}}_{t+f}$ and their variances by $\mathrm{var}\left({\stackrel{^}{y}}_{t+f}\right)$. The term $\mathrm{var}\left({\epsilon }_{t}\right)$ is estimated as the mean deviation.
The parameters, $\alpha$, $\beta$ and $\gamma$ control the amount of smoothing. The nearer these parameters are to one, the greater the emphasis on the current data point. Generally these parameters take values in the range $0.1$ to $0.3$. The linear Holt and two Holt–Winters smoothers include an additional parameter, $\varphi$, which acts as a trend dampener. For $0.0<\varphi <1.0$ the trend is dampened and for $\varphi >1.0$ the forecast function has an exponential trend, $\varphi =0.0$ removes the trend term from the forecast function and $\varphi =1.0$ does not dampen the trend.
For all methods, values for $\alpha$, $\beta$, $\gamma$ and $\psi$ can be chosen by trying different values and then visually comparing the results by plotting the fitted values along side the original data. Alternatively, for single exponential smoothing a suitable value for $\alpha$ can be obtained by fitting an $\mathrm{ARIMA}\left(0,1,1\right)$ model (see g13bec). For Brown's double exponential smoothing and linear Holt smoothing with no dampening, (i.e., $\varphi =1.0$), suitable values for $\alpha$ and $\gamma$ can be obtained by fitting an $\mathrm{ARIMA}\left(0,2,2\right)$ model. Similarly, the linear Holt method, with $\varphi \ne 1.0$, can be expressed as an $\mathrm{ARIMA}\left(1,2,2\right)$ model and the additive Holt–Winters, with no dampening, ($\varphi =1.0$), can be expressed as a seasonal ARIMA model with order $p$ of the form $\mathrm{ARIMA}\left(0,1,p+1\right)\left(0,1,0\right)$. There is no similar procedure for obtaining parameter values for the multiplicative Holt–Winters method, or the additive Holt–Winters method with $\varphi \ne 1.0$. In these cases parameters could be selected by minimizing a measure of fit using one of the nonlinear optimization functions in Chapter E04.
In addition to values for $\alpha$, $\beta$, $\gamma$ and $\psi$, initial values, ${m}_{0}$, ${r}_{0}$ and ${s}_{-\mathit{j}}$, for $\mathit{j}=0,1,\dots ,p-1$, are required to start the smoothing process. You can either supply these or they can be calculated by g13amc from the first $k$ observations. For single exponential smoothing the mean of the observations is used to estimate ${m}_{0}$. For Brown double exponential smoothing and linear Holt smoothing, a simple linear regression is carried out with the series as the dependent variable and the sequence $1,2,\dots ,k$ as the independent variable. The intercept is then used to estimate ${m}_{0}$ and the slope to estimate ${r}_{0}$. In the case of the additive Holt–Winters method, the same regression is carried out, but a separate intercept is used for each of the $p$ seasonal groupings. The slope gives an estimate for ${r}_{0}$ and the mean of the $p$ intercepts is used as the estimate of ${m}_{0}$. The seasonal parameters ${s}_{-\mathit{j}}$, for $\mathit{j}=0,1,\dots ,p-1$, are estimated as the $p$ intercepts – ${m}_{0}$. A similar approach is adopted for the multiplicative Holt–Winter's method.
One step ahead forecasts, ${\stackrel{^}{y}}_{t+1}$ are supplied along with the residuals computed as $\left({y}_{t+1}-{\stackrel{^}{y}}_{t+1}\right)$. In addition, two measures of fit are provided. The mean absolute deviation,
 $1 n ∑ t=1 n |yt- y^ t |$
and the square root of the mean deviation
 $1 n ∑ t=1 n (yt- y^ t ) 2 .$

## 4References

Chatfield C (1980) The Analysis of Time Series Chapman and Hall

## 5Arguments

1: $\mathbf{mode}$Nag_InitialValues Input
On entry: indicates if g13amc is continuing from a previous call or, if not, how the initial values are computed.
${\mathbf{mode}}=\mathrm{Nag_InitialValuesSupplied}$
Required values for ${m}_{0}$, ${r}_{0}$ and ${s}_{-\mathit{j}}$, for $\mathit{j}=0,1,\dots ,p-1$, are supplied in init.
${\mathbf{mode}}=\mathrm{Nag_ContinueAndUpdate}$
g13amc continues from a previous call using values that are supplied in r.
${\mathbf{mode}}=\mathrm{Nag_EstimateInitialValues}$
Required values for ${m}_{0}$, ${r}_{0}$ and ${s}_{-\mathit{j}}$, for $\mathit{j}=0,1,\dots ,p-1$, are estimated using the first $k$ observations.
Constraint: ${\mathbf{mode}}=\mathrm{Nag_InitialValuesSupplied}$, $\mathrm{Nag_ContinueAndUpdate}$ or $\mathrm{Nag_EstimateInitialValues}$.
2: $\mathbf{itype}$Nag_ExpSmoothType Input
On entry: the smoothing function.
${\mathbf{itype}}=\mathrm{Nag_SingleExponential}$
Single exponential.
${\mathbf{itype}}=\mathrm{Nag_BrownsExponential}$
Brown double exponential.
${\mathbf{itype}}=\mathrm{Nag_LinearHolt}$
Linear Holt.
${\mathbf{itype}}=\mathrm{Nag_AdditiveHoltWinters}$
${\mathbf{itype}}=\mathrm{Nag_MultiplicativeHoltWinters}$
Multiplicative Holt–Winters.
Constraint: ${\mathbf{itype}}=\mathrm{Nag_SingleExponential}$, $\mathrm{Nag_BrownsExponential}$, $\mathrm{Nag_LinearHolt}$, $\mathrm{Nag_AdditiveHoltWinters}$ or $\mathrm{Nag_MultiplicativeHoltWinters}$.
3: $\mathbf{p}$Integer Input
On entry: if ${\mathbf{itype}}=\mathrm{Nag_AdditiveHoltWinters}$ or $\mathrm{Nag_MultiplicativeHoltWinters}$, the seasonal order, $p$, otherwise p is not referenced.
Constraint: if ${\mathbf{itype}}=\mathrm{Nag_AdditiveHoltWinters}$ or $\mathrm{Nag_MultiplicativeHoltWinters}$, ${\mathbf{p}}>1$.
4: $\mathbf{param}\left[\mathit{dim}\right]$const double Input
Note: the dimension, dim, of the array param must be at least
• $1$, when ;
• $3$, when ${\mathbf{itype}}=\mathrm{Nag_LinearHolt}$;
• $4$, when .
On entry: the smoothing parameters.
If ${\mathbf{itype}}=\mathrm{Nag_SingleExponential}$ or $\mathrm{Nag_BrownsExponential}$, ${\mathbf{param}}\left[0\right]=\alpha$ and any remaining elements of param are not referenced.
If ${\mathbf{itype}}=\mathrm{Nag_LinearHolt}$, ${\mathbf{param}}\left[0\right]=\alpha$, ${\mathbf{param}}\left[1\right]=\gamma$, ${\mathbf{param}}\left[2\right]=\varphi$ and any remaining elements of param are not referenced.
If ${\mathbf{itype}}=\mathrm{Nag_AdditiveHoltWinters}$ or $\mathrm{Nag_MultiplicativeHoltWinters}$, ${\mathbf{param}}\left[0\right]=\alpha$, ${\mathbf{param}}\left[1\right]=\gamma$, ${\mathbf{param}}\left[2\right]=\beta$ and ${\mathbf{param}}\left[3\right]=\varphi$.
Constraints:
• if ${\mathbf{itype}}=\mathrm{Nag_SingleExponential}$, $0.0\le \alpha \le 1.0$;
• if ${\mathbf{itype}}=\mathrm{Nag_BrownsExponential}$, $0.0<\alpha \le 1.0$;
• if ${\mathbf{itype}}=\mathrm{Nag_LinearHolt}$, $0.0\le \alpha \le 1.0$ and $0.0\le \gamma \le 1.0$ and $\varphi \ge 0.0$;
• if ${\mathbf{itype}}=\mathrm{Nag_AdditiveHoltWinters}$ or $\mathrm{Nag_MultiplicativeHoltWinters}$, $0.0\le \alpha \le 1.0$ and $0.0\le \gamma \le 1.0$ and $0.0\le \beta \le 1.0$ and $\varphi \ge 0.0$.
5: $\mathbf{n}$Integer Input
On entry: the number of observations in the series.
Constraint: ${\mathbf{n}}\ge 0$.
6: $\mathbf{y}\left[{\mathbf{n}}\right]$const double Input
On entry: the time series.
7: $\mathbf{k}$Integer Input
On entry: if ${\mathbf{mode}}=\mathrm{Nag_EstimateInitialValues}$, the number of observations used to initialize the smoothing.
If ${\mathbf{mode}}\ne \mathrm{Nag_EstimateInitialValues}$, k is not referenced.
Constraints:
• if ${\mathbf{mode}}=\mathrm{Nag_EstimateInitialValues}$ and ${\mathbf{itype}}=\mathrm{Nag_AdditiveHoltWinters}$ or $\mathrm{Nag_MultiplicativeHoltWinters}$, $2×{\mathbf{p}}\le {\mathbf{k}}\le {\mathbf{n}}$;
• if ${\mathbf{mode}}=\mathrm{Nag_EstimateInitialValues}$ and ${\mathbf{itype}}=\mathrm{Nag_SingleExponential}$, $\mathrm{Nag_BrownsExponential}$ or $\mathrm{Nag_LinearHolt}$, $1\le {\mathbf{k}}\le {\mathbf{n}}$.
8: $\mathbf{init}\left[\mathit{dim}\right]$double Input/Output
Note: the dimension, dim, of the array init must be at least
• $1$, when ${\mathbf{itype}}=\mathrm{Nag_SingleExponential}$;
• $2$, when ;
• $2+{\mathbf{p}}$, when .
On entry: if ${\mathbf{mode}}=\mathrm{Nag_InitialValuesSupplied}$, the initial values for ${m}_{0}$, ${r}_{0}$ and ${s}_{-\mathit{j}}$, for $\mathit{j}=0,1,\dots ,p-1$, used to initialize the smoothing.
If ${\mathbf{itype}}=\mathrm{Nag_SingleExponential}$, ${\mathbf{init}}\left[0\right]={m}_{0}$ and the remaining elements of init are not referenced.
If ${\mathbf{itype}}=\mathrm{Nag_BrownsExponential}$ or $\mathrm{Nag_LinearHolt}$, ${\mathbf{init}}\left[0\right]={m}_{0}$ and ${\mathbf{init}}\left[1\right]={r}_{0}$ and the remaining elements of init are not referenced.
If ${\mathbf{itype}}=\mathrm{Nag_AdditiveHoltWinters}$ or $\mathrm{Nag_MultiplicativeHoltWinters}$, ${\mathbf{init}}\left[0\right]={m}_{0}$, ${\mathbf{init}}\left[1\right]={r}_{0}$ and ${\mathbf{init}}\left[2\right]$ to ${\mathbf{init}}\left[p+1\right]$ hold the values for ${s}_{-\mathit{j}}$, for $\mathit{j}=0,1,\dots ,p-1$. The remaining elements of init are not referenced.
On exit: if ${\mathbf{mode}}\ne \mathrm{Nag_ContinueAndUpdate}$, the values used to initialize the smoothing. These are in the same order as described above.
9: $\mathbf{nf}$Integer Input
On entry: the number of forecasts required beyond the end of the series. Note, the one step ahead forecast is always produced.
Constraint: ${\mathbf{nf}}\ge 0$.
10: $\mathbf{fv}\left[{\mathbf{nf}}\right]$double Output
On exit: ${\stackrel{^}{y}}_{t+\mathit{f}}$, for $\mathit{f}=1,2,\dots ,{\mathbf{nf}}$, the next nf step forecasts. Where $t={\mathbf{n}}$, if ${\mathbf{mode}}\ne \mathrm{Nag_ContinueAndUpdate}$, else $t$ is the total number of smoothed and forecast values already produced.
11: $\mathbf{fse}\left[{\mathbf{nf}}\right]$double Output
On exit: the forecast standard errors for the values given in fv.
12: $\mathbf{yhat}\left[{\mathbf{n}}\right]$double Output
On exit: ${\stackrel{^}{y}}_{\mathit{t}+1}$, for $\mathit{t}=1,2,\dots ,{\mathbf{n}}$, the one step ahead forecast values, with ${\mathbf{yhat}}\left[i-1\right]$ being the one step ahead forecast of ${\mathbf{y}}\left[i-2\right]$.
13: $\mathbf{res}\left[{\mathbf{n}}\right]$double Output
On exit: the residuals, $\left({y}_{\mathit{t}+1}-{\stackrel{^}{y}}_{\mathit{t}+1}\right)$, for $\mathit{t}=1,2,\dots ,{\mathbf{n}}$.
14: $\mathbf{dv}$double * Output
On exit: the square root of the mean deviation.
On exit: the mean absolute deviation.
16: $\mathbf{r}\left[\mathit{dim}\right]$double Communication Array
Note: the dimension, dim, of the array r must be at least
• $13$, when ;
• $13+{\mathbf{p}}$, when .
On entry: if ${\mathbf{mode}}=\mathrm{Nag_ContinueAndUpdate}$, r must contain the values as returned by a previous call to g05pmc or g13amc, r need not be set otherwise.
If ${\mathbf{itype}}=\mathrm{Nag_SingleExponential}$, $\mathrm{Nag_BrownsExponential}$ or $\mathrm{Nag_LinearHolt}$, only the first $13$ elements of r are referenced, otherwise the first $13+p$ elements are referenced.
On exit: the information on the current state of the smoothing.
Constraint: if ${\mathbf{mode}}=\mathrm{Nag_ContinueAndUpdate}$, r must have been initialized by at least one previous call to g05pmc or g13amc with ${\mathbf{mode}}\ne \mathrm{Nag_ContinueAndUpdate}$, and r should not have been changed since the last call to g05pmc or g13amc.
17: $\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_ENUM_INT
On entry, ${\mathbf{p}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{itype}}=\mathrm{Nag_AdditiveHoltWinters}$ or $\mathrm{Nag_MultiplicativeHoltWinters}$, ${\mathbf{p}}>1$.
NE_INT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 0$.
On entry, ${\mathbf{nf}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nf}}\ge 0$.
NE_INT_2
On entry, ${\mathbf{k}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{mode}}=\mathrm{Nag_EstimateInitialValues}$ and ${\mathbf{itype}}=\mathrm{Nag_AdditiveHoltWinters}$ or $\mathrm{Nag_MultiplicativeHoltWinters}$, $1\le {\mathbf{k}}\le {\mathbf{n}}$.
NE_INT_3
On entry, ${\mathbf{k}}=⟨\mathit{\text{value}}⟩$, $2×{\mathbf{p}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{mode}}=\mathrm{Nag_EstimateInitialValues}$ and ${\mathbf{itype}}=\mathrm{Nag_AdditiveHoltWinters}$ or $\mathrm{Nag_MultiplicativeHoltWinters}$, $2×{\mathbf{p}}\le {\mathbf{k}}$.
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_MODEL_PARAMS
A multiplicative Holt–Winters model cannot be used with the supplied data.
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.
NE_REAL_ARRAY
On entry, ${\mathbf{param}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: $0.0\le {\mathbf{param}}\left[⟨\mathit{\text{value}}⟩\right]\le 1.0$.
On entry, ${\mathbf{param}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{itype}}=\mathrm{Nag_BrownsExponential}$, $0.0<{\mathbf{param}}\left[⟨\mathit{\text{value}}⟩\right]\le 1.0$.
On entry, ${\mathbf{param}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{param}}\left[⟨\mathit{\text{value}}⟩\right]\ge 0.0$.
On entry, the array r has not been initialized correctly.

Not applicable.

## 8Parallelism and Performance

g13amc is not threaded in any implementation.

Single exponential, Brown's double exponential and linear Holt smoothing methods are stable, whereas the two Holt–Winters methods can be affected by poor initial values for the seasonal components.

## 10Example

This example smooths a time series relating to the rate of the earth's rotation about its polar axis.

### 10.1Program Text

Program Text (g13amce.c)

### 10.2Program Data

Program Data (g13amce.d)

### 10.3Program Results

Program Results (g13amce.r)