% This is a simple LaTex sample document that gives a submission format
%   for IEEE PAMI-TC conference submissions.  Use at your own risk.

% Make two column format for LaTex 2e.\
\documentclass[11pt,twocolumn]{article} %,twocolumn

%\usepackage{times,amsmath,amsfonts}

% Use following instead for LaTex 2.09 (may need some other mods as well).
%\documentstyle[times,twocolumn]{article}
\usepackage[dvips]{graphicx,graphics}
% Set dimensions of columns, gap between columns, and paragraph indent
\setlength{\textheight}{10in} \setlength{\textwidth}{7in}
%\setlength{\columnsep}{0.3125in} \setlength{\topmargin}{0in}
\setlength{\headheight}{0in} \setlength{\headsep}{-1in}
\setlength{\parindent}{1pc}
\setlength{\oddsidemargin}{-.5in}  % Centers text.
\setlength{\evensidemargin}{-.5in}

% Add the period after section numbers.  Adjust spacing.
\newcommand{\Section}[1]{\vspace{-8pt}\section{\hskip -1em.~~#1}\vspace{-3pt}}
\newcommand{\SubSection}[1]{\vspace{-3pt}\subsection{\hskip -1em.~~#1}
        \vspace{-3pt}}
\newcommand{\bqn}{\begin{eqnarray}}
\newcommand{\eqn}{\end{eqnarray}}
\begin{document}

% Make title bold and 14 pt font (Latex default is non-bold, 16pt)
\title{Stat 471: Lecture 4\\
Quantile-Quantile Plot}
% For single author (just remove % characters)
\author{Moo K. Chung\\
mchung@stat.wisc.edu}
% For two authors (default example)
\maketitle \thispagestyle{empty}


We studied a couple of method for generating random numbers. For
instance we studied two ways for generating exponential random
numbers. {\em But how do you know two random number generators are
equivalent.} One simple way is a graphical display called the
quantile-quantile plot (Q-Q plot) (Wilk and Gnanadesikan, 1968).

\begin{enumerate}
\item Quantile point $q_p$ for random variable $X$ is the point
such that $$F_X(q_p)=P(X \leq q_p) = p.$$ So the quantile is a
function of probability or proportion, i.e.
$$q_p = F_X^{-1}(p).$$

\item Plot the quantile function for the exponential random
variable $X$ with parameter $\lambda = 2$.\\
{\em Solution.} From lecture 02-5, $F^{-1}(p) =
-\frac{1}{2}\ln(1-p)$.
\begin{verbatim}
p=[1:99]/100; 
q=inline('log(1-p)/2');
plot(p,q(p));
\end{verbatim}

\begin{figure}
\centering
\renewcommand{\baselinestretch}{1}
\includegraphics[scale=0.4]{lecture04-1.eps}
\end{figure}
 \item If $q_p^X$ and $q_p^Y$ are quantile functions of random
 variables $X$ and $Y$, Q-Q plot of $X$ and $Y$ is the plot of
 $(q_p^X,q_p^Y)$ for all $p$.

\item Generate the Q-Q plot of $X \sim exp(2)$ and $Y \sim
exp(2)$. Since they are identical distributions, you would expect
line $y=x$ as the Q-Q plot.

\begin{verbatim}
U=rand(1000,1); X=-log(U)/2; 
V=rand(1000,1); Y=-log(V)/2;
qqplot(U,V)
\end{verbatim}

\begin{figure}
\centering
\renewcommand{\baselinestretch}{1}
\includegraphics[scale=0.4]{lecture04-2.eps}
\end{figure}

 \item If $q_p^X$ and $q_p^Y$ are quantile functions of random
 variables $X$ and $Y$, Q-Q plot of $X$ and $Y$ is the plot of
 $(q_p^X,q_p^Y)$ for all $p$.

\item Check if the integral transform and the accept-reject method
produce identical distribution for $exp(2)$ random variable.

\begin{verbatim}
U=rand(1000,1); X=-log(U)/2;
f=inline('exp(-2*x)/2'); 
i=1; while i <= 1000 
         U = rand; V = rand;
         if (U < 2*f(V)) Y(i)=V; i=i+1; 
         end; 
     end;
qqplot(X,Y)
\end{verbatim}

Warning: For the accept-reject method, the distributions $f$ and
$g$ should be somewhat similar to have a sufficiently good
algorithm. The range of $f$ should be covered by $g$.

\begin{figure}
\centering
\renewcommand{\baselinestretch}{1}
\includegraphics[scale=0.4]{lecture04-3.eps}
\end{figure}

\begin{figure}
\centering
\renewcommand{\baselinestretch}{1}
\includegraphics[scale=0.4]{lecture04-4.eps}
\end{figure}

\end{enumerate}
\end{document}
