---
title: "lomb - periodogram of unevenly spaced time series"
output: rmarkdown::pdf_document
vignette: >
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteIndexEntry{lomb - periodogram of unevenly spaced time series}
  %\usepackage[UTF-8]{inputenc}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

\pagenumbering{arabic}
Thomas Ruf
----------
Veterinary University Vienna, Austria
-------------------------------------
Even a single missing or falsely read point can make a time series unevenly sampled. These data with varying time point increments cannot be analyzed for temporal patterns with traditional Fourier periodograms. However, Lomb (1976), followed by Scargle (1982) devised a method to investigate uneven time series. This is provided bv package lomb an the function lsp(), the Lomb-Scargle Periodogram.

For example, we can make the timeseries Lynx uneven by making ten points unavailable
```{r, eval=FALSE}
  missing=c(5,25,49,26,56,79,88,98,99,112)
  lmiss=data.frame(year=1:114, capture=lynx)
  lmiss[missing,]=NA
  lmiss=na.omit(lmiss)
  
  library(lomb)
  result=lsp(lmiss)
```


\begin{figure}
\begin{center}
  \includegraphics [width=0.8\columnwidth]{p1.jpeg}
  \caption{Lomb-Scargle Periodogram of the time series lynx with 5 missing points.}
\end{center}
\end{figure}

The increment between subsequent years now varies from 1 to 3. The outcome of lsp is a figure with a peak at a period of approximately 10 years (exactly stored in result$peak.at). In other words, there was a ~10 year rhythm in Lynx trappings. This rhythm can be detected even if the sampling is uneven.
The horizontal, dashed line is the false alarm probability, i.e., the likelihood that a peak as large as the observed should occur by chance. It was computed according to Baluev, but a Montecarlo method is also available. Here, the chance for a random event is less than 0.01. Find the exact number at result$p.value.
Sometimes, unevenly spaced series are generated by noting the time of a movement. This was done for a blind beetle and can be visualized in an actogram. 


\begin{figure}

\begin{center}
\includegraphics [width=0.7\columnwidth]{p2.jpeg}
  \caption{Actogram of locomotion of a blind beetle.us function actogram()}
\end{center}
\end{figure}

This 12 day double-plot of activity shows day1 and day2 in the first row, day2 and day3 in the second row, ans so on.
A Lomb-Scargle periodogram of these data can be computed as follows.
```{r, eval=FALSE}
data(caradat)
focus=actogram(caradat$Date, caradat$Activity, dble=TRUE, photo=FALSE, zone=1,from="1970-01-01 00:00:00",to="1970-01-14 00:00:00")
df=makedf (focus$date, focus$plotvar)
lsp(df, type="period",ofac=5,from=12,to=36)
```
\begin{figure}
\begin{center}
  \includegraphics [width=0.6\columnwidth]{p3.jpeg}
  \caption{Lomb-Scargle Periodogram of the activity of a beetle shown before}
\end{center}
\end{figure}
The resutlting lsp, for the unique days shown previously, (here day 1-12) has major peaks at ~19-22 h, thus the rhythm is < 24 h. The periodorgam is shown for periods from 12 to 36 h. Ofac determines the oversampling factor, which (without a statistical penalty) makes the periodogram smoother. Aside from other advantages, the lsp is highly sensitive to rhythmic signals (Ruf 1999).

\vspace{2 cm}

\textbf{References:}
\newline
Lomb, N. R. (1976). Least-squares frequency analysis of unequally spaced data. Astrophysics and space science, 39, 447-462.
\newline
Scargle, J. D. (1982). Studies in astronomical time series analysis. II-Statistical aspects of spectral analysis of unevenly spaced data. Astrophysical Journal, Part 1, vol. 263, Dec. 15, 1982, p. 835-853., 263, 835-853.
\newline
Baluev, R. V. (2008). Assessing the statistical significance of periodogram peaks. Monthly Notices of the Royal Astronomical Society, 385(3), 1279-1285.
\newline
Ruf, T. (1999). The Lomb-Scargle periodogram in biological rhythm research: analysis of incomplete and unequally spaced time-series. Biological Rhythm Research, 30(2), 178-201.




