\setcounter{ExampleCounter}{1}
\paragraph{Example:} Home Prices

\begin{center}
\begin{tabular}{c | c}
\textbf{Size (sq. ft.)} & \textbf{Selling Price (\$1000s)}\\
\hline
& \\
2521 & 400\\
2555 & 426\\
2735 & 428\\
2846 & 435\\
3028 & 469\\
3049 & 475\\
3198 & 488\\
3198 & 455\\
\end{tabular}
\end{center}

\paragraph{Notice:} \text{}
\begin{itemize}
\item Let $x$ be the size and $y$ be the selling price
\item We expect that the size will predict the price
\item The price doesn't \emph{only} depend on the size (ex: last house)
\end{itemize}

\begin{center}
\begin{tikzpicture}
\begin{axis}[
    xmin=2450, xmax=3300,
    ymin=390, ymax=500,
    axis lines=center,
    axis on top=false,
    domain=0:1,
    x=0.01cm,
    y=0.038cm,
    xtick={2500,2550,...,3300},
    xticklabels={2500,,2600,,2700,,2800,,2900,,3000,,3100,,3200,,3300},
    ytick={390,400,...,500},
    yticklabels={390,400,...,500},
    axis lines=middle,
    axis line style={->},
    x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
    y label style={at={(axis description cs:-0.11,.5)},rotate=90,anchor=south},
    xlabel={Size (sq. ft.)},
    ylabel={Price (\$1000s)},
    grid=major
    ]
	\addplot [blue,only marks,mark size=2] table {
	2521 400
	2555 426
	2735 428
	2846 435
	3028 469
	3049 475
	3198 488
	3198 455
	};
	%\addplot [blue, thick] table {
	
	%};
\end{axis}
\end{tikzpicture}
\end{center}

\begin{itemize}
\item The values look like they're grouped around a straight line.
\item Larger sizes are associated with higher prices
\end{itemize}
\vfill
\pagebreak

\begin{formula}{Association}
\begin{itemize}
\item Two variables have a \textbf{linear association} if the scatter plot shows the data clustering around a straight line.
\item Two variables have a \textbf{positive association} if larger values of one variable are linked with larger values of the other variable.
\item Two variables have a \textbf{negative association} if larger values of one variable are linked with smaller values of the other variable.
\end{itemize}
\end{formula}

\begin{center}
\begin{tabular}{c c c}
\begin{tikzpicture}
\begin{axis}[
    xmin=100, xmax=500,
    ymin=100, ymax=500,
    axis lines=center,
    axis on top=false,
    domain=0:1,
    x=0.01cm,
    y=0.01cm,
    xtick={100,200,...,500},
    xticklabels={},
    ytick={100,200,...,500},
    yticklabels={},
    axis lines=middle,
    axis line style={->},
    x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
    y label style={at={(axis description cs:-0.11,.5)},rotate=90,anchor=south},
    %xlabel={Size (sq. ft.)},
    %ylabel={Price (\$1000s)},
    grid=none
    ]
	\addplot [blue,only marks,mark size=2] table {
	110 150
	150 200
	250 220
	300 300
	150 180
	240 270
	310 360
	350 400
	400 475
	400 415
	450 488
	475 465
	};
	%\addplot [blue, thick] table {
	
	%};
\end{axis}
\end{tikzpicture}
&
\begin{tikzpicture}
\begin{axis}[
    xmin=100, xmax=500,
    ymin=100, ymax=500,
    axis lines=center,
    axis on top=false,
    domain=0:1,
    x=0.01cm,
    y=0.01cm,
    xtick={100,200,...,500},
    xticklabels={},
    ytick={100,200,...,500},
    yticklabels={},
    axis lines=middle,
    axis line style={->},
    x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
    y label style={at={(axis description cs:-0.11,.5)},rotate=90,anchor=south},
    %xlabel={Size (sq. ft.)},
    %ylabel={Price (\$1000s)},
    grid=none
    ]
	\addplot [blue,only marks,mark size=2] table {
	110 465
	150 488
	250 415
	300 375
	150 400
	240 360
	310 270
	350 180
	400 300
	400 220
	450 200
	475 150
	};
	%\addplot [blue, thick] table {
	
	%};
\end{axis}
\end{tikzpicture}
&
\begin{tikzpicture}
\begin{axis}[
    xmin=100, xmax=500,
    ymin=100, ymax=500,
    axis lines=center,
    axis on top=false,
    domain=0:1,
    x=0.01cm,
    y=0.01cm,
    xtick={100,200,...,500},
    xticklabels={},
    ytick={100,200,...,500},
    yticklabels={},
    axis lines=middle,
    axis line style={->},
    x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
    y label style={at={(axis description cs:-0.11,.5)},rotate=90,anchor=south},
    %xlabel={Size (sq. ft.)},
    %ylabel={Price (\$1000s)},
    grid=none
    ]
	\addplot [blue,only marks,mark size=2] table {
	140 250
	120 400
	250 320
	300 250
	150 300
	240 270
	450 260
	350 200
	400 175
	400 215
	450 488
	475 365
	200 150
	220 430
	400 350
	350 400
	};
	%\addplot [blue, thick] table {
	
	%};
\end{axis}
\end{tikzpicture}\\
Positive linear & Negative linear & No association\\
\\
\\
\begin{tikzpicture}
\begin{axis}[
    xmin=100, xmax=500,
    ymin=100, ymax=500,
    axis lines=center,
    axis on top=false,
    domain=0:1,
    x=0.01cm,
    y=0.01cm,
    xtick={100,200,...,500},
    xticklabels={},
    ytick={100,200,...,500},
    yticklabels={},
    axis lines=middle,
    axis line style={->},
    x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
    y label style={at={(axis description cs:-0.11,.5)},rotate=90,anchor=south},
    %xlabel={Size (sq. ft.)},
    %ylabel={Price (\$1000s)},
    grid=none
    ]
	\addplot [blue,only marks,mark size=2] table {
	140 150
	150 160
	200 180
	350 250
	150 180
	240 150
	450 260
	350 200
	400 275
	400 215
	450 488
	475 365
	200 150
	300 200
	400 350
	350 220
	};
	%\addplot [blue, thick] table {
	
	%};
\end{axis}
\end{tikzpicture}
&
\begin{tikzpicture}
\begin{axis}[
    xmin=100, xmax=500,
    ymin=100, ymax=500,
    axis lines=center,
    axis on top=false,
    domain=0:1,
    x=0.01cm,
    y=0.01cm,
    xtick={100,200,...,500},
    xticklabels={},
    ytick={100,200,...,500},
    yticklabels={},
    axis lines=middle,
    axis line style={->},
    x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
    y label style={at={(axis description cs:-0.11,.5)},rotate=90,anchor=south},
    %xlabel={Size (sq. ft.)},
    %ylabel={Price (\$1000s)},
    grid=none
    ]
	\addplot [blue,only marks,mark size=2] table {
	140 365
	150 260
	150 488
	200 215
	200 350
	240 275
	300 220
	350 200
	350 150
	350 200
	400 150
	400 150
	400 180
	450 180
	450 160
	475 150
	};
	%\addplot [blue, thick] table {
	
	%};
\end{axis}
\end{tikzpicture} &\\
Positive nonlinear & Negative nonlinear
\end{tabular}
\end{center}
\vfill
\pagebreak

\subsection{Using Your Calculator}
Make sure that there is no equation begin graphed, then enter the data.  Press \includegraphics[height=0.3in]{CalcStatPlotMenu} to access the \texttt{STAT PLOT} menu.  Select the scatter plot and select the lists where you entered the data.
\begin{center}
\begin{tabular}{c c}
\includegraphics[height=1.75in]{CalcScatterPlot}
&
\includegraphics[height=1.75in]{CalcScatterPlot2}
\end{tabular}
\end{center}
Press the \includegraphics[height=0.3in]{CalcGraphButton} button and adjust the window until the scatter plot is visible.

\subsection{The Correlation Coefficient}
The correlation coefficient, $r$, is a measure of how strong a linear relationship is between two variables.

\begin{formula}{Correlation Coefficient}
\[r=\dfrac{1}{n-1}\ \Large{\sum} \left(\dfrac{x-\overline{x}}{s_x}\right) \left(\dfrac{y-\overline{y}}{s_y}\right)\]

\paragraph{Note:} It doesn't matter which variable is $x$ and which is $y$; the correlation coefficient is the same either way.
\end{formula}
\vfill
\pagebreak

\begin{example}{Finding $r$}
Find the correlation coefficient for the house price data.
\begin{center}
\begin{tabular}{c | c}
\textbf{Size (sq. ft.)} & \textbf{Selling Price (\$1000s)}\\
\hline
& \\
2521 & 400\\
2555 & 426\\
2735 & 428\\
2846 & 435\\
3028 & 469\\
3049 & 475\\
3198 & 488\\
3198 & 455\\
\end{tabular}
\end{center}

\begin{center}
\begin{tabular}{c c}
\multicolumn{2}{c}{$n=8$}\\
$\overline{x} = 2891.25$ & $\overline{y} = 447$\\
$s_x = 269.49$ & $s_y = 29.68$
\end{tabular}
\end{center}

\begin{center}
\begin{tabular}{c c c c c}
$x$ & $y$ & $\dfrac{x-\overline{x}}{s_x}$ & $\dfrac{y-\overline{y}}{s_y}$ & $\left(\dfrac{x-\overline{x}}{s_x}\right)\left(\dfrac{y-\overline{y}}{s_y}\right)$\\
\hline
\\
2521 & 400 & $-1.37389$ & $-1.58356$ & 2.17564\\
2555 & 426 & $-1.24773$ & $-0.70755$ & 0.88283\\
2735 & 428 & $-0.57980$ & $-0.64016$ & 0.37116\\
2846 & 435 & $-0.16791$ & $-0.40431$ & 0.06789\\
3028 & 469 & 0.50744 & 0.74124 & 0.37613\\
3049 & 475 & 0.58536 & 0.94340 & 0.55223\\
3198 & 488 & 1.13826 & 1.38140 & 1.28783\\
3198 & 455 & 1.13826 & 0.26954 & 0.30681\\
\hline
& & & & 6.30414
\end{tabular}
\end{center}

\[r=\dfrac{6.30414}{7} = 0.90059\]
\end{example}
\vfill
\pagebreak

How do we interpret the correlation coefficient?

\begin{formula}{Properties of the Correlation Coefficient}
\begin{itemize}
\item The correlation can range from $-1$ to 1:
\[-1 \leq r \leq 1\]
\item Regardless of which variable we call $x$ and which we call $y$, $r$ will be the same.
\item The correlation coefficient only measures the strength of a \textbf{linear} association.
\item If $r$ is positive, the association is positive.
\item If $r$ is negative, the association is negative.
\item The closer $r$ is to $-1$ or 1, the stronger the linear association.
\item If $r=0$, there is no linear association.
\item The value of $r$ is not connected to the value of the slope (aside from sign).
\item The correlation coefficient is sensitive to outliers.
\end{itemize}
\end{formula}
\vfill
\pagebreak

\subsection{Correlation Does Not Imply Causation}
Just because two variables are highly correlated, that doesn't mean that one causes the other.  In the example of the house sizes and their price, there IS a causal link, but you can't assume that in every case where there's a strong correlation.

\begin{center}
\includegraphics[width=0.7\textwidth]{xkcdCorrelation}\\
``Correlation doesn't imply causation, but it does waggle its eyebrows suggestively and gesture furtively while mouthing `look over there.' ''\\
\hfill xkcd.com
\end{center}

For instance, the number of injuries sustained in a swimming pool is correlated with the sales of ice cream cones.  Do ice cream cones cause injuries, or vice versa?  Of course not; it's just that both of them are much more common in warmer weather.

In that case, we call the weather a \textbf{confounder}, a third variable that is related to the two we're interested in.  If we don't consider this third variable, it can fool us into thinking that the other two cause each other.\\

Even if there isn't a confounder, sometimes two variables can be related by coincidence.  There's a book and website by Tyler Vigen (\href{http://tylervigen.com/spurious-correlations}{tylervigen.com}) devoted to showing such correlations.  For example:
\begin{center}
\includegraphics[width=\textwidth]{SpuriousCorrelation}
\end{center}


\vfill
\pagebreak





%%%%Homework problem: ex. of farmland on p. 485 of Navidi and Monk