Performs a harmonic analysis of a univariate time series (G. Tunnicliffe Wilson & R.P. Littlejohn).

### Options

`PRINT` = string tokens |
Controls printed output (`accumulated` , `means` , `tsm` ); default `*` |
---|---|

`PLOT` = string tokens |
What to plot (`periodogram` , `harmonics` , `means` , `residuals` , `cumulative` , `range` ); default `peri` , `harm` , `mean` , `resid` |

`MODELTYPE` = string token |
What harmonic regression model to fit (`none` , `best` , `full` ); default `none` |

`GROUPS` = factor |
Groups for plot of means |

`ORDER` = variate |
Order for time series model; default `!(1,0,0)` |

`COLOURS` = text or variate |
Colour for each level of `GROUPS` |

`FACSHORTCYCLE` = factor |
Factor giving levels of the short cycle |

`NCOMPONENTS` = scalar |
Number of nested cycles, must be 0, 1, or 2; default 0 |

`SHORTCYCLE ` = scalar |
Length of the short cycle; default 24 |

`LONGCYCLE` = scalar |
Length of the long cycle; default 365.225 |

`LABSHORTCYCLE` = text |
Label for the short cycle; default `'daily'` |

`LABLONGCYCLE` = text |
Label for the long cycle; default `'annual'` |

`NHSHORTCYCLE` = scalar |
Number of harmonics for the short cycle; default 5 |

`NHLONGCYCLE` = scalar |
Number of harmonics for the long cycle; default 3 |

`RANGE` = variate |
Variate with two values, defining the frequency range within [0,0.5] to draw a portion of the periodogram |

### Parameters

`DATA` = variates |
Time series |
---|---|

`PERIODOGRAM` = variates |
Saves the periodogram of `DATA` |

`FREQUENCY` = variates |
Saves the frequencies at which the periodogram is calculated |

`MEANS` = tables |
Saves the table of means of the fitted model for each value of `FACSHORTCYCLE` by each level of `GROUPS` |

`RESIDUALS` = variates |
Saves the residuals from the fitted model |

`FITTEDVALUES` = variates |
Saves the fitted values from the model |

### Description

`DFOURIER`

performs a harmonic analysis for a univariate time series which is supplied, in a variate, by the `DATA`

parameter. In its basic form, it can produce 3 pages of graphs to study the series. These graphs are all controlled by the `PLOT`

option. Setting `PLOT=periodogram`

produces a page of graphs showing the time series, its periodogram and its log periodogram. The frequencies for the periodogram are calculated internally, and noted in the output. These can be saved, in a variate, by the `FREQUENCY`

parameters, and the `PERIODOGRAM`

parameter can save the periodogram. The `cumulative`

setting of `PLOT`

plots the cumulative periodogram (on a separate page), and the `range`

setting plots the periodogram over the range specified by the `RANGE`

option (this must be a value within [0,0.5]).

Other graphs are useful if you anticipate that the series will show some specific components. The number of these components is specified by the `NCOMPONENTS`

option, and may be either 0 (no components, the default), 1 (a “short” cycle) or 2 (a “short” and a “long” cycle). The lengths of the long and short cycles are specified by the `LONGCYCLE`

and `SHORTCYCLE`

options, respectively. The defaults 365.225 and 24, correspond to hourly measurement of annual and daily cycles. The `LABLONGCYCLE`

and `LABSHORTCYCLE`

options supply labels for these cycles for the plots, with defaults of `'annual'`

and `'daily'`

respectively.

The components are particularly useful for analysing meterological time series (such as air temperatures) measured hourly over several years, where you want to describe how the diurnal pattern varies throughout the year. A single (non-sinusoidal) periodic component with period *p* (e.g. *p* = 24 for hourly observations) produces a main spike in the periodogram at the frequency *f* = 1/*p*, followed by a series of diminishing spikes at integer multiples of *f* known as *harmonics*.

When there are two periodic components with interacting rhythms, signals are observed in the periodogram not only at harmonics of each frequency, but at integer differences of the lower frequency from the higher. Thus, if hourly and annual frequencies are denoted by *f _{d}* and

*f*, spikes may be observed in the periodogram at

_{a}*f _{da}* =

*n*×

*f*+

_{d}*m*×

*f*,

_{a}where *n* is a non-negative integer, and *m* is an integer, which must be positive when *n* is zero.

These spikes generated by the interaction are generally hard to discern in an ordinary graph of the periodogram. The `harmonic`

setting of `PLOT`

produces a trellis plot that zooms in on a narrow range of about *n* × *f _{d}*, for integer values of

*n*ranging from 1 up to a value defined by the

`NHSHORTCYCLE`

option. This can be set to either 5 (default), 7 or 8, producing respectively a 3 × 2, 4 × 2 or 3 × 3 array of graphs. The `NHLONGCYCLE`

option specifies the number of vertical lines to be drawn, within each graph, at positions corresponding to differences due to the long cycle. This can be set to 0, 1, 2 or 3 (default). It should be set to 0 if there is only one periodicity in the sampling protocol. The y-axes of the plots are scaled individually to a suitable order of magnitude, which is denoted in each graph. The frequency range for each panel is*n* × *f _{d}* +/- 5.1 ×

*f*.

_{a}The `MODELTYPE`

option allows a harmonic regression analysis to be conducted on `DATA`

. The setting `full`

fits sine and cosine terms for each frequency indicated in the harmonics graph. Alternatively, the setting `best`

fits the full model and then drops terms that are non-significant at the 5% level. This does not guarantee that all terms remaining in the model are necessarily significant at the 5% level. In practice, however, dropping these additional terms will usually make little difference to the fitted model or residual variance. The accumulated setting of the `PRINT`

option prints the accumulated analysis of deviance table from the fit.

With the `tsm`

setting of the `PRINT`

option, the model fitted as above is then used as the `TRANSFERFUNCTION`

in a time series analysis of `DATA`

. The `TSM`

is defined by the `ORDER`

option; by default this is set to a first-order autoregression (i.e. `ORDER=!(1,0,0)`

). Note that this may take a long time to fit if there are many missing values in the data.

The fitted values and residuals from the final model (`tsm`

is fitted after `best`

, which is fitted after `full`

) can be saved by the `FITTEDVALUES`

and `RESIDUALS`

parameters. The `residuals`

setting of `PLOT`

produces time-series plots of the residuals, from the `BJIDENTIFY`

procedure.

`DFOURIER`

forms tables of means of the fitted values classified by the the short cycle component and another factor, specified by the `GROUPS`

option. You can supply the short cycle factor using the `FACSHORTCYCLE`

option; this must have `SHORTCYCLE`

levels or a fault will be generated. If `FACSHORTCYCLE`

is unset, the required factor will be internally generated with levels 1…`SHORTCYCLE`

. The factor `GROUPS`

may, for example, be month or season. The `SHORTCYCLE`

factor should be nested within `GROUPS`

to provide meaningful output, but no checks are carried out on this.

You can plot the means using the `means`

setting of the `PLOT`

option. The points in each group are plotted in different colours, and you can supply these using the `COLOURS`

option. If `COLOURS`

is unset, the colours are set by default. If `GROUPS`

has 4 levels, it is assumed they correspond to season, and pens 1 to 4 are defined to be red, gold, blue and green, corresponding to summer, autumn, winter and spring. If `GROUPS`

has 12 levels, it is assumed that they correspond to months, and pens 1 to 12 are given decreasing intensities within the seasonal shades in clusters of three. Thus pens 1 to 3 are given crimson, red and salmon for the summer months. Note that this is tuned to a southern hemisphere calendar.

Options: `PRINT`

, `PLOT`

, `MODELTYPE`

, `GROUPS`

, `ORDER`

, `COLOURS`

, `FACSHORTCYCLE`

, `NCOMPONENTS`

, `SHORTCYCLE`

, `LONGCYCLE`

, `LABSHORTCYCLE`

, `LABLONGCYCLE`

, `NHSHORTCYCLE`

, `NHLONGCYCLE`

, `RANGE`

.

Parameters: `DATA`

, `PERIODOGRAM`

, `FREQUENCY`

, `MEANS`

, `RESIDUALS`

, `FITTEDVALUES`

.

### Action with `RESTRICT`

There must not be any restrictions.

### See also

Directive: `FOURIER`

.

Procedures: `MCROSSPECTRUM`

, `PERIODTEST`

, `PREWHITEN`

, `REPPERIODOGRAM`

, `SMOOTHSPECTRUM`

.

Commands for: Time series.

### Example

CAPTION 'DFOURIER example',\ !t('Data hourly temperatures at Tara Base',\ 'courtesy of Alison Rutherford.'); STYLE=meta,plain IMPORT '%gendir%/examples/DFOU-1.gsh' DFOURIER [PRINT=accumulated,means; MODELTYPE=best;\ PLOT=periodogram,harmonics,means,residuals,cumulative,range;\ GROUPS=season; FACSHORT=hour; NCOMPONENTS=2; NHSHORTCYCLE=5;\ NHLONGCYCLE=2; RANGE=!(0.13,0.225)] TB