% Method

\section{Data Origin}
Switzerland has an automatic meteorological network since 1978. From some stations longer time series are available \cite{projektANETZ1980,zellweger1983}. All meteorological data are provided by the \ac{MeteoSwiss}. \ac{PM} is measured by the \ac{NABEL} and the data are provided by the \ac{BAFU} and the \ac{Empa}.

The data for Germany are available from the \ac{DWD}.

In this work only daily values are considered which are mostly computed from ten minutes values.

To facilitate the handling, all measured values used in the computations are stored in a database (details in Appendix \vref{chap:database}).

\section{Data Evaluation}
Climatological variables have different fluctuations caused by diurnal and seasonal cycles and diverse weather conditions.

For the analysis of a 7-day cycle, it is advisable to filter these cycles, primarily diurnal and seasonal ones. Considering only daily values, the diurnal cycle does not matter anymore.

\subsection{Running Mean}
A simple method to filter out these fluctuations is to compute the deviation to a running mean.

This deviation ($\delta_d$) is computed as follows:
\begin{eqnarray}
\delta_d = v_d - \frac{1}{\Delta}\sum_{i=d-\frac{\Delta-1}{2}}^{d+\frac{\Delta-1}{2}}{v_i} \label{methods:eq:runningmean}
\end{eqnarray}
The given measured value at day $d$ is given as $v_d$, then the mean of the $\Delta$ days---which has to be odd---around the day $d$ are subtracted (Equation~\ref{methods:eq:runningmean}). \citet{baeumer2007feb} set $\Delta$ to 31\,days.

In \ac{R} this is realised with the function \script{gleitendesmittel.R} (Appendix, Section \vref{chap:R:gleitendesmittel.R}). The result is a new time series, which contains the daily deviation from the running mean and is called the \RM{} ($\delta$).

\subsection{Grouping by weekdays}\label{methods:subsec:gbyw}
The \RM{} ($\delta$) can be grouped by weekdays. This gives 7 time series ($\delta_{\text{weekday}_w}$), one for each weekday (Equation~\ref{methods:eq:gbyw}).
\begin{eqnarray}
\delta_{\text{Monday}_w} & = & \{\delta_{d} | d \text{ is Monday}\}\nonumber\\
\delta_{\text{Tuesday}_w} & = & \{\delta_{d} | d \text{ is Tuesday}\}\nonumber\\
 & \vdots & \nonumber\\
\delta_{\text{Sunday}_w} & = & \{\delta_{d} | d \text{ is Sunday}\}
\label{methods:eq:gbyw}
\end{eqnarray}
Calculating the mean of each group provides the deviation for every weekday ($\bar{\delta}_{\text{weekday}}$) (Equation~\ref{methods:eq:deviation}).
\begin{eqnarray}
\bar{\delta}_{\text{weekday}} & = & \frac{1}{w_{\text{end}}-w_{\text{begin}}+1} \sum_{w=w_{\text{begin}}}^{w_{\text{end}}}{\delta_{\text{weekday}_w}} \label{methods:eq:deviation}
\end{eqnarray}

It is also possible to group the measured values directly by weekdays. The result is a distribution in both cases.

\subsection{Several Stations}\label{methods:subsec:several stations}
There are two possibilities to compute $\bar{\delta}_{\text{weekday}}$ if there are data available from more than one station.
\begin{enumerate}
\item Group directly by weekday, as described in \vref{methods:subsec:gbyw}
\item First aggregate the data for each single day and then group them by weekday
\end{enumerate}
The number of the $\delta_{\text{weekday}}$ is higher in the first case (by a factor of the number of stations).

\subsection{Plots}
If the time dependence is neglected, $\delta_{\text{weekday}}$  can be considered as a distribution, so it is possible to calculate e.\,g. the standard deviation and standard error and plot the weekly cycle with errorbars.

\subsection{Tests}\label{methods:subsec:tests}
With $\delta_{\text{weekday}}$ as a distribution it is possible to run a statistical test, e.\,g. Wilcoxon test one sided, of the maximum mean against the one with the minimum---this corresponds to the amplitude of the weekly cycle. Due to the fact that more than two groups exist (equal to the number of weekdays) an analysis of variance might be more appropriate, e.\,g., with the \KW{} test.

If a time series ($\delta$ or $v$) of a station correlates with another one, they are not independent and therefore to group them directly by weekday (Section \vref{methods:subsec:several stations} item 1) is not correct for the tests mentioned previously. To check whether the time series from the different stations correlate with each other, they can be tested against each other. It is important to test only the filtered time series. In \ac{R} this can be done with the function {\tt cor.test} and is realised in the program \script{korrelation.R}, Appendix, Section \vref{chap:R:korrelation.R}.

Another simple way to compare whether or not there is a weekly cycle, is to assume a 6-day-week and a 8-day-week. To distinguish between the ``weeks'' the following names for the weekdays are chosen:
\begin{description}
\item[6-day-week] Jeroboam, Rehoboam, Methuselah, Shalmanazar, Balthazar and Nebuchadnezzar\footnote{Names of wine bottles}
\item[7-day-week] Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday\footnote{It is difficult to explain where these names come from}
\item[8-day-week] Bo, Hamm, Slink, Potato, Woody, Sarge, Etch and Lenny\footnote{Names of Debian releases}
\end{description}

\subsection{Periodogram}
A periodogram is an estimate of the spectral density of a signal. It allows certain frequencies in a time series to be detected---unless there are any at all. A weekly cycle in the daily measured values provides a peak at the frequency of $\frac{1}{7}$ and at the multiples of it.

\section{Simulation}\label{methods:simulation}
%To compare the results with a random process the following methods are used to create a random sequence.
Another plausibility check can be done by comparing the results with a random process. Different methods are used to create a random sequence. The target of all these methods is to create a new time series with the same length and the same characteristic as the original one but without a possible weekly cycle. The simulation can be based on the original time series with the measured values or on the \RM{}.

\subsection{Random}\label{methods:simulation_random_series}
There are two ways to create a new absolutely random series with the same length and standard deviation as the original time series.
\begin{itemize}
 \item A random order of the time series
 \item A distribution with the same standard deviation and length as the time series
\end{itemize}

\subsection{Autocorrelation}\label{methods:Autocorrelation}
The time series has an autocorrelation, because a meteorological measured value often depends on the preceding value. The new time series ($a_k$) is computed as follows: the first entry is set to the mean of the original time series $\bar{\delta}$. The next entry is then computed from the entry before and a random part (equation~\vref{methods:eq:autocorserie}).
\begin{eqnarray}
a_1 & = & \bar{\delta}\nonumber\\
a_2 & = & a_1 \cdot \varrho + (1-\varrho) \cdot r_1\nonumber\\
a_3 & = & a_2 \cdot \varrho + (1-\varrho) \cdot r_2\nonumber\\
&\vdots&\nonumber\\
a_n & = & a_{n-1} \cdot \varrho + (1-\varrho) \cdot r_{n-1} \label{methods:eq:autocorserie}
\end{eqnarray}
$r_i$ is a random number from a distribution with the same standard deviation as the original time series and $\varrho$ is the autocorrelation of it. The autocorrelation $\varrho$ is the estimated measure of association of the time series with itself shifted by one day, which corresponds to one entry. In \ac{R} this is realised with the function {\tt cor.test} as follows:
\lstinputlisting{./codes_snippet/cortest.R}

Setting the autocorrelation to a arbitrary value is useful for comparison (e.\,g. 0 and 0.9).

It is not advisable to do these simulations with the measured values because they have a seasonal cycle.

\subsection{Take Samples}
The time series created in Section~\vref{methods:Autocorrelation} could lack a feature describing the original time series. Another approach is to create a new time series ($s_k$) with samples from the original time series, which then exhibits the same length as the week. The procedure is shown in Equation~\vref{methods:eq:rauspicken}:
\begin{eqnarray}
\text{First week of the new time series} & &
\left\lbrace
 \begin{matrix}
  s_1 & = & \delta_{r_{1}+1}\\
  s_2 & = & \delta_{r_{1}+2}\\
      & \vdots & \\
      s_{w} & = & \delta_{r_{1}+w}
 \end{matrix}
\right. \nonumber\\
\text{Second week of the new time series} & &
\left\lbrace
 \begin{matrix}
  s_{w+1} & = & \delta_{r_{2}+1}\\
  s_{w+2} & = & \delta_{r_{2}+2}\\
          & \vdots & \\
  s_{w+w} & = & \delta_{r_{2}+w}
 \end{matrix}
\right. \nonumber\\
\text{Third week of the new time series} & &
\left\lbrace
\begin{matrix}
 s_{2w+1} & = & \delta_{r_{3}+1}\\
          & \vdots &
 \end{matrix}
\right.
\label{methods:eq:rauspicken}
\end{eqnarray}
$r_i$ is a random number between 0 and the length of the time series minus the length of the week and $w$ is the length of the week.

%\subsection{Verschieben und sample und dann addieren}
%  # Verschieben und sample und dann addieren
%  corzahlen <- origdata[2:(laenge)]-origdata[1:(laenge-1)]
%   zufallszahlen <- sample(corzahlen)
%   zufallszahlen[is.na(zufallszahlen)] <-0
%
%     neuereihe[j] <- neuereihe[j-1]+zufallszahlen[j-1]

\subsection{Evaluation}
The weekdays are matched to each of these new time series. The first entry in the time series is Monday (Jeroboam or Bo depending on the length of the week) the second Tuesday (Rehoboam or Hamm) and so on.

To receive the amplitude of the average weekly cycle one has to subtract the weekday with the minimum mean value from the one with the maximum mean value. Repetitions of this procedure allow a histogram of the amplitudes to be made.

Storing the mean of each weekday from a few runs allows the simulated weekly cycle  to be compared with the original one.

To compare the different tests presented in Section~\vref{methods:subsec:tests}, the same procedure as for the amplitude is used with the $p$-values of each test. Thus one can make a histogram of the $p$-values.
%This sequence is then divided in as many parts as ``weekdays'' exists, which means: the sequence is divided by 6 for a 6-day-week, by 7 for a 7-day-week and by 8 for a 8-day-week. To receive the amplitude of the weekly cycle one has to subtract the part with the minimum mean from the one with the maximum mean. Repetitions of this procedure allowed to draw a histogram of the amplitudes.
