\documentclass[30pt,landscape]{foils}

\usepackage{amsmath}

\usepackage{pause}               \usepackage{background}
\usepackage{graphicx}           \usepackage{geometry}
\usepackage{hyperref}

\usepackage{pp4slide}
\geometry{headsep=3ex,hscale=0.9}

\newtheorem{example}{Example} 
\newtheorem{question}[example]{Question}
\newtheorem{definition}[example]{Definition}
\newtheorem{theorem}[example]{Theorem}
\newtheorem{fact}[example]{Fact}
\newtheorem{notation}[example]{Notation}

\newcommand{\pz}{\pause}
\newcommand{\pb}{\pagebreak}

\definecolor{bgblue}{rgb}{0.03,0.39,0.23}
\vpagecolor{bgblue}

\hypersetup{pdftitle={lecture},
  pdfsubject={A mathematics lecture},
  pdfauthor={Dev Sinha, University of Oregon},
  pdfkeywords={pdftex, acrobat},
  pdfpagemode={FullScreen},
  linkcolor={red}
}

\begin{document}



\begin{quotation}
{I gather, young man, that you wish to be a Member of Parliament. The
first lesson that you must learn is, when I call for statistics about
the rate of infant mortality, what I want is proof that fewer babies
died when I was Prime Minister than when anyone else was Prime
Minister. That is a political statistic.}

{\emph{--Winston Churchill} }
\end{quotation}\pb


{\Large  Review of scatterplots and correlation.}\pause

For two observed  quantities in the same data set, 
a scatterplot ``plots them against each other'' \pz
To measure correlation, we take the value $r$,
which depends on the normalized variables (deviations
from the mean) \pz (and thus doesn't care about the units
of measurement, for example). \pb

\begin{example}
We take the data from exercise 4.27.  This gives, for 19 wealthy
countries, the average number of liters of alcohol per year from wine,
and the yearly rate of death from heart disease (per 100,000
people).\pause \begin{tabbing}
\= explanatory explanatory variable \= asdfasdfasdf \= \kill\\
\> INDIVIDUALS: \> countries\pz \\
\> EXPLANATORY VARIABLE: \> \pause liters of alcohol per year\\ from wine\\\pause 
\> RESPONSE VARIABLE: \> deaths per 100,000 from \\heart attack per year.
\end{tabbing}
\end{example}

\includegraphics{Figures/wine-heartdisease.jpg}\pb

This seems to show a strong correlation.  Does it look positive or negative? \pause

 Do you think that there is some causality? \pz

The value of $r$ is $-.843$ - how does that fit with what we see informally? \pb


{{\Large The least squares regression line}} \pz

When we introduced the $r$-value, we talked about it as related to
some line \pz (since for example if $r= \pm1$, the data lies along some line).  
We will now study that line. \pz  

\begin{definition}
The
\emph{{least square regression line}}  is decribed as
follows:  \begin{itemize}
\item Put the explanatory variable $x$ along the horizontal axis and
the response variable $y$ along the vertical axis. \pz
The least squares regression line is the line that minimizes
the sum of the squares of the vertical distances from the points to
the line. \pz
\item Numerically, take 
\[
b = r \frac{s_{y}}{s_{x}}
\]
 Take 
\[
a=\overline{y}-b\overline{x}
\]
Then the least squares regression line is 
\[
\hat{y} = a + bx
 \]
\end{itemize}\pause 
In these formulas, $\overline{x}$ is the mean for the variable $x$,
$s_{x}$ is the standard deviation for the variable $x$.    \pz
\end{definition}

We use
$\hat{y}$ instead of $y$ to remind ourselves that the line will only
give a prediction for the response variable, not its actual value. \pz

You can derive the equation of the regression line using calculus, as
is done sometimes in Math 242. \pz

There would be many criteria
by which we might find a ``best line'' - why might the least squares
criterion be better in many situations? \pz
 \pb

\begin{example}
We calculate with our wine consumption /life expectancy data. With
\[
\overline{x} = 3.026, s_{x} = 2.51, \overline{y} = 191.053, s_{y} = 68.396, 
r = - .843.
\]
What is the equation of the regression line? \pz
%So  \[  b = -.843 \frac{68.396}{2.51} = -22.971 \]
% \[ a = 191.053 - (-22.971)3.026 = 260.563. \]
%So our regression line is 
% \[ \hat{y}  = 260.563 - 22.971 x.\]\pause 
\end{example}

Let's plot the regression line over our scatterplot:

\includegraphics{Figures/regression.jpg}\pause 

What do you notice? \pb

\begin{example}
Both your calculators and statistical programs such as Excel can 
do regression analysis.  \pz  We use Excel to analyze Data Set A
from Table 5.2 of your book. \pz
Steps: enter data; \pz highlight data; \pz ``Insert'' a chart; \pz
under Chart menu, add a trendline (with options to give equation). \pb
\end{example} \pb

{\Large Using the regression line for prediction} \pz

Prediction using the regression line is simple - \pz
just plug in. \pz

\begin{example}
Suppose we know that in Elbonia the average person drinks 5 liters of
wine per year.  What is the predicted rate of heart attack? \pz
 
%Then we get our predicted value of $y$ for Elbonia:
%\[
%\hat{y} = 260.563 - 22.971 \times 5 = 145.708.
 %\]\pause 

Suppose in the Grand Duchy of Fenwick, we know the average person
drinks 1.8 liters of wine each year. \pause  What is our predicted
value of $y$? \pz
\end{example}
%\[
%\hat{y} = 260.563 - 22.971 \times 1.8 = 219.215.
%\]\pause 

\begin{example}
Using our linear regression, what would we predict
from Data Set A of Table 5.2 for a $y$-value if
we observe an $x$-value of 10?  \pz of 15? \pz
\end{example}\pz

It is somewhat funny to ``predict'' an associated y-value
for an x-value which has already been observed; \pz
what does it mean to do so?

\begin{fact}
Facts about regression line:
\begin{itemize}
\item It matters which variable you take as ``explanatory'' and which
as ``response.''\pause 
\item Slope is related to $r$.\pause  More precisely, a change of one
standard deviation in $x$ predicts a change of $r$ standard deviations in $y$.
\item The line goes through $(\overline{x},\overline{y})$.\pause 
\item $r$ gives the strength of the relationship.\pause 
\item $r^{2}$ tells the fraction of the variation of $y$ that is
explained by the variation of $x$. (In our wine example, $r^{2} = .71$.)
\end{itemize}
\end{fact}
\pb

{\large Residual plot}

We can make a residual plot by measuring how far each $y$ value is
from the predicted $\hat{y}$ value (for each $x$).

\includegraphics{Figures/residual.jpg}

This gives a subjective impression of how well the regression line
fits. \pause  If most $y$ values are close to zero, the fit is good. \pb

{\Large Correlation and the regression line}\pause

We take data from our dataset involving life expectancies (male,
female and both), people per TV and people per doctor.  We examine the
variables ``people per television'' as a possible explanatory variable
and ``life expectancy'' as a possible response variable.\pause 

We'd like to use this data for two purposes. 
\begin{itemize}
\item Correlation does \emph{not} imply causation.  These two
variable are reasonably strongly correlated, but obviously abundance
of TVs does not cause a long lifespan.
\item We'll calculate correlation and regression lines removing
outliers to demonstrate that correlation and the regression line are
\emph{not} resistant.
\end{itemize}

We will take the opportunity to calculate the regression lines,
and try to understand the numbers which go into them,
along the way.

\newpage

\includegraphics{Figures/tv-lifeexpect.pdf}
\[
r=-.605847,  r^{2} = .36705
\]

\includegraphics{Figures/tv-life-regress1.pdf}
\[
r=-.605847,  r^{2} = .36705
\]
\[
\hat{y} = 69.64 - 0.036 x
\]

\includegraphics{Figures/tv-life-regress2.pdf}
\[
r=-.541398,  r^{2} = .293112
\]
\[
\hat{y} = 71.48 - 0.153 x
\]

\includegraphics{Figures/tv-life-regress3.pdf}
\[
r=-.740354,  r^{2} = .548123
\]
\[
\hat{y} = 73.16 - 0.343 x
\]

\includegraphics{Figures/tv-life-regress4.pdf}
\[
r=-.784158,  r^{2} = .614904
\]
\[
\hat{y} = 74.56 - 0.516 x
\]

\pb

{\Large Final cautions about regression} \pz

{\bf Always plot data you analyze with regression}  \pz
The equation doesn't tell the whole story. \pz Take for
example Data Set D from Table 5.2. \pz

{\bf Beware the effects of outliers} \pz  As we have illustrated
with the TV vs. Life Span regressions. \pz
If a statistic can change a lot with the addition or subtraction
of one data point, how heavily can we rely on it? \pb

{\bf Avoid extrapolating too much} \pz For example
if people in Vinland drank 50 liters of wine per year,
would we really expect them to be healthier
than the Elbonians? \pz

{\bf Correlation does not imply causation} \pz
Or else we would be shipping TV's to sub-Saharan Africa to 
increase their lifespans. \pz


\end{document}
 