# spec.ls: Estimate Spectral Density of an Irregularly Sampled Time... In cts: Continuous Time Autoregressive Models

## Description

The most commonly used method of computing the spectrum on unevenly spaced time series is periodogram analysis, see Lomb (1975) and Scargle (1982). The Lomb-Scargle method for unevenly spaced data is known to be a powerful tool to find, and test significance of, weak perriodic signals. The Lomb-Scargle periodogram possesses the same statistical properties of standard power spectra.

## Usage

 ```1 2 3``` ```spec.ls(x, y=NULL, spans = NULL, kernel = NULL, taper = 0.1, pad = 0, fast = TRUE, type = "lomb",demean = FALSE, detrend = TRUE, plot.it = TRUE, na.action = na.fail, ...) ```

## Arguments

 `x` two column data frame or matrix with the first column being the sampled time and the second column being the observations at the first column; otherwise `x` is a numeric vector of sampled time. `y` not used if `x` has two columns; otherwise `y` is a numeric vector of observations at sampled time `x`.the time at which `x` is observed `spans` vector of odd integers giving the widths of modified Daniell smoothers to be used to smooth the periodogram. `kernel` alternatively, a kernel smoother of class `"tskernel"`. `taper` proportion of data to taper. A split cosine bell taper is applied to this proportion of the data at the beginning and end of the series. `pad` proportion of data to pad. Zeros are added to the end of the series to increase its length by the proportion `pad`. `fast` logical; if `TRUE`, pad the series to a highly composite length. `type` Lomb-Scargle spectrum of Fourier transformation spectrum `demean` logical. If `TRUE`, subtract the mean of the series. `detrend` logical. If `TRUE`, remove a linear trend from the series. This will also remove the mean. `plot.it` plot the periodogram? `na.action` `NA` action function. `...` graphical arguments passed to `plotSpecLs`.

## Details

The raw Lomb-Scargle periodogram for irregularly sampled time series is not a consistent estimator of the spectral density, but adjacent values are asymptotically independent. Hence a consistent estimator can be derived by smoothing the raw periodogram, assuming that the spectral density is smooth.

The series will be automatically padded with zeros until the series length is a highly composite number in order to help the Fast Fourier Transform. This is controlled by the `fast` and not the `pad` argument.

The periodogram at zero is in theory zero as the mean of the series is removed (but this may be affected by tapering): it is replaced by an interpolation of adjacent values during smoothing, and no value is returned for that frequency.

## Value

A list object of class `"spec.ls"` with the following additional components:

 `kernel` The `kernel` argument, or the kernel constructed from `spans`. `df` The distribution of the spectral density estimate can be approximated by a chi square distribution with `df` degrees of freedom. `bandwidth` The equivalent bandwidth of the kernel smoother as defined by Bloomfield (1976, page 201). `taper` The value of the `taper` argument. `pad` The value of the `pad` argument. `detrend` The value of the `detrend` argument. `demean` The value of the `demean` argument.

The result is returned invisibly if `plot.it` is true.

## Note

This is 'slow' program and a fast program may use FFT, see (Press et al, 1992)

## Author(s)

Lomb-Scargle periodogram by Zhu Wang

## References

Bloomfield, P. (1976) Fourier Analysis of Time Series: An Introduction.Wiley.

Lomb, N. R. (1976) Least-squares frequency-analysis of unequally spaced data. Astrophysics and Space Science, 39,447-462

W. H. Press and S. A. Teukolsky and W. T. Vetterling and B.P. Flannery (1992) Numerical Recipes in C: The Art of Scientific Computing., Cambridge University Press, second edition.

Scargle, J.D. (1982) Studies in astronomical time series analysis II. Statistical aspects of spectral analysis of unevenly spaced data, The Astrophysical Journal, 263, volume 2, 835-853.

`spec.taper`, `plotSpecLs`, `fft`
 ```1 2 3 4 5``` ```data(V22174) spec.ls(V22174) data(asth) spec.ls(asth) ```