\section{Kolmogorov-Smirnov Test}
The Kolmogorov-Smirnov Test (KS test) is based on the cumulative distribution function of the underlying distribution.  The graphic in Figure (\ref{ecdf}) shows the CDF of the Normal Distribution and an observed CDF or Empirical CDF of normally distributed random numbers.  The KS test is based on the maximum difference between these two CDF's.
\begin{figure}[ht]
\begin{center}
\includegraphics[scale=0.5]{ecdf2.eps}
\caption{Comparison of ECDF and CDF of Normal Distribution}
\label{ecdf}
\end{center}
\end{figure}
To test the hypothesis $H_{0} : X \sim F(x)$, where $F$ is a fully specified CDF, we use the statistics
\begin{eqnarray}
D^{+} & = & \max_{i} (i/n - F(x_{i:n})) \label{ksmax} \\ 
D^{-} & = & \min_{i} (F(x_{i:n}) - (i-1)/n) \label{ksmin} \\ 
D & = & \max (D^{+},D^{-}) \label{dstat}
\end{eqnarray}
Where $x_{i:n}$ denotes the $i^{th}$ order statistic of the random sample and $F(x_{i:n}) = P\{X < i\}$ for the distribution that is being fit (in our case, the standard normal distribution).

The distribution of (\ref{ksmax}) - (\ref{dstat}) will not change if location-scale parameters are estimated, only the form of $F$ will change in this case.  Critical values for the $D$ statistic have been calculated by Stephens\footnote{``EDF Statistics for Goodness of Fit and Some Comparisons'' \textit{J. Amer. Statist. Assoc.} \textbf{69}, p.730}.

\subsection{Calculations / Simulations}
\texttt{R} includes a function to run the KS test.  It is called \texttt{ks.test}.  The \texttt{ks.test} function takes two parameters, a data set and a character string naming which distribution we are testing.  In our case, we will call \texttt{ks.test} with the parameter \texttt{`pnorm'}.  \texttt{pnorm} is the normal density function provided by \texttt{R}.



We will examine some of the properties of the power function.  This will be done by considering some data with the form
\begin{equation}
Z(\delta) = X + \delta Y \label{skewdata}
\end{equation}
Where $X \sim N(0,1)$, $Y \sim U(-1,1)$ and $\delta$ is a value we use to skew the data.  The first thing we look at is how the KS test reacts to changes in $\delta$.  Figure (\ref{dpowerks}) shows a plot of the observed $\alpha$ level against $\delta$ for a few chosen $\delta$ values.

We see that at $\delta = 0$, we get a significance level of $\alpha = 0.05$ as to be expected.  As $\delta$ increases, the observed significance level increases very rapidly.  This demonstrates that the KS test recognizes small alterations to our data, and rejects more often.  This also indicates that the KS test is fairly conservative, since it detects small changes in the data set.
\begin{figure}[ht]
\begin{center}
\includegraphics[scale=0.55]{deltapowerks.eps}
\caption{Power as a function of $\delta$ (KS test)}
\label{dpowerks}
\end{center}
\end{figure}

Next, we fix a small number of $\delta$ values and change the sample size $n$ in order to gauge what the power function does when the sample size is changed.  In this case we take $N = 2500$ samples of size $n = 10,20,\ldots,100$ and plot the observed rejection rate against $n$.  The results can be seen in Figure (\ref{npowerks}).
\begin{figure}[ht]
\begin{center}
\includegraphics[scale=0.55]{npowerks.eps}
\caption{Power as a function of sample size (KS test)}
\label{npowerks}
\end{center}
\end{figure}

The test in this case is set up such that
\begin{equation}
H_{0} : X \sim N(0,1) \textrm{ \hspace*{2cm} } H_{a} : X \sim N(0,1) + \delta U(-1,1) \label{peqn}
\end{equation}
And we are concerned with the proportion of times we reject $H_{0}$ given that we have engineered it to be false.  In this case we want this proportion to be greater than or equal to $0.95$ or $1 - \alpha = 0.95$ and we would like to know what sample size is needed to acheive these requirements.

Figure (\ref{npowerks}) shows the percentage of times the test rejected as a function of sample size for various values of $\delta$.  It also shows a black line where our cut off is.  This graphic shows that for very contaminated data, we need a very small sample size.  This leads to the conclusion that the KS test has good power.
