% 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[dvips]{graphicx,graphics,color}
\usepackage{times,amsmath,amsfonts}


\setlength{\textheight}{10in} \setlength{\textwidth}{6.875in}
\setlength{\columnsep}{0.3125in} \setlength{\topmargin}{-0.5in}
\setlength{\headheight}{0in} \setlength{\headsep}{0in}
\setlength{\parindent}{1pc}
\setlength{\oddsidemargin}{-.2in}  % Centers text.
\setlength{\evensidemargin}{-.2in}

% Add the period after section numbers.  Adjust spacing.

\newcommand{\bqn}{\begin{eqnarray}}
\newcommand{\eqn}{\end{eqnarray}}
\newcommand{\bq}{\begin{eqnarray*}}
\newcommand{\eq}{\end{eqnarray*}}

\begin{document}

% Don't want date printed
%\date{January 23, 2003}

% Make title bold and 14 pt font (Latex default is non-bold, 16pt)
\title{Stat 312: Lecture 06\\
Quantile-quantile plots}

% For single author (just remove % characters)
\author{Moo K. Chung\\
mchung@stat.wisc.edu}
% For two authors (default example)
\maketitle
\thispagestyle{empty}

\begin{enumerate}
\item In order to compute
$100(1-\alpha)\%$ confidence interval, it is required to find
$z_{\alpha/2}$ that satisfies $P(Z > z_{\alpha/2}) = \alpha/2$ for
given $\alpha$. We will study how to find $z_{\alpha/2}$ and more.
This lecture is based on Chapter 4.6.

\item The $p$-th {\em quantile} point $q$ for random variable $X$ is the point such
that $$F(q) = P(X \leq q) = p.$$ The textbook represent it in terms
of {\em percentile}. Note that $p$-th quantile $= 100\times p$-th
percentile. So given $p$,
$$q = F^{-1}(p).$$
For $X \sim N(0,1)$, it is easy to find the $p$-th quntile using
\begin{verbatim}
> qnorm(1)
[1] Inf
> qnorm(0.5)
[1] 0
> qnorm(0)
[1] -Inf
> qnorm(0.5)
[1] 0
> qnorm(0.95)
[1] 1.644854
> qnorm(0.05)
[1] -1.644854
\end{verbatim}
In order to find $z_{\alpha}$, we use command
$\tt{qnorm(1-\alpha)}$.


\item Given $n$ observations $x_1,\cdots, x_n$, we order them from
the smallest to the largest and we have $x_{(1)}, \cdots, x_{(n)}$.
The $i$-th smallest observation is defined as the $(i-0.5)/n$-th
{\em sample quantile} point or $100(i-0.5)/n$ {\em sample
percentile} point.
\begin{verbatim}
> library(Devore6)
> data(xmp01.05)
> attach(xmp01.05)
> sq <- sort(bingPct)
\end{verbatim}


\item If {\tt bingePct} really follows $N(42,14^2)$, then the sample
quantiles should be resonably close to the corresponding quantiles
of the normal distribution. The corresponding quantile points for
{\tt bingePct} can be computed using
\begin{verbatim}
> q=qnorm((1:140-0.5)/140,42,14)
\end{verbatim}
We can check how closely the sample quantiles corresponds to the
normal distribution by plotting the {\em quantile-quantile plot}
(QQ-plot) of the sample quantiles vs. the corresponding quantiles of
a normal distribution (Figure 1).
\begin{verbatim}
> plot(q,sq)
\end{verbatim}

\begin{figure}[t]
\centering
\includegraphics[width=70mm]{lecture07-1.ps}
\caption{Plot of ordered data {\tt bingePct} showing sample {\tt
sq}-th quantile.}\label{fig:sq}
\end{figure}

\item If $X \sim N(\mu,\sigma^2)$, then $$Z=\frac{X-\mu}{\sigma} \sim
N(0,1).$$ The $p$-th quantile of $X$ is given by
$$p = P(X \leq q) = P\Big(\frac{X-\mu}{\sigma} \leq \frac{q-\mu}{\sigma}  \Big)=P\Big(Z \leq \frac{q-\mu}{\sigma}  \Big).$$
The quantile point $q$ of $N(\mu,\sigma^2)$ corresponds to the
quantile point $(q-\mu)/\sigma$ of $N(0,1)$. So we do not need to
find the quantile points of $N(\mu,\sigma^2)$. All we need is the
quantile points of $N(0,1)$ for checking normality. It can be easily
done using command
\begin{verbatim}
> qqnorm(bingePct)
\end{verbatim}

This plot (Figure 2) is usually referred as the normal probability
plot.

\begin{figure}[t]
\centering
\includegraphics[width=70mm]{lecture07-2.ps}
\caption{Normal probability plot of {\tt bingePct}}\label{fig:sq}
\end{figure}
\begin{figure}[t]
\centering
\includegraphics[width=70mm]{lecture07-3.ps}
\caption{Normal probability plot of data that follows an exponential
disribution}\label{fig:sq}
\end{figure}

\item What would happen if we plot data that do not follow a normal
distribution?
\begin{verbatim}
> x<-rexp(100,1)
> qqnorm(x)
\end{verbatim}
\end{enumerate}
{\em Review Problems.} Example 4.28. 4.29.
\end{document}
