% 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]{article} %
\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{\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}}
\newcommand{\bq}{\begin{eqnarray*}}
\newcommand{\eq}{\end{eqnarray*}}
\begin{document}

% Don't want date printed
\date{March 1, 2005}

% Make title bold and 14 pt font (Latex default is non-bold, 16pt)
\title{Stat 324: Lecture 10\\
Probability 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 {\em Motivation.} Checking the normality of data is
important in setting up a statistical model. Measurements are
usually modeled using a normal distribution. We may assume $x_1,
\cdots,x_n$ are $n$ measurements from $N(\mu,\sigma^2)$. But how do
we know the data will follow normality?

\item {\em Example.} Consider the following example of binge drinking percentage
across universities.
\begin{verbatim}
> library(Devore6)
> data(xmp01.05)
> attach(xmp01.05)
> hist(bingePct,14)
\end{verbatim}
\begin{figure}[h]
\centering
\includegraphics[width=55mm]{324.10.01.ps}
\includegraphics[width=55mm]{324.10.02.ps}
\caption{Top: histogram of {\tt bingePct} data. Bottom: histogram of
simulated data from $N(42.34,14.35^2)$.}\label{fig:sq}
\end{figure}

If it were really from $N(\mu,\sigma^2)$, we can estimate $\mu$ and
$\sigma$ from the sample mean and the sample standard deviation:
\begin{verbatim}
> sd(bingePct)
[1] 14.34699
> mean(bingePct)
[1] 42.33571
> length(bingePct)
[1] 140
\end{verbatim}
There are 140 measurement in the data set. Let us randomly generate
140 numbers from $N(42.34,14.35)$ and plot the histogram.
\begin{verbatim}
> simulated <-rnorm(140,42.34,14.35)
> hist(simulated,14)
\end{verbatim}
Unfortunately eyeball comparison can be deceptive so we need a
better method to compare the two histograms. We will compare the
percentiles.


\item {\em Definition.} 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} or the $100(i-0.5)/n$-th {\em sample
percentile} point. If {\tt bingePct} really follows
$N(42.34,14.35^2)$, then the sample quantiles should be resonably
close to the corresponding quantiles of the normal distribution.
\begin{verbatim}
> sorted_bingePct <- sort(bingePct)
> sorted_simulated <- sort(simulated)
> plot(sorted_simulated,sorted_bingePct)
\end{verbatim}

\begin{figure}[h]
\centering
\includegraphics[width=55mm]{324.10.03.ps}
\includegraphics[width=55mm]{324.10.04.ps}
\caption{Left: plot of sorted data {\tt bingePct} vs. {\tt sq}-th
quantile. This plot is called the {\em quantile-quantile plot}
(QQ-plot) and is used to check the equality of distribution between
two samples. This plot shows more or less a straight line so {\tt
bigePct} seems to follow normality. Right: normal probability plot
of {\tt bingePct}. Qunatile points for the x-axis is directly
computed from $N(42.34, 14.35^2)$ without simulation.}\label{fig:sq}
\end{figure}

\item {\em Normal probability plot.} A better method is to generate the percentile points directly from
the theoretical distribution $N(42.34, 14.35^2)$, which can be
obtained by
\begin{verbatim}
> theoretical_quantile<-qnorm((1:140-0.5)/140,42.34,14.35)
> plot(theoretical_quantile,sorted_bingePct)
\end{verbatim}


{\tt R} software has a very simple command for generating the normal
probability plot:
\begin{verbatim}
> qqnorm(bingePct)
\end{verbatim}

%\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{figure}[t]
%\centering
%\includegraphics[width=70mm]{lecture07-2.ps}
%\caption{Normal probability plot of {\tt bingePct}}\label{fig:sq}
%\end{figure}
\begin{figure}[h]
\centering
\includegraphics[width=50mm]{lecture07-3.ps}
\includegraphics[width=50mm]{324.10.05.ps}
\caption{Normal probability plot of data that do not follow normal
distributions.}\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}
{\bf Assigned Problems.} Exercise 4.82., 4.88. Homework III due this
Thursday. Submit assigned problems from Lectures 07-10.

\end{enumerate}
\end{document}
