\documentclass[handout]{beamer}
\usepackage{beamerthemeshadow,psfrag,pst-all,eurosym,comment,soul,fancybox}
\usepackage[english]{babel}
% or whatever
\usepackage[latin1]{inputenc}
\usepackage{wasysym}
% or whatever
\usepackage{times,bm,ulem}
\usepackage[T1]{fontenc}
%\usepackage[usenames,dvipsnames]{xcolor}
\newcommand{\announce}{\setbeamercolor{structure}{fg=green!60!black}}
\newcommand{\sol}{\setbeamercolor{structure}{fg=purple!80!black}}
\newcommand{\normal}{\setbeamercolor{structure}{fg=blue!60!green}}

\newcommand{\seminar}{\setbeamercolor{structure}{fg=orange!60!red}}
\newcommand{\vsp}{\vspace{0.3cm}}
\newcommand{\vspl}{\vspace{0.15cm}}
\newcommand{\xvec}{\boldsymbol{x}}
\newcommand{\yvec}{\vec{y}}
\newcommand{\Xvec}{\boldsymbol{X}}
\newcommand{\Yvec}{\vec{Y}}
\newcommand{\Evec}{\vec{E}}
\newcommand{\tvec}{\bodsymbol{t}}
\newcommand{\Tvec}{\bodsymbol{T}}
\newcommand{\mutau}{\begin{pmatrix}\mu\\\tau\end{pmatrix}}
\newcommand{\thetavec}{\vec{\theta}}
\newcommand{\thetavechat}{\vec{\hat\theta}}
\newcommand{\thetahat}{\hat\theta}
\newcommand{\xvece}{\boldsymbol{x}=(x_1,x_2,\ldots,x_n)^T}
\newcommand{\Xvece}{\boldsymbol{X}=(X_1,X_2,\ldots,X_n)^T}
\newcommand{\thetavece}{\vec{\theta}=(\theta_1,\theta_2,\ldots,\theta_p)^T}
\newcommand{\exxvec}{$x_1,x_2,\ldots,x_n$\xspace}
\newcommand{\exxvecdot}{$x_1,x_2,\ldots,x_n$.\ }
\newcommand{\exXvec}{$X_1,X_2,\ldots,X_n$\ }
\newcommand{\comb}[2]{\,^{#1}\text{C}_{#2}}
%\renewcommand{\jump}[1]{\textcolor{purple}{\boldsymbol{#1}}}

\normal
\title{ACC1012 / 1053:\\ Mathematics \& Statistics} 

\author{Dr. James Waldron, Dr. Kevin Wilson}

%\institute{\textit{Newcastle University, Newcastle upon Tyne, U.K.}}

\vspace{0.15cm}

%\textcolor{blue}{\texttt{lee.fawcett@ncl.ac.uk}, \texttt{david.walshaw@ncl.ac.uk}}}

\date{\textcolor{purple}{\textbf{Semester 2, 2017---2018}}}

\usetheme[height=8mm]{Rochester}

\setbeamercovered{transparent=9}
\begin{document}

\beamertemplatenavigationsymbolsempty

\frame{\titlepage}

%\begin{comment}

\announce

\frame{
\frametitle{Contact details}
\begin{center}
\begin{tabular}{l l}	
\textbf{Semester 1:}		&	Dr. James Waldron			\\
				&					\\
\textbf{Office:}		&	Room 2.14 Herschel Building	\\
				&					\\
\textbf{Phone:}			&	0191 208 8019			\\
				&					\\
\textbf{Email:}			&	\texttt{james.waldron@ncl.ac.uk}	\\
\end{tabular}
\end{center}
}

\frame{
\frametitle{Contact details}
\begin{center}
\begin{tabular}{l l}	
\textbf{Semester 2:}		&	Dr. Kevin Wilson			\\
				&					\\
\textbf{Office:}		&	Room 2.19 Herschel Building	\\
				&					\\
\textbf{Phone:}			&	0191 208 7311			\\
				&					\\
\textbf{Email:}			&	\texttt{kevin.wilson@ncl.ac.uk}	\\
\end{tabular}
\end{center}
}






\begin{frame}
\frametitle{Timetable and Administrative arrangements}
\begin{itemize}
\item \textbf{Lectures} are on Fridays -- 9:30--10:30 in NUBS.1.03, Newcastle Business School

\vspl

%\textcolor{red}{Check your timetable every week!}  \pause
  
\pause

\vspace{0.2cm}

\item Each student should also attend one \textbf{workshop} \vspl \pause
\begin{itemize}
\item [--] Attendance is monitored in \underline{every} session! \pause
\item [--] There are 8 workshops -- you have been allocated to \underline{one}:   \pause

\vspl

{\scriptsize
\begin{center}
\begin{tabular}{|c|c c|l|} \hline
Group         &Day    &Time          &Place            \\ \hline
A             &Mon    &12--1          &Barbara Strang Teaching Centre 2.51   \\
B             &Mon    &1--2          &Barbara Strang Teaching Centre 2.51\\
C             &Mon   &4--5         & Barbara Strang Teaching Centre 2.41B\\
D             &Mon   &5--6        & Herschel Building TR1 (4th floor) \\
E             &Tues   &9--10        &Barbara Strang Teaching Centre 3.31\\
F             &Tues   &12--1          &Barbara Strang Teaching Centre 2.51  \\
G             &Tues    &2--3         &Barbara Strang Teaching Centre 2.51 \\
H             &Thurs  &4--5         & Barbara Strang Teaching Centre 3.31\\ \hline
\end{tabular}
\end{center} 
}




\pause
\vspl
\item [--] These workshops are \underline{vital} for putting into practice what you've been taught in the lecture!
\end{itemize}
\end{itemize}
\end{frame}

\frame{
\frametitle{Timetable and Administrative arrangements}
\begin{itemize}
\item\textbf{Office hours:} Just pop by our office if you need to see us and if we're not busy, we'll be happy to help!  

\vsp

\item \textbf{Revision classes} will be scheduled before the exam next summer
 
\end{itemize}
}



\begin{frame}
\frametitle{Assessment}
Assessment is by:

\vsp

\begin{itemize}
\item Professional Skills/Taxation component (\textbf{30\%})
\pause

\vsp

\item Mathematics \& Statistics component (\textbf{70\%}) \pause
\vspl
\begin{itemize}
\item [--]Written exam at the end of the academic year \textcolor{red}{\bf (50\%)} \pause
\vspl
\item[--] Coursework: Eight small assignments across the year \textcolor{red}{\bf (20\%)}, consisting of computer work/written case study work
\end{itemize}
\end{itemize}
\end{frame}

\frame{
\frametitle{Coursework: Computer--based assessments (CBAs)}
\begin{itemize}
\item A bit like online tests, but not done under test conditions \pause
\vspl
\item Uses our \textit{Numbas} system, via Blackboard -- will demonstrate in a minute \pause
\vspl
\item You should all be familiar with \textit{Numbas} and Blackboard \pause 
\vspl
\item There is a \textcolor{purple}{\bf practice} version for each CBA, where you can log-in and try the questions as many times as you like (the questions/numbers within questions will change slightly each time)\pause
\vspl
\item An \textcolor{purple}{\bf assessed} version of each CBA will be available for {\bf one week only}, during which the practice versions are unavailable -- you must log-in and complete this at some point before the deadline! \pause

\vspl
\item You will be reminded about upcoming deadlines in class
\end{itemize}
}

\frame{
\frametitle{Coursework: Case studies}
\begin{itemize}
\item Require more thought than the CBA questions \pause

\vspl

\item Real--life accounting/finance scenarios and problems \pause

\vspl

\item More open--ended questions \pause

\vspl

\item Designed to make you \textcolor{purple}{\bf understand} the material, not just ``turn the handle''\pause

\vspl

\item You will work in small groups on these in the weekly workshops, under the supervision of me/assistants \pause

\vspl

\item You will hand in an individual report (about 5/6 sides of work including calculations) \pause

\vspl

\item Important that you attend all your workshops!
\end{itemize}
}

\frame{
\frametitle{Deadlines: Semester 1}
\begin{center}
\begin{tabular}{|c|l|} \hline
                \textbf{Assessment}       &\textbf{Deadline}     \\ \hline\hline
                CBA              &Practice mode opens Thurs 5th October 2017 \\
				 &Assessed mode opens Thurs 12th October 2017 \\
                                 &\textcolor{red}{Deadline: 23:59 Wednesday 18th October} \\ \hline \pause
                Case Study       &Start work in tutorials w/b Monday 9th October \\
                 &\textcolor{red}{Deadline: 4pm, Friday 3rd November} \\ \hline \pause
                Case Study       &Start work in tutorials w/b Monday 20th November \\
                                 &\textcolor{red}{Deadline: 4pm, Friday 12th January} \\ \hline \pause
                CBA              &Practice mode opens Thurs 30th November 2017 \\
			 	 &Assessed mode opens Thurs 7th December 2017 \\
                                 &\textcolor{red}{Deadline: 23:59 Wednesday 13th December} \\ \hline
\end{tabular}
\end{center}
\textit{Don't worry -- you will be reminded about these in class!}
}

\frame{
\frametitle{Pre--requisites}
\begin{itemize}
\item A pass in GCSE Maths (grade C+) \pause

\vspl

\item Completion of the \textcolor{purple}{\bf summer revision booklet} -- if you've not looked at this by now, make sure you do before next week!
\end{itemize}
}

\frame{
\frametitle{Other stuff}
\begin{itemize}
\item Notes (with gaps) will be handed out in lectures -- you should fill in the gaps during lectures
\pause

\vspace{0.15cm}

\item A summarised version of the notes will be used in lectures as slides
\pause


\begin{itemize}
\item [--]\color{blue!60!green}{\textbf{Listen and learn}}
\item [--]\color{purple!80!black}{\textbf{Write down}}
\item [--]\color{green!60!black}{\textbf{Announcements}}
\end{itemize} 

\vspace{0.15cm}
\pause
\item These notes and slides will be posted on the \textbf{course website} after each topic is finished, along with any other course material -- such as problems sheets, supplementary handouts etc.   
\end{itemize}
}

\frame{
\frametitle{Other stuff}
\begin{itemize}
\item The course website can be found via the Blackboard page for ACC1012/ACC1053, or directly via:

\begin{center}
\large
\textbf{\texttt{\textcolor{red}{www.mas.ncl.ac.uk/$\sim$nlf8/teaching/acc1012}}} \\
\end{center}

\normalsize

\vspace{0.2cm}

\pause

\item There will be practice questions in the lecture notes -- I will expect you to look at these before the workshops so you're ready for discussion...\pause

\vspace{0.15cm}

\item Please check your University email account regularly, as course announcements will often be made via email


\vspace{0.15cm}

\pause
\item Course textbook: not compulsory that you buy it, but it could help!
\end{itemize}
}




\frame{
\frametitle{Why Maths \& Stats?}
\begin{itemize}
\item Maths \& Stats has a huge role to play in the modern world of accounting and finance \pause

\vspl

\item Case in point: the recent global economic situation \pause
\vspl
\begin{itemize}
\item [--] Mathematical/Statistical indicators are used to quantify the state of a country's economy and identify whether or not that economy is officially in recession \pause
\vspl
\item [--] Mathematical/statistical models are used to forecast periods of recession (and double--dip recession!)
\end{itemize}
\end{itemize}
}

\frame{
\frametitle{Why Maths \& Stats?}
\begin{itemize}
\item Mathematical tools (e.g. \textcolor{red}{Chaos Theory}) are used to map market trends \pause

\vsp

\item At a more basic level: \pause 
\vspl
\begin{itemize}
\item [--] Statistics and probability are used in everyday business and economics \pause
\vspl
\item [--] Employers love graduates with solid numeracy skills, as well as problem--solving skills and the ability to think logically
\end{itemize}
\end{itemize}
}


\frame{
\frametitle{Why Maths \& Stats?}
\begin{itemize}
\item In order to model real--life situations realistically, the maths involved can get quite sophisticated... \pause
\vspl
\item ...so we need to learn to walk before we can run:\pause
\vspl
\begin{itemize}
\item [--]We will start with some very basic maths you would have seen before in your GCSE course, and build up quite gently... \pause
\vspl
\item [--]... it might take you a while to see the relevance of some of the stuff we do, but stick with it!
\end{itemize}
\end{itemize}
}

\normal 


\frame{
\frametitle{ACC1012 / ACC1053}
\LARGE
\begin{center}
\textcolor{purple}{\bf \textit{Any questions...?}}
\end{center}
\normalsize
}

\end{document}

\begin{comment}
\seminar

\frame{

\vspace{1cm}

\huge
\textbf{ACC1012/ACC1053}

\vspace{1cm}

\Large
\textbf{Workshop 1}

}

\frame{
\frametitle{Workshop 1}
\begin{itemize}
\item Welcome to the first workshop! \pause

\vspl

\item These workshops will take place at this time every week -- you must attend the slot you have been allocated to! %\pause

\vspl

\item I will also see you in the lecture on Friday (\textcolor{blue}{\bf 1pm}, \textcolor{blue}{\bf Lecture Theatre 2}, on the \textcolor{blue}{\bf first floor} of \textcolor{blue}{\bf Claremont Tower}) \pause

\vspl

\item What you'll need: Calculator (see webpage for a list of permitted calculators), lecture notes, pens, ruler, paper,... \pause

\vspl

\item Usually, I will also ask you to work through some questions \textit{before} coming to seminars
\end{itemize}
}

\frame{
\frametitle{How will the workshops `work'?}
\begin{itemize}
\item Not all taken by me \pause

\vspl

\item Attendance register \pause

\vsp

\item \textbf{First half:} \pause

\vspl

\begin{itemize}
\item [--] Standard questions that were set the previous week \pause

\vspl

\item [--] More ``standard'' questions \pause

\vspl

\item [--] These questions aren't assessed -- model solutions will be made available during workshop/online at the end of the week \pause

\vspl

\item [--] Staff supervision
\end{itemize}
\end{itemize}
}

\frame{

\frametitle{How will the workshops `work'?}
\begin{itemize}
\item \textbf{Second half:} \pause

\vspl

\begin{itemize}
\item [--] Work on case studies in small groups \pause

\vspl

\item [--] Group discussion \pause 

\vspl

\item [--] Close staff supervision \pause

\vspl

\item [--] This work \textit{is} assessed -- through individual write--up and questions in the last workshop
\end{itemize}
\end{itemize}
}


\frame{
\frametitle{Case studies: More information}
\begin{itemize}
\item Groups of between 4 and 6: \pause allocate randomly/work with friends? \pause 

\vspl

\item Will start the first one next week \pause

\vspl

\item Group discussion in the second half of each workshop until the work is due in

\vspl

\item Idea: to get you to \textcolor{blue}{\bf problem--solve}, interpret \textcolor{blue}{\bf real--life} scenarios, and to promote \textcolor{blue}{\bf deep learning} (as opposed to surface--learning) \pause

\vspl

\item Idea: to learn from each other! \pause

\vspl

\item More open--ended questions related to the scenario, rather than prescribed questions telling you exactly what to do \pause

\vspl

\item You might hate this at first, but give it a chance!  It'll make you a much better person!
\end{itemize}
}

\frame{
\frametitle{Case studies: Assessment}
\begin{itemize}
\item Individual written report after about 4/5 weeks' work in workshops \pause

\vspl

\item 2/3 pages, including write--up and maths \pause

\vspl

\item First one due in \textcolor{blue}{\bf 4pm, Friday 1st November} \pause

\vspl

\item In the last workshop before the written work is due in, you will each be asked a question by me/seminar assistant -- you will get a mark out of 3 for how well you answer this, and this will go towards your final mark for the case study \pause

\vspl

\item Each one (like \textit{all} of your homeworks for me) counts as 2.5\% of the module as a whole \pause

\vspl

\item You will be given an example case study, including write--up, to get you thinking about exactly what we're after
 \pause

\vspl

\item Feedback within two weeks
\end{itemize}
}

\frame{
\frametitle{Other stuff}
\begin{itemize}
\item At some point ASAP, please make sure you can log into our \texttt{Moodle} system which hosts the Numbas CBAs (demo) \pause

\vspl

\item The first CBA will go live in \textcolor{blue}{\bf practice mode} next week... \pause

\vspl

\item ...then assessed mode the week after \pause

\vspl

\item And don't forget our first \textcolor{blue}{\bf lecture} on Friday at \textcolor{blue}{\bf 1pm}, \textcolor{blue}{\bf Lecture Theatre 2}, on the \textcolor{blue}{\bf first floor} of \textcolor{blue}{\bf Claremont Tower}

\end{itemize}
}



\normal

\frame{

\vspace{1cm}

\huge
\textbf{Chapter 1}

\vspace{1cm}

\Large
\textbf{Linear and quadratic functions}

}


\frame{
\frametitle{What we'll cover...}
\begin{itemize}
\item What \textcolor{purple}{\bf are} linear/quadratic functions? \pause
\vspl
\item The role of the \textcolor{purple}{\bf gradient} and \textcolor{purple}{\bf intercept} \pause
\vspl
\item \textcolor{purple}{\bf Graphs} of linear/quadratic functions \pause
\vspl
\item Finding the \textcolor{purple}{\bf equation} of a line \pause
\vspl
\item \textcolor{purple}{\bf Solving} linear equations \pause
\vspl
\item \textcolor{purple}{\bf Simultaneous} linear equations \pause
\vspl
\item \textcolor{purple}{\bf Linear programming} \pause
\vspl
\item \textcolor{purple}{\bf Solving} quadratics using various methods \pause
\vspl
\item Chapters 1 and 2 from the course text would be useful here
\end{itemize}
}


\frame{
\frametitle{1.1 Linear functions}
\textcolor{purple}{\bf Linear functions} occur often in accounting and finance.  \pause

\vsp

You should already be familiar with linear functions from your GCSE maths courses.  \pause For example,
\[
y=3x+4
\]
is a linear function of $x$ which, when operated, gives us $y$.\pause

\vsp

We know this is a linear function because when we produce a graph of this function, we get a straight line.  \pause

\vsp

For example, when $x=2$ we get \pause
\[
y=3\times 2+4 \pause = 6+4 \pause = 10,
\]
bearing in mind the rules of ``\textsc{bidmas}'': \underline{\bf{B}}rackets, \underline{\bf{I}}ndices, \underline{\bf{D}}ivision, \underline{\bf{M}}ultiplication, \underline{\bf{A}}ddition, \underline{\bf{S}}ubtraction. 
}



\frame{
\frametitle{1.1 Linear functions}
Similarly, for other values of $x$:  \pause
\begin{center}
\begin{tabular}{|c|c c c c c c c c|} \hline
$x$       &0   &1 &\textbf{2}  &3  &4  &5  &6  &7 \\ \hline
$y$       &4   &7 &\textbf{10} &13 &16 &19 &22 &25 \\ \hline
\end{tabular}
\end{center} \pause

}

\frame{
\frametitle{1.1 Linear functions}
Plotting $x$ against $y$ and joining up the points gives the graph shown below.

\vspace{-0.5cm}

%\begin{figure}[!h]
\begin{center}
\includegraphics[width=8cm,angle=-90]{graph1.ps}
%\caption{Lee}
\end{center}
}

\frame{
\frametitle{1.1 Linear functions}
Simple linear functions have an \textcolor{purple}{\bf intercept} and a \textcolor{purple}{\bf gradient}. \pause
\vspl
\begin{itemize}

\item Intercept: point at which the line would cut through the $y$--axis \pause -- in A\&F, often represents \textit{fixed costs} \pause
\vspl
\item Gradient: tells us how steep the line is, as well as the direction of the line \pause -- in A\&F, often represents \textit{ cost per unit made/sold} 
\end{itemize}
}

\frame{
\frametitle{1.1 Linear functions}
Generally, the linear function \pause
\[
y=mx + c
\] \pause
has intercept $c$ and gradient $m$. 

\vsp

So, our old friend 
\[
y=3x +4 
\]
has gradient 3 and intercept 4 (we saw the intercept on the graph).   \pause

\vsp

For every unit increase in $x$, $y$ increases by 3 units!
}
\frame{
\frametitle{1.1 Linear functions}
Notice that the gradient is always the number that is ``stuck'' to the $x$; \pause that is, the gradient is the $x$ \textcolor{purple}{\bf coefficient}.\pause

\vsp

Notice also that the highest power in $x$ is a 1 -- because $x^{1}=x$.  There are no terms in $x^{2}$ or $x^{3}$.  Thus, we know we have a linear function.  \pause

\vsp

The intercept is the ``other'' number, and is sometimes called the \textcolor{purple}{\bf constant}.  \pause

\vsp

As we shall shortly see, if the $x$ coefficient is positive, then the graph has an uphill slope; if the $x$ coefficient is negative, then the graph has a downhill slope.  \pause

\vsp

The bigger the coefficient, the steeper the slope, no matter which direction the slope goes in! 

\vsp

We will come back to finding the equation of a line shortly.  
}

\frame{
\frametitle{1.1.1 Solving linear equations}
If we set our linear function equal to a number/constant, then we have a linear \textcolor{purple}{\bf equation}. \pause

\vsp

Solve each of the following linear equations for $x$ and $t$ respectively.
\begin{itemize}
\item [\textbf{1.}] $\displaystyle \frac{6}{x+4}=4$; 

\vsp

\item [\textbf{2.}] $\displaystyle \frac{-4t+4}{5t-6} =-8$. 
\end{itemize}
}

\sol

\frame{
\frametitle{Solution to (1)}
\begin{eqnarray*}
\frac{6}{x+4}  &=& 4 \pause \\
              & & \\
           6  &=&4(x+4) \pause \\
            & & \\
            6 &=&4x + 16 \pause \\
                & & \\
          6-16 &=& 4x \pause \\
         & & \\
           -10 &=&4x \pause \\
 & & \\
            x &=& -\frac{10}{4} = -2.5.
\end{eqnarray*}
}
\frame{
\frametitle{Solution to (2)}
\begin{eqnarray*}
\frac{-4t+4}{5t-6}   &=&-8 \pause \\
& & \\
           -4t+4       &=&-8(5t-6) \pause \\
                    & & \\
              -4t+4 &=&-40t+48 \pause \\
& & \\
               -4t+40t &=&48-4 \pause \\
& & \\
                36t  &=&44 \pause\\
& & \\
                  t &=& \frac{44}{36}  = \frac{11}{9} = 1\frac{2}{9} = 1.222
\end{eqnarray*}
}


\frame{
\frametitle{1.1.2 Finding the equation of a line}
Suppose we are told that the gradient of a line is 6.  We are also told that the line passes through the point $(3,25)$.  What is the equation of this line? \pause

\vsp

We are told that $m=6$, and so we have
\[
y=6x+c.
\] \pause
So now we just need to find $c$!  We are also told that the line passes through the point $(3,25)$, i.e. the point where $x=3$ and $y=25$.  \pause

\vsp

Substituting these values into the above equation gives \pause
\begin{eqnarray*} 
25 &=& (6\times 3) + c \qquad \textrm{\sf i.e.} \\ \pause
25 &=& 18+c.
\end{eqnarray*} \pause
So obviously $c=7$, giving $y=6x+7$.
}

\frame{
\frametitle{1.1.2 Finding the equation of a line}
Suppose we are told that a line passes through the points $(1,3)$ and $(5,35)$.  What is the equation of the line? \pause

\vsp

Again, we need to find the gradient, $m$, and the intercept, $c$. \pause We know that
\begin{eqnarray*}
\textrm{\sf Gradient}  &=& \frac{\textrm{\sf Change in $y$}}{\textrm{\sf Change in $x$}} \\
               & & \\ \pause
                   &=& \frac{35-3}{5-1}  \\
                  & & \\ \pause
                 &=& \frac{32}{4} = 8.
\end{eqnarray*}
}

\frame{
\frametitle{1.1.2 Finding the equation of a line}
So now we have  \pause
\[
y = 8x + c,
\]
 and we just need to find $c$.  \pause

\vsp

We know that the line passes through $(1,3)$, and so substituting $x=1$ and $y=3$ into the above equation gives \pause
\begin{eqnarray*}
3  &=& (8 \times 1) + c \\
3  &=& 8 + c \qquad \textrm{\sf i.e.} \\
3-8 &=& c \qquad \textrm{\sf and so}\\
-5 &=& c.\pause
\end{eqnarray*}
So the equation of the line is $y=8x-5$.  
}

\normal
\frame{
\frametitle{Example 1.1}
The United Nations believes the annual consumption of rice in India ($y$ kilograms per household) is a linear function of the unit cost ($x$ US \$).  

\vsp

They also know that, when the unit cost of rice is \$12, the annual consumption of rice is 40.8kg per household; when this unit cost doubles, the corresponding consumption decreases to 21.6kg per household. 

\vsp
 
\begin{itemize}
\item [\textbf{(a)}] Using this information, obtain the linear function for demand in terms of cost.
\item [\textbf{(b)}] Find the unit cost of rice if the demand is 25kg per household.  
\end{itemize}
}

\sol

\frame{
\frametitle{Example 1.1: Solution to part (a)}
%We are told that 
\begin{eqnarray*}
x &:& \textsf{Cost (\$ US)}\qquad \textsf{and} \\
y &:& \textsf{Consumption (kg)}
\end{eqnarray*}
We are also told that 
\begin{itemize}
\item when $x=12$, $y=40.8$ \pause $\longrightarrow (12,40.8)$,
\item when $x=24$, $y=21.6$ \pause $\longrightarrow (24,21.6)$; thus \pause

\vspl

\end{itemize}
\[
\textsf{Gradient} = \frac{40.8-21.6}{12-24} = -1.6. \pause
\]
Since we are asked to find the {\it linear} demand function, we know that $y=mx+c$ (where $m=-1.6$).  Taking the point $(12,40.8)$: \pause
\begin{eqnarray*}
40.8  &=&-1.6\times 12 + c \\
40.8+1.6\times 12 &=&c\\
60    &=&c.
\end{eqnarray*} \pause
So the linear demand function is $y=-1.6x+60$.  }


\frame{
\frametitle{Example 1.1: Solution to part (b)}
If demand is 25kg per household, then $y=25$. Thus \pause
\begin{eqnarray*}
25  &=&-1.6x + 60 \pause \\
25-60 &=&-1.6x \pause \\
-35  &=&-1.6x \quad \textsf{so} \pause \\
x   &=&21.875,
\end{eqnarray*}
or \$21.88.  }


\normal

\frame{
\frametitle{1.1.3 Solving two linear equations simultaneously}
Solve the following linear equations simultaneously; do \textit{not} use a graph. 
\begin{eqnarray*}
4x + 8y &=& 30 \\
7x - 6y &=& 5.
\end{eqnarray*}
}

\sol

\frame{
\frametitle{Solution}
Let's eliminate the $y$'s.  \pause

\vsp

Multiplying the first equation by 3 and multiplying the second equation by 4 gives: \pause
\begin{eqnarray*}
12x + 24y  &=& 90 \\
28x - 24y  &=&20.
\end{eqnarray*} \pause
The signs of the $y$--coefficients are different, so we add: \pause
\begin{eqnarray*}
12x + 24y  &=& 90 \\
\underline{28x - 24y}  &=&\underline{20} \\ \pause
40x + 0y     &=& 110
\end{eqnarray*} \pause
and so 
\[
x = \frac{110}{40} = \frac{11}{4} = 2.75.  
\]
}
\frame{
\frametitle{Solution}
Substituting $x=2.75$ into  the first equation gives:\pause
\begin{eqnarray*}
4\times 2.75 + 8y&=& 30  \\ \pause
11 + 8y    &=& 30 \\ \pause
       8y   &=&19 \pause \\
 & & \\
             y&=& \frac{19}{8} = 2.375.  
\end{eqnarray*}
}


\begin{comment}
\frame{
\frametitle{Announcements}
\begin{itemize}
\item Numbas CBA1: \pause

\vspl

\begin{itemize}
\item [--] Opens in \textcolor{purple}{\bf assessed mode} next week \pause

\vspl

\item [--] Practice mode will close at the end of this week

\vspl

\item [--] Deadline: \textbf{23:59 Sunday 25th October}  \pause
\end{itemize}

\vsp

\item Case studies -- same topics next week, example write--up available from course webpage
\end{itemize}
}


\frame{
\frametitle{Recap}
\begin{itemize}
\item Linear functions: $y=mx+c$\pause
\begin{itemize}
\item [--] Gradient -- what is it?  Interpetation?  \textit{Practical} intepretation? \pause
\item [--] Intercept -- what is it? Interpretation? \pause
\item [--] How do we know it's linear? \pause
\end{itemize}

\vspl

\item Finding the gradient: \pause
\[
\frac{\textsf{Change in $y$}}{\textsf{Change in $x$}}
\] \pause

\item Finding the equation of the line \pause
\begin{itemize}
\item [--] Gradient--point \pause
\item [--] Point--point
\end{itemize}
\end{itemize}
}

\frame{
\frametitle{Recap}
Consider lines with the equations:
\begin{eqnarray}
y  &=& 4x+17 \\
3y&=&-12x+21 \\
2x &=&10-y
\end{eqnarray}
Which is `steepest'? \pause

\vsp

\textbf{Gradient of (1):} $+4$   \pause

\vspl

\textbf{Gradient of (2):} 
\begin{eqnarray*}
y  &=&-4x+7  \quad \longrightarrow \textsf{Gradient} = -4
\end{eqnarray*} \pause

\vspl

\textbf{Gradient of (3):}
\begin{eqnarray*}
y &=&-2x+10 \quad \longrightarrow \textsf{Gradient} = -2
\end{eqnarray*}
}

\frame{
\frametitle{Recap}
\begin{itemize}
\item Solving linear equations

\vsp

\item Solving two linear equations simultaneously

\end{itemize}
}


\normal

\frame{
\frametitle{Example 1.2}

A cookie company makes two types of biscuit: \textit{standard} and \textit{deluxe}.  \pause Suppose the company makes $x$ batches of standard biscuits and $y$ batches of deluxe biscuits every day. \pause
\vsp 
\begin{itemize}
\item [\textbf{(a)}] Each batch of standard biscuits requires 5kg of flour; each batch of deluxe biscuits requires 8kg of flour.  Every day, exactly 98kg of flour must be used.  Write down a linear equation in $x$ and $y$ for the total amount of flour used each day (in kg).
\vspl
\item [\textbf{(b)}] Each batch of standard biscuits requires 2kg of butter; each batch of deluxe biscuits requires twice as much butter.  Every day, exactly 44 kg of butter must be used.  Write down a linear equation in $x$ and $y$ for the total amount of butter used each day (in kg). 
\vspl 
\item [\textbf{(c)}] How many batches of standard and deluxe biscuits can the company make each day? 
\end{itemize}
}

\sol
\frame{
\frametitle{Example 1.2: Solution to (a) and (b)}
It often helps if you draw up a table: \pause
\begin{center}
\begin{tabular}{|c| c c|} \hline
     &\textbf{Flour (kg)}      &\textbf{Butter (kg)} \\ \hline
Standard ($x$)& 5                   &2                  \\
Deluxe ($y$)  &8                    &4 \\ \hline
\textbf{Total} &98             &44 \\ \hline 
\end{tabular}
\end{center} \pause
Then for flour (part (a)), we would have \pause
\[
5x+8y = 98. \pause
\]

For butter (part (b)), we have \pause
\[
2x+4y = 44.
\]
}

\frame{
\frametitle{Example 1.2: Solution to (c)}
If we keep the flour equation the same, but multiply the butter equation by 2, we get:\pause
\begin{eqnarray*}
5x + 8y  &=& 98 \\
4x + 8y  &=& 88
\end{eqnarray*} \pause
Subtracting to eliminate the $y$'s gives: \pause
\begin{eqnarray*}
1x + 0y &=& 10 \\ \pause
      x &=&10 \pause
\end{eqnarray*}
}
\frame{
\frametitle{Example 1.2: Solution to (c)}
Substituting $x=10$ into the flour equation gives \pause
\begin{eqnarray*}
5\times 10 + 8y &=& 98 \pause \\
     50 + 8y   &=& 98 \pause \\
             8y&=&48 \pause \\
              y &=&6. \pause
\end{eqnarray*}
So, each day, the company must make 10 batches of standard biscuits and 6 batches of deluxe biscuits.  
}

\normal


\frame{
\frametitle{1.2 Quadratic functions}

 As you might imagine, not everything in real--life can be represented by a straight line! \pause

\vsp

At best, the linear functions we have looked at so far -- such as linear cost functions and linear functions for profit -- are simplifications.  \pause

\vsp

With this in mind, in this section we will consider the role of \textcolor{purple}{\bf  non--linear functions}.  
}

\frame{
\frametitle{1.2 Quadratic functions}
In particular, we will think about polynomial functions where the power in $x$ is
greater than 1 (giving a non--linear graph). \pause

\vsp

The simplest case here is the \textcolor{purple}{\bf quadratic function}, where the highest power of $x$ in our polynomial is 2. \pause

\vsp

That is, at most we have an $x^{2}$ term. \pause For example,
\[
y = 5x^{2}-2x + 6
\]
is a quadratic, since the highest power of $x$ is 2.  \pause The polynomial
\[
y = 2x^{4}-3x^{2} + 9
\]
is not a quadratic, since the highest power of x here is 4 (in fact, this is a \textcolor{purple}{\bf quartic}).
}
 
\frame{
\frametitle{1.2.1 Plotting quadratic functions}

In the space below, plot the graph of the function 
\[
y=x^{2}-2x-15. 
\]
}

\sol
\frame{
\frametitle{Solution}
\begin{center}

\begin{tabular}{|c|c c c c |c| c c c c c|} \hline
$x$    &--4   &--3   &--2   &--1   &0   &1  &2   &3   &4  &5\\ \hline
$y$    &\pause 9     &\pause 0     &\pause --7   &--12   &--15&--16&--15 &--12 &--7 &0 \\ \hline
\end{tabular}

\pause
\vspace{0.6cm}

\includegraphics[width=7cm,angle=-90]{graph10newb.ps}
%\caption{Lee}
\end{center}
}

\normal
\frame{
\frametitle{Example 1.5}
The estates manager of a zoo has 100 metres of fencing to construct a rectangular enclosure for some West African camels.  
\begin{itemize}
\item [\textbf{(a)}] Formulate a non--linear function for the area of the enclosure in terms of its width, $x$ metres.  
\item [\textbf{(b)}] Produce a plot of your non--linear function in (a) (see overleaf).
\item [\textbf{(c)}] Using your plot in (b), what length $x$ would give the optimal area for the camel enclosure?  What area would this give?
\end{itemize}
}

\sol

\frame{
\frametitle{Example 1.5: Solution to part (a)}
Consider the diagram: \pause

\vspace{-2cm}

\begin{center}
\includegraphics[width=8cm,angle=-90]{box.ps}
\end{center}

\vspace{-2cm}

The area is obviously $x\times y = xy$, but the question wants the solution in terms of $x$ only.  
}

\frame{
\frametitle{Example 1.5: Solution to part (a)}
Now \pause
\[
\textsf{Perimeter} = x + x + y + y = 2x + 2y = 100.
\] \pause
Therefore we can write \pause
\begin{eqnarray*}
2y  &=& 100-2x \qquad \textsf{i.e.} \\ \pause
 y  &=& 50-x.
\end{eqnarray*} \pause

So now
\begin{eqnarray*}
\textsf{Area} &=& x \times y \\ \pause
              &=&x(50-x) \\ \pause
              &=&50x-x^{2}.
\end{eqnarray*}
}

\frame{
\frametitle{Example 1.5: Solution to part (b)}
\begin{center}
\includegraphics[width=8cm,angle=-90]{graph11sol.ps}
%\caption{Lee}
\end{center}}
\frame{
\frametitle{Example 1.5: Solution to part (c)}
From the graph, we can see that a length of $x=25m$ would give the largest area for the camel enclosure. \pause

\vsp

This would give an area of \pause
\begin{eqnarray*}
\textsf{Area}  &=& 50\times 25 - 25^{2} \\ \pause
           &=& 625 \textsf{m}^{2}.
\end{eqnarray*}
}

\normal

\frame{
\frametitle{1.2.1 Plotting quadratic functions}
As with linear functions, it would be useful to be able to plot or sketch a non--linear function without having to draw up a full table of results. \pause

\vsp

For a quadratic function, it might be useful to know where the curve cuts into the $x$--axis, as well as the $y$--intercept of the curve.  \pause

\vsp

Consider the quadratic from the earlier example: $y=x^{2}-2x-15$.  We know the $y$--intercept occurs when $x=0$, that is
\[
y = 0^{2}-2\times 0 -15 = -15,
\]
and this can be seen in our plot of this function.  

\vsp

\textcolor{white}{However, how can we tell, without drawing up a full table of results, where the curve will cut the $x$--axis? }}

\frame{
\frametitle{1.2.1 Plotting quadratic functions}
\begin{center}
\includegraphics[width=8cm,angle=-90]{graph10newb.ps}
%\caption{Lee}
\end{center}
}

\frame{
\frametitle{1.2.1 Plotting quadratic functions}
As with linear functions, it would be useful to be able to plot or sketch a non--linear function without having to draw up a full table of results.

\vsp

For a quadratic function, it might be useful to know where the curve cuts into the $x$--axis, as well as the $y$--intercept of the curve. 

\vsp

Consider the quadratic from the earlier example: $y=x^{2}-2x-15$.  We know the $y$--intercept occurs when $x=0$, that is
\[
y = 0^{2}-2\times 0 -15 = -15,
\]
and this can be seen in our plot of this function.  

\vsp

\textbf{However, how can we tell, without drawing up a full table of results, where the curve will cut the $x$--axis? }}


\frame{
\frametitle{1.2.1 Plotting quadratic functions}
The curve cuts the $x$--axis when $y=0$, that is when
\[
x^{2}-2x-15 = 0,
\]
and so we would need to solve this equation for $x$.  However, this is an example of a \textcolor{purple}{\bf quadratic equation}, and we haven't considered how to solve these yet... 
}

\frame{
\frametitle{1.2.2 Quadratic equations}
We can visualise the solution(s) for $x$ in the equation \pause
\[
ax^{2}+bx+c = 0
\] \pause
by looking at a plot of the quadratic and noting where the curve intersects/touches the line $y=0$, that is, the $x$--axis. \pause

\vsp

 However, the accuracy of our solutions obtained in this way will depend on the accuracy of our graph.  \pause

\vsp

We would also need to know what range of $x$--values to draw the graph over. \pause

\vsp

 Two approaches for solving quadratics a bit more mathematically will now be considered.  }


\frame{
\frametitle{1.2.2 Quadratic equations}
In both, we will assume the general form of a quadratic as
\[
y = ax^{2}+bx+c;
\] \pause
the \textcolor{purple}{\bf discriminant}, $D$, is given by \pause
\[
D = b^{2}-4ac,
\] \pause
and has important properties in terms of how we classify the solutions to our quadratic.  
}

\frame{
\frametitle{1.2.2 Quadratic equations: Factorisation}
If the discriminant is a perfect square -- that is, if the square root of $D$ is an integer -- then we can solve our quadratic by the method of \textcolor{purple}{\bf factorisation}.\pause

\vsp

Consider the following quadratic equations:
\begin{itemize}
\item [1.] $x^{2}-2x-15 = 0$ 
\item [2.] $x^{2}+5x+2=0$
\item [3.] $x^{2}-8x+12 = 0$ 
\item [4.] $x^{2}-5x-36=0$
\item [5.] $2x^{2}-7x+5=0$
\end{itemize}

\vspace{0.5cm}

\begin{itemize}
\item [\textbf{(a)}] For each, find the discriminant $D$.
\item [\textbf{(b)}] Which equations can be solved by factorisation?
\item [\textbf{(c)}] Solve the equations identified in (b) by factorisation.
\end{itemize}
}


\sol

\frame{
\frametitle{Solution to (a)}
\begin{itemize}
\item [1.] $x^{2}-2x-15 = 0$  \pause
\[
D = (-2)^{2} - (4\times 1 \times -15) = \pause 64
\]\pause

\vsp

\item [2.] $x^{2}+5x+2=0$ \pause
\[
D = 5^{2} - (4\times 1\times 2) = \pause 17 
\] \pause

\vsp

\item [3.] $x^{2}-8x+12 = 0$  \pause
\[
D = (-8)^{2} - (4\times1\times12) = \pause 16
\]
\end{itemize}
}

\frame{
\frametitle{Solution to (a)}
\begin{itemize}
\item [4.] $x^{2}-5x-36=0$ \pause
\[
D = (-5)^{2} - (4\times 1 \times -36) = \pause 25+144 = 169
\] \pause

\vsp

\item [5.] $2x^{2}-7x+5=0$ \pause
\[
D = (-7)^{2} -(4 \times 2 \times 5) =\pause 9
\]

\end{itemize}
}

\frame{
\frametitle{Solution to (b)}
Note that the discriminant for Equation (1) was $D=64$:
\[
\sqrt{64} = 8,
\]
which is an integer value; thus $\boldsymbol{D}$ \textbf{is a perfect square}, and so we can solve this equation by factorisation.   \pause

\vsp

In fact, we can solve all but equation (2) by factorisation -- equation 2 is the only one where the discriminant is {\it not} a perfect square. 
}


\frame{
\frametitle{Solution to (c)}
\textbf{Equation (1):}

\vsp

Sinced $D$ was a perfect square, we can factorise our quadratic; in fact, 
\[
x^{2}-2x-15 = (x-5)(x+3).
\] \pause
How did we do this?  \pause
\begin{itemize}
\item The first term inside each pair of brackets must be $x$; \pause
\vspl
\item The other two numbers must add together to give the $x$--coefficient (e.g. {\color{red} $-5+3 =-2$})... \pause
\vspl
\item...and must multiply to give the constant (e.g. {\color{red}$-5 \times 3 = -15$})
\end{itemize}
}

\frame{
\frametitle{Solution to (c)}
 We can check our factorisation by expanding the brackets using the \textbf{F-O-I-L} rule, standing for ``\textbf{F}irst two'', ``\textbf{O}utside two'', ``\textbf{I}nside two'', ``\textbf{L}ast two'': \pause
\begin{eqnarray*}
\textbf{F}   &:& x \times x = x^{2} \\ \pause
\textbf{O}   &:&x \times 3 = 3x \\\pause
\textbf{I}   &:&-5 \times x = -5x \\ \pause
\textbf{L}   &:&-5 \times 3 = -15, \pause
\end{eqnarray*}
giving 
\[
x^{2}+3x-5x-15 = \pause x^{2}-2x-15,
\]
which is exactly what we started with!  
}


\frame{
\frametitle{Solution to (c)}
So now we know that
\[
x^{2}-2x-15 = (x-5)(x+3) = 0,
\]
we know that either $(x-5)=0$ or $(x+3)=0$. \pause So we have
\begin{eqnarray*}
x-5 = 0    &\textrm{\sf or}  & x+3 = 0 \\ \pause
  x=5      &\textrm{\sf or}  &x=-3,
\end{eqnarray*}
and these are the values we see on the graph on page 19.  
}


\frame{
\frametitle{Solution to (c)}
\textbf{Equation (3):}
\begin{eqnarray*}
x^{2}-8x+12 &=&0 \\ \pause
(x-6)(x-2)   &=&0,\pause
\end{eqnarray*}
so $x=6$ or $x=2$.  }

\frame{
\frametitle{Solution to (c)}
\textbf{Equation (4): }
\begin{eqnarray*}
x^{2}-5x-36&=&0 \\ \pause
(x-9)(x+4) &=&0, \pause
\end{eqnarray*}
so $x=9$ or $x=-4$. \pause

\vsp

\textbf{Equation (5):}
\begin{eqnarray*}
2x^{2}-7x+5&=&0 \\ \pause
(2x-5)(x-1)&=& 0, \pause 
\end{eqnarray*}
so $(2x-5)=0$ or $(x-1)=0$. \pause From the first: \pause
\[
2x = 5 \pause \rightarrow x=2.5,
\]
and also $x=1$.
}

\normal

\begin{comment}

\frame{
\frametitle{Announcements: CBA1}
\begin{itemize}
\item Live right now in assessed mode \pause

\vspl

\item Have been some issues - check that I've replied to your emails \pause

\vspl

\item Deadline: \textcolor{red}{23:59, Sunday 25th October}
\end{itemize}
}

\frame{
\frametitle{Announcements: Case studies}

\begin{itemize}
\item Decide on your $x$ and $y$ variables  \pause

\vspl

\item See if you can find the co-ordinates of two points from which you can formulate a linear function.  For example:
\begin{center}
\begin{tabular}{c|c}
 $x$ (Consumption / Selling price)   & $y$ (Price / Units produced) \\ \hline
$x_{1}$        &$y_{1}$ \\
$x_{2}$        &$y_{2}$  \\ 
\end{tabular}
\end{center}

\vspl

\item Do this twice!  We're looking for at least two linear functions in each case study... \pause

\vspl

\begin{itemize}
\item [--]Alcohol: Thai government's research versus \textit{Singha}'s research \pause

\vspl

\item [--] iPhone: Supply versus demand
\end{itemize} \pause

\vspl

\item Don't worry \textit{too much} about \textit{elasticity} or \textit{ceiling price} \pause

\vspl

\item Remember to look at example report; equation editor handout for MS WORD; graphical software in ``Videos'' 
\end{itemize}
}



\frame{
\frametitle{Non--linear functions: the story so far...}
\begin{itemize}
\item Any polynomial where the highest power of $x>1$ \pause

\vspl

\item Simplest non--linear function: \textcolor{purple}{\bf Quadratics}, where the highest power is 2 (i.e. a term in $x^{2}$) \pause

\vspl

\item General form: $ax^{2}+bx+c$, with \textcolor{purple}{\bf discriminant}
\[
D=b^{2}-4ac
\]
\pause

\vspl

\item Should know how to \textit{plot} these \pause

\vspl

\item Should know how to \textit{solve} these when set equal to zero: \pause

\vspl

\begin{itemize}

\item [--] by factorisation (when $D$ is a perfect square) \pause

\vspl

\item [--] by the \textcolor{purple}{\bf quadratic formula}
\end{itemize}
\end{itemize}
}

\normal

\frame{
\frametitle{1.2.2 Quadratic equations: formula}
\noindent If we cannot factorise our quadratic, then we can use the \textcolor{purple}{\bf quadratic formula} in order to find the solution(s) to our quadratic equation. \pause

\vsp

For example, consider equation (2) in the last question:
\[
x^{2}+5x+2 = 0.
\]
The discriminant
\[
D = 5^{2} - 4\times 1 \times 2 = 17,
\]
which is not a perfect square.  
}

\frame{
\frametitle{1.2.2 Quadratic equations: formula}
All is not lost -- we can use the quadratic formula! \pause

\vsp

\begin{itemize}
\item Developed by \textcolor{purple}{\bf Indian mathematicians} around 628AD \pause
\vspl
\item The formula as we know it today was not published until 1637 by a \textcolor{purple}{\bf French mathematician}\pause
\vspl
\item In fact, the formula can \textit{always} be used -- whether the discriminant is a perfect square or not!
\end{itemize} 
}


\frame{
\frametitle{1.2.2 Quadratic equations: formula}
 The solution(s) to the equation
\[
ax^{2}+bx+c=0,
\]
with discriminant $D=b^{2}-4ac$, are given by the formula \pause
\[
x=\frac{-b\pm \sqrt{D}}{2a}.
\]
}

\frame{
\frametitle{1.2.2 Quadratic equations: formula}
Consider the quadratic we plotted on page 19:
\[
y=x^{2}-2x-15.
\] \pause
The graph showed that when $y=0$ the solutions were $x=5$ and $x=-3$.\pause

\vsp

Note that $a=1$, $b=-2$ and $c=-15$.  Thus the discriminant is
\[
D =  (-2)^{2} - 4 \times 1 \times -15 = 64.
\] \pause
So by the formula, we have
\begin{eqnarray*}
x   &=& \frac{-(-2)\pm \sqrt{64}}{2 \times 1} \\ \pause
     & & \\
    &=& \frac{2 \pm 8}{2}.
\end{eqnarray*}}

\frame{
\frametitle{1.2.2 Quadratic equations: formula}
So the solutions are given by 
\[
x = \frac{2+8}{2} = \frac{10}{2} = 5,
\] \pause
or
\[
x=\frac{2-8}{2} = \frac{-6}{3} = -3,
\] \pause
exactly the solutions we obtained graphically (and by factorisation)!
}

\sol

\frame{
\frametitle{1.2.2 Quadratic equations: formula}

Solve the quadratic equation
\[
  x^{2}+5x+2 = 0.
\] \pause

\vsp

\textbf{Solution} \pause

\vsp

The discriminant is \pause
\[
D = 5^{2} - (4\times 1 \times 2) = 17.
\] \pause
Thus, we have \pause
\[
x   =\frac{-5\pm\sqrt{17}}{2},
\]
}

\frame{
\frametitle{1.2.2 Quadratic equations: formula}
giving \pause
\begin{eqnarray*}
x  &=&\frac{-5+\sqrt{17}}{2} \\
   & & \\
    &=& -0.44 \pause
\end{eqnarray*}

\textbf{or} \pause
\begin{eqnarray*}
x  &=&\frac{-5-\sqrt{17}}{2} \\
   & & \\
    &=& -4.56 \pause
\end{eqnarray*}
}

\normal
\frame{
\frametitle{Example 1.6}
A company models its annual profits using the function
\[
P(x) = x^{2}+20x-300,
\]
where $P$ represents profits and $x$ is the number of units sold.  In 2011 their profits were \pounds 167,700.  How many units of their product did they sell?
}

\sol

\frame{
\frametitle{Example 1.6: Solution}
We set the equation equal to 167700 and solve for $x$: \pause
\begin{eqnarray*}
x^{2}+20x-300 &=& 167700 \pause \\
  x^{2}+20x-300-167700 &=& 0 \pause \\
    x^{2}+20x-168000  &=&0 \pause
\end{eqnarray*}
Now the discriminant is \pause
\[
D = 20^{2} - (4 \times 1 \times -168000) = 672400,
\]\pause
and so
\begin{eqnarray*}
x  &=& \frac{-20 \pm \sqrt{672400}}{2} \pause \\ \pause
 & & \\
    &=& \frac{-20 \pm 820}{2}.
\end{eqnarray*}
}
\frame{
\frametitle{Example 1.6: Solution}
So
\[
x  =\frac{-20+820}{2} = 400 \pause
\]
or 
\[
x = \frac{-20-820}{2} = -420.
\]
Obviously we can't sell a negative number of units, and so $x=400$.\pause

\vsp
Note the discriminant was a perfect square and so we could have solved this quadratic via factorisation.  
}


\normal

\frame{
\frametitle{Example 1.7}
The manager of a vineyard thinks there is a relationship between the average temperature during the grape--growing season ($t^{\textrm{o}}\textrm{C}$) and the quality of the grapes produced and hence the selling price of resulting bottles of wine ($p$ pounds).  
}

\frame{
\frametitle{Example 1.7}
Over a ten year period the following relationship is revealed:
\begin{center}
\psfrag{5}[][]{\sf \tiny 5}
\psfrag{6}[][]{\sf \tiny 6}
\psfrag{7}[][]{\sf \tiny 7}
\psfrag{8}[][]{\sf \tiny 8}
\psfrag{9}[][]{\sf \tiny 9}
\psfrag{10}[][]{\sf \tiny 10}
\psfrag{16}[][]{\sf \tiny 16}
\psfrag{18}[][]{\sf \tiny 18}
\psfrag{20}[][]{\sf \tiny 20}
\psfrag{22}[][]{\sf \tiny 22}
\psfrag{24}[][]{\sf \tiny 24}
\psfrag{t}[][]{\sf \tiny Temperature ($t^{\textrm{o}}\textrm{C}$)}
\psfrag{p}[][]{\sf \tiny Price (\pounds $p$)}
\includegraphics[width=9cm,height=6cm]{Rplot1.ps}
\end{center}
}

\frame{
\frametitle{Example 1.7}
\begin{itemize}
\item [\textbf{(a)}] Which model would best suit the relationship shown?
\begin{itemize}
\item [*] $p = 0.2t+4.4$
\item [*] $p = 0.2t^{2}-8t+70$
\item  [*]$p = -0.2t^{2}+8t-70$
\end{itemize}

\vsp

\item [\textbf{(b)}] Suppose the manager needs to sell this variety of wine in 2013 for at least \pounds 9 per bottle.  What is the critical range of temperatures required to meet this price?
\end{itemize}
}

\sol
\frame{
\frametitle{Example 1.7: Solution to part (a)}
Clearly, it cannot be the first equation, as this is a linear equation and we have a non--linear relationship.  \pause

\vsp

Of the two remaining quadratics, it must be the last one to give the ``upside--down'' curve we see in the graph (negative coefficient for $t^{2}$).
}

\frame{
\frametitle{Example 1.7: Solution to part (b)} 
We set $p=9$ and solve for $t$: \pause
\begin{eqnarray*}
-0.2t^{2}+8t-70   &=& 9 \pause \\
 -0.2t^{2}+8t -70-9 &=&0 \pause \\
-0.2t^{2}+8t - 79  &=&0.
\end{eqnarray*}
Now $a=-0.2$, $b=8$ and $c=-79$, giving \pause
\[
D = 8^{2} - (4\times -0.2 \times -79) = 0.8. \pause
\]
}

\frame{
\frametitle{Example 1.7: Solution to part (b)} 
So
\[
x   = \frac{-8 \pm \sqrt{0.8}}{-0.4},
\] \pause
giving
\[
x = \frac{-8+\sqrt{0.8}}{-0.4}  = 17.76
\]\pause
and
\[
x  = \frac{-8-\sqrt{0.8}}{-0.4}  = 22.24.
\] 
\pause
So any temperatures between $17.8^{\textrm{o}}\textrm{C}$ and $22.2^{\textrm{o}}\textrm{C}$ should give bottles of wine that sell for at least \pounds 9.
}

%\frame{
%\frametitle{Example 1.7: Solution to part (b)}
%\begin{center}
%\psfrag{16}[][]{\sf \tiny 16}
%\psfrag{18}[][]{\sf \tiny 18}
%\psfrag{20}[][]{\sf \tiny 20}
%\psfrag{22}[][]{\sf \tiny 22}
%\psfrag{24}[][]{\sf \tiny 24}
%\psfrag{5}[][]{\sf \tiny 5}
%\psfrag{6}[][]{\sf \tiny 6}
%\psfrag{7}[][]{\sf \tiny 7}
%\psfrag{8}[][]{\sf \tiny 8}
%\psfrag{9}[][]{\sf \tiny 9}
%\psfrag{10}[][]{\sf \tiny 10}
%\psfrag{p}[][]{$p$}
%\psfrag{t}[][]{$t$}
%\includegraphics[width=11cm,height=7cm]{wine1.ps}
%\end{center}
%}

%\frame{
%\frametitle{Example 1.7: Solution to part (b)}
%\begin{center}
%\psfrag{16}[][]{\sf \tiny 16}
%\psfrag{18}[][]{\sf \tiny 18}
%\psfrag{20}[][]{\sf \tiny 20}
%\psfrag{22}[][]{\sf \tiny 22}
%\psfrag{24}[][]{\sf \tiny 24}
%\psfrag{5}[][]{\sf \tiny 5}
%\psfrag{6}[][]{\sf \tiny 6}
%\psfrag{7}[][]{\sf \tiny 7}
%\psfrag{8}[][]{\sf \tiny 8}
%\psfrag{9}[][]{\sf \tiny 9}
%\psfrag{10}[][]{\sf \tiny 10}
%\psfrag{p}[][]{$p$}
%\psfrag{t}[][]{$t$}
%\includegraphics[width=11cm,height=7cm]{wine2.ps}
%\end{center}
%}

\frame{
\frametitle{Example 1.7: Solution to part (b)}
\begin{center}
\psfrag{16}[][]{\sf \tiny 16}
\psfrag{18}[][]{\sf \tiny 18}
\psfrag{20}[][]{\sf \tiny 20}
\psfrag{22}[][]{\sf \tiny 22}
\psfrag{24}[][]{\sf \tiny 24}
\psfrag{5}[][]{\sf \tiny 5}
\psfrag{6}[][]{\sf \tiny 6}
\psfrag{7}[][]{\sf \tiny 7}
\psfrag{8}[][]{\sf \tiny 8}
\psfrag{9}[][]{\sf \tiny 9}
\psfrag{10}[][]{\sf \tiny 10}
\psfrag{p}[][]{$p$}
\psfrag{t}[][]{$t$}
\includegraphics[width=11cm,height=7cm]{wine3.ps}
\end{center}
}


\normal
\frame{
\frametitle{Summary}

\begin{itemize}
\item If $D$ is a perfect square, then we can solve the quadratic by \textcolor{purple}{\bf factorisation}; otherwise, we can use the \textcolor{purple}{\bf formula} (in fact, the formulae will always work!)\pause

\vspl

\item If $D>0$, our quadratic will have \textcolor{purple}{\bf two real solutions} -- that is, the curve will cut the $x$--axis in two places\pause

\vspl

\item If $D=0$, then our quadratic will have \textcolor{purple}{\bf repeated solutions} -- that is, our graph only just touches the $x$--axis \pause

\vspl

\item If $D<0$, then we cannot operate the quadratic formula as we cannot take the square root of a negative -- at least, not in the real number system.  Actually, such a quadratic has \textcolor{purple}{\bf complex roots} making use of the complex number system, but this goes beyond the scope of ACC1012/53.  
\end{itemize}
}

\frame{
\frametitle{1.3 Higher--order polynomials}
In more complicated accounting and finance problems, linear and/or quadratic functions might still not be adequate enough to model our situation realistically.  Higher--order polynomials can be used, such as \textcolor{purple}{\bf cubics}: \pause
\[
y = ax^{3}+bx^{2}+cx +d,
\]
or even \textcolor{purple}{\bf quartics}: \pause
\[
y=ax^{4}+bx^{3}+cx^{2}+dx + e;
\]\pause
We will return to such functions in Chapter 3 of this course.  
}


\frame{
\begin{center}
Now back to page 8...
\end{center}
}
\normal

\frame{
\frametitle{1.1.4 Linear programming}

\noindent \textcolor{purple}{\bf Dynamic programming} techniques were developed during the Second World War by a group of American mathematicians.\pause

\vsp

They sought to produce mathematical models of situations in which all the \textcolor{purple}{\bf requirements}, \textcolor{purple}{\bf constraints} and \textcolor{purple}{\bf objectives} were expressed as algebraic equations. \pause

\vsp

They then developed methods for obtaining the \textcolor{purple}{\bf optimal solution} -- the maximum or minimum value of a required function. 
}

 
\frame{
\frametitle{1.1.4 Linear programming}
In this section, we will attempt to formulate the requirements, constraints and objectives of real--life accounting and finance problems as linear equations. \pause

\vsp

This branch of dynamic programming is referred to as \textcolor{purple}{\bf linear programming}, for obvious reasons. \pause

\vsp

Thus, all algebraic expressions will be of the form 
\begin{eqnarray*}
(\textrm{\sf a number})x + (\textrm{\sf a number})y;
\end{eqnarray*} \pause
for example, 
\begin{eqnarray*}
\textrm{\sf Profit}	&=& 4x - 3y
\end{eqnarray*}
is a linear equation for profit in terms of $x$ and $y$, where $x$ might represent our expenditure on advertising and $y$ might be our costs. 
}

\frame{
\frametitle{1.1.4 Linear programming} 

\noindent Linear programming methods are some of the most widely used methods employed to solve management and economic problems.  

\vsp

They have been applied in a variety of contexts, some of which will be discussed in this chapter, with enormous savings in money and resources.  

\vsp

The first step is to \textcolor{purple}{\bf formulate} a problem as a linear programming problem; \pause the second step is to \textcolor{purple}{\bf solve} the problem.  
}

\frame{
\frametitle{1.1.4 Linear programming}
As well as drawing upon our recent work on linear equations, in this section we also need to think about linear \textcolor{purple}{\bf inequalities}; \pause for example, 
\begin{eqnarray*}
16x +18y &\leq& 25
\end{eqnarray*}
is a linear inequality in $x$ and $y$.  The role of inequalities will become apparent as we work through some examples.  
}

\frame{
\frametitle{1.1.4 Formulating linear programming problems}
\noindent The first step in formulating a linear programming problem is to determine which quantities you need to know to solve the problem.  These are called the \textcolor{purple}{\bf decision variables}.  \pause

\vsp

\noindent The second step is to decide what the \textcolor{purple}{\bf constraints} are in the problem.  For example, there may be a limit on resources. \pause

\vsp

\noindent The third step is to determine the obective to be achieved.  This is the quantity to be maximised or minimised, that is, \textit{optimised}.  The function of the decision variables that is to be optimised is called the \textcolor{purple}{\bf objective function}.  
}

\frame{
\frametitle{Example 1.3: The chair manufacturer}
\noindent A manufacturer makes two kinds of chairs -- \textcolor{purple}{\textbf{A}} and \textcolor{purple}{\textbf{B}}.  Each type of chair has to be processed in two departments -- \textrm{\textbf{I}} and \textrm{\textbf{II}}.
\pause

\vspace{0.3cm}


\noindent Chair \textcolor{purple}{\textbf{A}} spends 3 hours in department \textrm{\textbf{I}} and 2 hours in department \textrm{\textbf{II}}.  Chair \textcolor{purple}{\textbf{B}} spends 3 hours in department \textrm{\textbf{I}} and 4 hours in department \textrm{\textbf{II}}.  
}

\frame{
\frametitle{Example 1.3: The chair manufacturer}
\noindent The time available in department \textrm{\textbf{I}} in any given month is 120 hours, and the time available in department \textrm{\textbf{II}} in the same month is 150 hours.  
\pause

\vspace{0.3cm}

\noindent Chair \textcolor{purple}{\textbf{A}} has a selling price of \pounds 10 and chair \textcolor{purple}{\textbf{B}} of \pounds 12.  
}

\frame{
\frametitle{Example 1.3: The chair manufacturer}
\noindent The manufacturer wishes to maximise his income.  
\pause

\vspace{0.5cm}

\textbf{How many of each type of chair should be made?}
}


\frame{
\frametitle{Example 1.3: The chair manufacturer}
\noindent You'll notice that there's a lot of information given in the question -- this is typical of a linear programming problem.  Sometimes it's easier to summarise the information given in a table:
\pause

\vspace{0.3cm}

\begin{center}
\small
\begin{tabular}{|c| c| c| c|} \hline 
Chair		&Time in dept. \textrm{I} 	&Time in dept. \textrm{II} 	&Selling price 	\\ \hline
\textcolor{purple}{\textbf{A}}			&3				&2				&10				\\
\textcolor{purple}{\textbf{B}}			&3				&4				&12				\\ \hline
Time limits 		&120		&150				&				\\ \hline
\end{tabular}
\normalsize
\end{center}
}
\frame{
\frametitle{Example 1.3: The chair manufacturer}
\noindent To formulate this linear programming problem, we consider the following three steps:
\pause
\begin{itemize}
\item [\textbf{1.}]	What are the \textcolor{purple}{\textbf{decision variables}}?  (i.e. which quantities do you need to know in order to solve the problem?)
\pause
\item [\textbf{2.}] What are the \textcolor{purple}{\textbf{constraints}}?
\pause
\item [\textbf{3.}] What is the \textcolor{purple}{\textbf{objective}}?
\end{itemize} 
}


\frame{
\frametitle{Step 1: Decision variables}
\noindent Read through the question and identify the things you'd like to know.  You can usually do this by going straight to the last sentence of the question: 
\pause
\begin{center}
\textbf{``How many of each chair should be made...''}
\end{center}
\pause
Thus, we'd like to know 
\begin{itemize}
\item the number of type \textcolor{purple}{\textbf{A}} chairs to make, and
\item the number of type \textcolor{purple}{\textbf{B}} chairs to make. 
\end{itemize}
}

\frame{
\frametitle{Step 1: Decision variables}
\noindent These are our decision variables, and are usually denoted with lower case letters.  Thus, our decision variables are
\pause
\begin{eqnarray*}
x&=& \textrm{\sf number of type \textcolor{purple}{\textbf{A}} chairs made}	\qquad \textrm{\sf and}	\\
\pause
y&=& \textrm{\sf number of type \textcolor{purple}{\textbf{B}} chairs made.}
\end{eqnarray*}
}

\frame{
\frametitle{Step 2: Constraints}
\noindent This is probably the hardest bit!  Consider what could happen in each department.  
\pause

\vspace{0.3cm}

\noindent For example, if we focus on what could happen in department \textrm{\textbf{I}}:
\pause
\begin{center}
\begin{tabular}{l l}
Since:		&the production of 1 type \textcolor{purple}{\textbf{A}} chair uses 3 hours,\\
\pause
then:		&the production of $x$ type \textcolor{purple}{\textbf{A}} chairs takes $\textrm{\sf 3}x$ hours.\\
		&						\\ \pause
Similarly:	&the production of 1 type \textcolor{purple}{\textbf{B}} chair uses 3 hours,\\
\pause
so:		&the production of $y$ type \textcolor{purple}{\textbf{B}} chairs takes $\textrm{\sf 3}y$ hours.\\
\end{tabular}
\end{center}
}

\frame{
\frametitle{Step 2: Constraints}
\noindent The total time used in department \textrm{\textbf{I}} is therefore 
\pause
\begin{eqnarray*}
(\textrm{\sf 3}x + \textrm{\sf 3}y) \textrm{ \sf hours}.
\end{eqnarray*}
\pause
Since only 120 hours are available in department \textrm{\textbf{I}}, one constraint is
\pause
\begin{eqnarray*}
(\textrm{\sf 3}x+\textrm{\sf 3}y) \textrm{ \sf hours} &\leq& \textrm{\sf 120} \textrm{ \sf hours}, \qquad \textrm{ \sf or just}	\\
\pause
(\textrm{\sf 3}x+\textrm{\sf 3}y)	&\leq& \textrm{\sf 120}.
\end{eqnarray*}
}


\frame{
\frametitle{Step 2: Constraints}
\noindent Considering department \textrm{\textbf{II}} in a similar way, we get:
\begin{center}
\begin{tabular}{l l}
Since:		&the production of 1 type \textcolor{purple}{\textbf{A}} chair uses 2 hours,\\	\pause
then:		&the production of $x$ type \textcolor{purple}{\textbf{A}} chairs takes 2$x$ hours.  \\ \pause
		&						\\
Similarly:	&the production of 1 type \textcolor{purple}{\textbf{B}} chair uses 4 hours,\\	\pause
so:		&the production of $y$ type \textcolor{purple}{\textbf{B}} chairs takes 4$y$ hours.\\
\end{tabular}
\end{center}
}

\frame{
\frametitle{Step 2: Constraints}
\noindent The total time used is therefore
\pause
\begin{eqnarray*}
(\textrm{ \sf 2}x+\textrm{\sf 4}y) \textrm{ \sf hours}.
\end{eqnarray*}
\pause
Since only 150 hours are available in department \textrm{\textbf{II}}, a second constraint is
\begin{eqnarray*}
(\textrm{\sf 2}x+\textrm{ \sf 4}y) \textrm{ \sf hours} &\leq& \textrm{ \sf 150} \textrm{ \sf hours}, \qquad \textrm{\sf or just}	\\
\pause
(\textrm{\sf 2}x + \textrm{\sf 4}y) &\leq& \textrm{\sf 150}.
\end{eqnarray*}
}


\frame{
\frametitle{Step 2: Constraints}
\noindent We're still not done! We can't make a negative number of chairs, so we also have:
\pause
\begin{eqnarray*}
x &\geq& \textrm{\sf 0} 	\qquad \textrm{\sf and}	\\
y &\geq& \textrm{\sf 0}.
\end{eqnarray*}
\pause
\noindent These are called the \textbf{non--negativity constraints}.
}

  
\frame{
\frametitle{Step 3: Objective function}
\noindent Our objective here is to \textbf{maximise income}.  
\pause

\vspace{0.3cm}

\noindent If we make $x$ type \textcolor{purple}{\textbf{A}} chairs, then we get \pounds$\textrm{\sf 10} \times x = \textsf{\pounds} \textrm{\sf 10}x$, since each type \textcolor{purple}{\textbf{A}} chair sells for \pounds$\textrm{\sf 10}$.  
\pause

\vspace{0.3cm}

\noindent Similarly, if we make $y$ type \textcolor{purple}{\textbf{B}} chairs, then we get \pounds $\textrm{\sf 12} \times y = \textsf{\pounds} \textrm{\sf 12}y$, since each type \textcolor{purple}{\textbf{B}} chair sells for \pounds$\textrm{\sf 12}$.  
}

\frame{
\frametitle{Step 3: Objective function}
\noindent The total income is then
\pause
\begin{eqnarray*}
\textsf{\pounds} Z &=& \textsf{\pounds} (\textrm{\sf 10}x + \textrm{\sf 12} y).
\end{eqnarray*}
\pause
\noindent The aim is to maximise income, so we'd like to maximise
\pause
\begin{eqnarray*}
Z &=& \textrm{\sf 10}x + \textrm{\sf 12}y,
\end{eqnarray*} 
\pause
where $Z$ is the objective function. 
}

 
\frame{
\frametitle{Example 1.3: The chair manufacturer}
\noindent \textbf{Thus, to summarise, we have the following linear programming problem:}
\pause

\vspace{0.3cm}

\noindent Maximise $Z=\textrm{\sf 10}x+\textrm{\sf 12}y$ subject to the constraints
\pause
\begin{eqnarray*}
\textrm{\sf 3}x+\textrm{\sf 3}y &\leq& \textrm{\sf 120},	\\
\pause
\textrm{\sf 2}x+\textrm{\sf 4}y&\leq& \textrm{\sf 150},	\\
\pause
x &\geq& \textrm{\sf 0} 	\qquad \textrm{\sf and}	\\
\pause
y &\geq& \textrm{\sf 0}.
\end{eqnarray*}
}

\frame{
\frametitle{Example 1.4: Replica sports shirts}
\textit{Sportizus} Clothing Company produce replica football shirts and replica rugby shirts for sale on the high street.  Each shirt produced goes through a \textcolor{purple}{\bf sewing process} and a \textcolor{purple}{\bf transfer process}.  \pause

\vsp

\noindent Each football shirt requires \textbf{8} minutes of \textcolor{purple}{\bf sewing time} and \textbf{9} minutes for the \textcolor{purple}{\bf transfer process}, whereas rugby shirts each require \textbf{5} minutes of \textcolor{purple}{\bf sewing time} and \textbf{15} minutes for the \textcolor{purple}{\bf transfer process}.  \pause

\vsp

In any given day, the \textcolor{purple}{\bf total time} available for the sewing process and transfer process is \textbf{10} hours and \textbf{15} hours respectively.  \pause
}


\frame{
\frametitle{Example 1.4: Replica sports shirts}
\noindent To meet current demand, \textit{Sportizus} must produce at least \textbf{30} football shirts and \textbf{10} rugby shirts each day.  \pause

\vsp

The company sells football shirts and rugby shirts at a \textcolor{purple}{\bf profit} of \pounds 22 and \pounds 16 respectively.  \pause

\vsp

\noindent\textit{ How many of each type of shirt should \textit{Sportizus} produce in order to maximise profits?}
}


\sol

\frame{
\frametitle{Example 1.4: Replica sports shirts}
Let's start off with a table which summarises the question: \pause
\begin{center}
\begin{tabular}{|c| c| c|c|} \hline
  &Sewing (mins)                    &Transfer (minutes)			&Profit ($P$)\\ \hline
        &                               &            & \\
Football& \textbf{8}	          		&\textbf{9}	     & \textbf{22} \\
        &                               &            &		\\ \hline
	&                               &                       & \\
Rugby	&\textbf{5}			        &\textbf{15}			& \textbf{16}\\
         &                              &                     &		\\ \hline
         &                               &                    &\\
         Total time	&\textbf{600}	&\textbf{900}	&			\\
        &                              &                    & \\ \hline
\end{tabular}
\end{center}

}

\frame{
\frametitle{Step 1: Decision variables}
 The decision variables are the number of football and rugby shirts to make.  Let
\begin{eqnarray*}
x &=& \textrm{\sf \textcolor{blue}{number of football shirts to make}}	\qquad \textrm{\sf and}	\\
  & & \\
y &=& \textrm{\sf \textcolor{blue}{number of rugby shirts to make.}}
\end{eqnarray*}
}

\frame{
\frametitle{Step 2: Constraints}
 The constraints are:
\begin{eqnarray*}
\textrm{\sf \textbf{sewing}}: 8x+5y &\leq& 600		\qquad \textrm{\sf and}	\\ \pause
                          &  & \\
\textrm{\sf \textbf{transfer}}:	9x+15y&\leq& 900	\pause
\end{eqnarray*}
We also have the \textcolor{purple}{\bf non--negativity contrainits}.  However, we are also told that we must make at least 30 football shirts and 10 rugby shirts, giving \pause
\begin{eqnarray*}
x &\geq& 30	\qquad \textrm{\sf and}	\\
 & & \\
y &\geq& 10 
\end{eqnarray*}
}

\frame{
\frametitle{Step 3: Objective function}
The aim is to \textcolor{purple}{\bf maximise profit} -- call this $P$. \pause

\vsp

We know that we make \pounds 22 for each football shirt that we make and sell.  Since we make (and sell) $x$ football shirts, this will give \pause
\[
\textrm{\sf \pounds} 22x \qquad \textrm{\sf profit.}
\]\pause
We also know that we make \pounds 16 for each rugby shirt we make and sell.  Since we make (and sell) $y$ rugby shirts, this will give \pause
\[
\textrm{\sf \pounds} 16y \qquad \textrm{\sf profit.}
\] \pause
Thus total profit is \pause
\[
\textrm{\sf \pounds} P = 22x+16y,
\] 
}

\frame{
\frametitle{Summary}
\textbf{Thus, to summarise:} \pause

\vsp

Maximise $P=22x+16y$ subject to the constraints \pause
\begin{eqnarray*}
8x+5y   &\leq& 600, \\ \pause
 & & \\
9x+15y  &\leq& 900, \pause \\
& & \\
x &\geq& 30 \qquad \textrm{\sf and} \\
& & \\
y  &\geq& 10.
\end{eqnarray*}
}



\begin{comment}

\frame{
\frametitle{Announcements}
\begin{itemize}
\item Chapter 1 learning outcomes -- will give out today -- prize question! \pause

\vspl

\item CBA1: Well done! \pause
\begin{center}
\begin{tabular}{c|c c|c c|c|} \hline
&$n$  &$n^{*}$      &Mean      &Median   &Max    \\ \hline
2013  &210  &2      &94       &100      &100    \\ \hline \pause
2014  &210  &4      &92       &100      &100      \\ \hline \pause
2015  &243  &11     &94       &100      &100   \\ \hline  
\end{tabular} 
\end{center}

\vspl

\item Case studies: come to a close next week... \pause

\vspl

\begin{itemize}
\item[--] We will be asking you all an individual question in next week's workshop which counts towards your final mark \pause
\item[--] Individual written report (4 pages max) due in by \textbf{4pm next Friday}: \pause 
\vspl
\item [--] Must include a completed cover sheet \pause
\vspl
\item [--] Must be posted into the Stage 1 homework submission letterbox in the General Office on the 3rd floor of the \textbf{Herschel Building}
\end{itemize}
\end{itemize}
}




\frame{
\frametitle{Announcements}
\textbf{Alcohol case study}
\begin{center}
{\it ``I heard that there were mistakes in the alcohol case study and that you were going to scrap it and give us all a new one'' } \pause

\vsp

\textbf{ \LARGE NO!} \pause

\end{center}

\vsp

\begin{itemize}
\item Some confusion over ``elasticity'' \pause 
\vspl

\item Different interpretations of this (Mathematics/Economics) \pause

\vspl

\item It's up to you what you do here -- you will not be penalised!
\end{itemize}
}

\normal
\frame{
\frametitle{Solving linear programming problems}
\noindent In the previous section we discussed how to \textcolor{purple}{\bf formulate} a linear programming problem. 

\vsp

We now consider how to \textcolor{purple}{\bf solve} such problems. 

\vsp

Linear programming problems that involve only two decision variables, $x$ and $y$, may be solved \textcolor{purple}{\bf graphically} --  that is, by drawing lines associated with the constraints, identifying a region of possible solutions and then locating a point in this region that has a particular property.

\vsp

We will now re--visit the two examples from the previous section. 
}


\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
\noindent Recall that the problem posed in \textcolor{purple}{\bf example 1.3}  could be summarised in the following way: 

\vsp

 Maximise $Z=10x + 12y$ subject to the following constraints:
\begin{eqnarray*} 
3x+3y &\leq& 120,\\ 
2x+4y &\leq& 150, \\  
x &\geq& 0 \qquad  \textrm{\sf and}	\\
y &\geq& 0.
\end{eqnarray*}
}

\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
\noindent To find the \textcolor{purple}{\bf feasible region} for this problem (i.e. the region on a graph which satisfies all of our inequalities), we proceed by indicating, on a diagram, the region for which all of the inequalities hold.  
}

\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
\noindent The first inequality is $3x+3y \leq 120$.  \pause To show this on a graph, we first need to plot the line $3x+3y\boldsymbol{=}120$. 
\begin{itemize}
\item When $x=0$, we have 
\begin{eqnarray*}
  3 \times 0 + 3y &=& 120	\qquad \textrm{\sf i.e.}	\\ 
	  3y &=& 120		\qquad \textrm{\sf i.e.}	\\
	   y &=& 40.
\end{eqnarray*}
\item When $y=0$, we have 
\begin{eqnarray*}
3x + 3 \times 0 &=& 120	\qquad \textrm{\sf i.e.}	\\
3x	&=& 120	\qquad \textrm{\sf i.e.}	\\
x	&=&40.
\end{eqnarray*} 
\end{itemize}
The points $(0,40)$ and $(40,0)$ have been plotted on the graph on page 16, and shading used to illustrate the inequality.
}

\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph7.ps}
\end{center}
}


\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
 Now consider the second inequality $2x + 4y \leq 150$.  \pause Again, to show this on a diagram, we first need to plot the line $2x+4y\boldsymbol{=}150$.\pause  
\begin{itemize}
\item When $x=0$, we have \pause
\begin{eqnarray*}
 2 \times 0 + 4y &=& 150 \qquad \textrm{\sf i.e.}	\\ 
	4y &=& 150	\qquad \textrm{\sf i.e.}		\\ 
	y  &=& 37.5. 
\end{eqnarray*}
\item When $y=0$, we have 
\begin{eqnarray*}
2x + 4 \times 0 &=& 150 \qquad \textrm{\sf i.e.}	\\ 
2x &=& 150		\qquad \textrm{\sf i.e.}	\\ 
x &=& 75. 
\end{eqnarray*}
\end{itemize}
\noindent On the same graph, you should plot the points $(0,37.5)$ and $(75,0)$, and shade accordingly.  
}

\sol

\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph7a.ps}
\end{center}
}

\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph7b.ps}
\end{center}
}

\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph7c.ps}
\end{center}
}

\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph7d.ps}
\end{center}
}

\normal
\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
We also need to respect the non--negativity constraints, and so we shade out the negative portion of the graph.}

\sol
\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph7e.ps}
\end{center}
}

\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph7f.ps}
\end{center}
}


\normal
\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
The unshaded region in your graph shows the feasible region associated with our set of inequalities. 

\vsp

\textcolor{white}{What we must do now is find the point in that region which meets our objective -- i.e. the point in that region which \textcolor{white}{\bf maximises income}. }

\vsp

\textcolor{white}{One way of doing this is to also plot the \textcolor{white}{\bf objective function}. }
}

\sol 
\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph7g.ps}
\end{center}
}

\normal
\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
The unshaded region in your graph shows the feasible region associated with our set of inequalities. 

\vsp

What we must do now is find the point in that region which meets our objective -- i.e. the point in that region which \textcolor{purple}{\bf maximises income}. \pause

\vsp

One way of doing this is to also plot the \textcolor{purple}{\bf objective function}.
}


\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
 Now our objective function is \pause
\begin{eqnarray*}
Z&=& 10x + 12y,
\end{eqnarray*}
where $Z$ is our income.  \pause

\vsp

When $Z$ takes different values we get a family of \textcolor{purple}{\bf parallel straight lines}.  \pause

\vsp
We need to choose a starting value for $Z$ in order to be able to plot the objective function.  
}

\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
It's often a good idea to try a value which is a multiple of both the coefficients of $x$ and $y$.  \pause

\vsp

The coefficient of $x$ is 10 and the coefficient of $y$ is 12, so we could try a starting value of $Z=120$.  \pause Thus, the objective function is now
\begin{eqnarray*} 
10x + 12y &=& 120. 
\end{eqnarray*} \pause
We can plot this line in the same way as before -- i.e. consider what happens when $x$ and $y$ are zero.}

\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
\begin{itemize}
\item When $x=0$, we have \pause
\begin{eqnarray*}
10 \times 0 + 12y &=&120	\qquad \textrm{\sf i.e.}	\\
12y &=& 120		\qquad \textrm{\sf i.e.}	\\
y &=&10. \pause
\end{eqnarray*}
\item When $y=0$, we have
\begin{eqnarray*} \pause
10x + 12 \times 0 &=& 120 \qquad \textrm{\sf i.e.}	\\ \pause
10x &=& 120			\qquad \textrm{\sf i.e.} \\ \pause
 x &=& 12.
\end{eqnarray*}
\end{itemize} \pause
This line should also plotted on your graph.  
\begin{itemize}
\item Notice that this line does not give the \textcolor{purple}{\bf optimal income}\pause
\item The origin represents zero income, and we want to move as far away from this as possible.  
\end{itemize}
}
\sol

\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph7h.ps}
\end{center}
}

\normal
\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
You should see from your graph that the point within the feasible region that is furthest away from the origin, \textcolor{purple}{\bf but parallel to the objective function}, is $\boldsymbol{x=5}$ and $\boldsymbol{y=35}$.

\vsp

\textcolor{white}{Thus, to maximise income, we should make \textcolor{white}{\bf 5 type A chairs} and \textcolor{white}{\bf 35 type B chairs}.} 

\vsp

\textcolor{white}{This will give an income of} 
\begin{eqnarray*}
&&	\\ 
 &&  \\
&& 	\\ 
  &&
\end{eqnarray*}
\textcolor{white}{i.e. \pounds 470.}
}

\sol

\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph7i.ps}
\end{center}
}

\normal
\frame{
\frametitle{Example 1.3 revisited (the chair manufacturer)}
You should see from your graph that the point within the feasible region that is furthest away from the origin, \textcolor{purple}{\bf but parallel to the objective function}, is $\boldsymbol{x=5}$ and $\boldsymbol{y=35}$.

\vsp

Thus, to maximise income, we should make \textcolor{purple}{\bf 5 type A chairs} and \textcolor{purple}{\bf 35 type B chairs}. \pause 

\vsp

This will give an income of \pause
\begin{eqnarray*} 
Z &=& 10x+12y	\qquad \textrm{\sf i.e.}\\ \pause 
Z &=& 10 \times 5 + 12 \times 35	\qquad \textrm{\sf i.e.} \\ \pause
Z &=& 50 + 420	\\ \pause
  &=& 470, \pause
\end{eqnarray*}
i.e. \pounds 470.
}

\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
Recall the example about \textit{Sportizus}, a company who produce replica football and rugby shirts.  \pause  We summarised this problem as follows.

\vsp

Maximise $P=22x+16y$ subject to the following constraints:
\begin{eqnarray*}
8x+5y &\leq& 600, \\
9x+15y &\leq& 900, \\
x&\geq& 30 \qquad \textrm{\sf and} \\
y&\geq& 10,
\end{eqnarray*}
where $x$ and $y$ are the number of football and rugby shirts to make, respectively. \pause

\vsp

Let's now solve this problem graphically.}

\sol
\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
\noindent The first inequality is $8x+5y\leq 600$: \pause
\begin{itemize}
\item When $x=0$, we have \pause
\begin{eqnarray*}
            5y &=& 600 \qquad \textrm{\sf i.e.} \\ \pause
             y &=&120. \pause
\end{eqnarray*}
\item When $y=0$, we have \pause
\begin{eqnarray*}
               8x &=&600 \qquad \textrm{\sf i.e.}\\ \pause
                x&=& 75.\pause
\end{eqnarray*} 
\end{itemize}
So plot $(0,120)$, $(75,0)$. 

}

\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph8a.ps}
\end{center}
}

\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph8b.ps}
\end{center}
}

\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph8c.ps}
\end{center}
}

\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
 The second inequality is $9x+15y\leq 900$: \pause  
\begin{itemize}
\item When $x=0$, we have \pause  
\begin{eqnarray*}
 15y &=&900 \qquad \textrm{\sf i.e.} \\ \pause  
              y &=&60. \pause  
\end{eqnarray*}
\item When $y=0$, we have \pause  
\begin{eqnarray*}
 9x   &=&900 \qquad \textrm{\sf i.e.} \\ \pause  
               x  &=&100.
\end{eqnarray*}
\end{itemize}
So plot $(0,60)$ and $(100,0)$.  
}

\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph8d.ps}
\end{center}
}

\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph8e.ps}
\end{center}
}

\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph8f.ps}
\end{center}
}

\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
We also require $x\geq 30$ and $y\geq 10$. \pause

\vsp

Thus, on the graph, you should also shade out all $x$ values less than 30 and all $y$ values less than 10, to leave $x\geq 30$ and $y\geq 10$ \textit{unshaded}. 
}

\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph8g.ps}
\end{center}
}

\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph8h.ps}
\end{center}
}

\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph8i.ps}
\end{center}
}

\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph8j.ps}
\end{center}
}


\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph8k.ps}
\end{center}
}

\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
 Finally, we need to plot the \textcolor{purple}{\bf objective function}.  \pause Here, we have
\[
P=22x+16y;
\] \pause
as with the previous example, we need a starting value for $P$ in order to plot this line.  \pause

\vsp

You should notice that starting with $P=22\times 16 =352$ will give $(0,22)$ and $(16,0)$, and so we also plot this line on the graph.
}

\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph8l.ps}
\end{center}
}

\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
\begin{center}
\includegraphics[angle=-90,width=12cm]{graph8m.ps}
\end{center}
}


\frame{
\frametitle{Example 1.4 revisited (\textit{Sportizus})}
To maximise profit, $\boldsymbol{x=60}$ and $\boldsymbol{y=24}$, i.e. we should make \textcolor{purple}{\bf 60 football shirts} and \textcolor{purple}{\bf 24 rugby shirts} each day.  \pause

\vsp

This will give a maximum daily profit of \pause
\begin{eqnarray*}
P &=&22x + 16y\\ \pause
  &=&22 \times 60 + 16 \times 24 \\ \pause
  &=&\textrm{\sf \pounds 1704}.
\end{eqnarray*}}

\normal

\frame{
\frametitle{Algebraic solutions for linear programming problems}
\noindent Notice that in both the examples we have looked at so far, the graphical representation indicates that the solution is at the intersection of two lines on the graph.  \pause

\vsp

Thus, we could find also the solution \textcolor{purple}{\bf algebraically}, as the solution to a pair of \textcolor{purple}{\bf simultaneous equations}. }

\frame{
\frametitle{Algebraic solutions for linear programming problems}
For example, for \textit{Sportizus}, the solution was at the intersection of the two lines
\begin{eqnarray*}
8x+5y &=& 600 \\
9x+15y &=&900.
\end{eqnarray*} \pause
Multyplying the first equation by 3 will allow us to eliminate $y$ on subtraction: \pause
\begin{eqnarray*}
24x + 15y   &=& 1800 \\
\underline{9x + 15y}     &=&\underline{900} \\
15x   + 0y   &=& 900, \pause
\end{eqnarray*}
and so $x=900/15 = 60$.  \pause Substituting this into the first equation gives:\pause
\begin{eqnarray*}
480 + 5y  &=& 600 \\ \pause
       5y &=& 120 \\ \pause
        y &=&24.
\end{eqnarray*}
}

\normal


\frame{

\vspace{1cm}

\huge
\textbf{Chapter 2}

\vspace{1cm}

\Large
\textbf{Optimisation using calculus}

}

\begin{comment}

\frame{
\frametitle{Announcements}
\begin{itemize}
\item Case study work: report due in by \textbf{4pm today} \pause

\vspl

\begin{itemize}

\item [--] 4 pages \pause

\vspl

\item [--] Cover sheet \pause

\vspl

\item [--] Maths \& Stats Stage 1 homework submission letterbox, 3rd floor Herschel \pause

\vspl

\item [--] No electronic submission
\end{itemize}

\vsp

\item Workshops next week will focus on content from the lectures -- no case study work for two weeks

\pause

\item Lecture attendance register starts today: make sure you sign in!

\end{itemize}
}
\normal

\frame{
\frametitle{What we'll cover...}
\begin{itemize}
\item The gradient of a \textcolor{purple}{\bf curve}? Ideas of \textcolor{purple}{\bf rates of change}\pause
\vspl
\item The method of \textcolor{purple}{\bf differentiation}: first principles \pause
\vspl
\item Differentiation: \textcolor{purple}{\bf general results} for polynomials \pause
\vspl
\item Finding the derivative of non--linear functions from \textcolor{purple}{\bf real--life} scenarios \pause
\vspl
\item \textcolor{purple}{\bf Optimisation} using the differential calculus, and the role of the second derivative \pause

\vspl

\item Chapters 3 and 4 in the \textcolor{purple}{\bf course text}

\end{itemize}
}




\normal

\frame{
\frametitle{2. Optimisation using calculus}
\noindent An important topic in many disciplines is the study of how quickly quantities \textcolor{purple}{\bf change over time}.\pause

\vsp

For example, in order to estimate the future demand for a commodity, we need information about \textcolor{purple}{\bf rates of change}.\pause

\vsp

As we shall see in this chapter, we can also use such information to solve optimisation problems: \pause for example, we might be interested in the number of items that need to be produced in order to \textcolor{purple}{\bf maximise profit} or \textcolor{purple}{\bf minimise loss}.  
}

\frame{
\frametitle{2. Optimisation using calculus}
\noindent We have already considered rates of change in Chapter 1.  \pause

\vsp

In the equation of the straight line
\[
y=mx + c, \pause
\]
the gradient $m$ represents the rate of change of $y$ with respect to $x$, and we thought about how to calculate $m$ using the formula \pause
\[
\textrm{\sf Gradient}=  \frac{\textrm{\sf Change in $y$}}{\textrm{\sf Change in $x$}}.
\]
}

\frame{
\frametitle{Example}
%\begin{figure}[!h]
\begin{center}
\includegraphics[width=8cm,angle=-90]{graph1.ps}
%\caption{Lee}
\end{center}}

\frame{
\frametitle{2. Optimisation using calculus}
In Chapter 1 we also considered some \textcolor{purple}{\bf non--linear functions}, focussing primarily on quadratic functions.  \pause

\vsp

We will begin Chapter 2 with an examination of how to find the \textcolor{purple}{\bf gradient of a non--linear function}, before thinking about how this can be used to aid the process of \textcolor{purple}{\bf optimisation}.
}

\frame{
\frametitle{2.1  Differentiation}
The concept used to describe the rate of change of a function (linear or non--linear) is the \textcolor{purple}{\bf derivative}, which is \underline{the} central concept in mathematical analysis.  

\vsp

In this section we will define the derivative of a function, as well as present some of the important rules for calculating it.  

\vsp

\textcolor{purple}{\bf Isaac Newton} (1642--1727) and \textcolor{purple}{\bf Gottfried Leibniz} (1646--1716) discovered most of these general rules independently of each other.  

\vsp

This initiated the \textcolor{purple}{\bf differential calculus}, which has been the foundation for the development of modern science. 

\vsp

It has also been of central importance to the theoretical development of modern economics.  }


\frame{
\frametitle{2.1.1 The gradient of a curve}
A curve does not have a constant gradient -- its direction is \textcolor{purple}{\bf continuously changing}, and so its gradient will continuously change too. \pause

\vsp

So we look at the gradient of the curve at a \textcolor{purple}{\bf particular point on the curve}, rather than calculate the gradient of an entire line as with a linear function.  
}


\frame{
\frametitle{2.1.1 The gradient of a curve}
Look at the graph of $y=x^{2}$ shown below.  \pause

\vsp

Let's suppose we are interested in the gradient of this curve at the point $x=3$.  \pause

\vsp

Informally, we can say a couple of things about the gradient at this point:\pause
\vspl
\begin{itemize}
\item The gradient will be \textcolor{purple}{\bf positive} -- as you look at the graph from left to right at this point, the curve goes uphill \pause
\vspl
\item The graph is \textcolor{purple}{\bf symmetric} about the point $x=0$: the gradient at $x=-3$ will be the same as that at $x=3$ (just negative)\pause
\vspl
\item As we move from $x=3$ to $x=0$, the gradient gets \textcolor{purple}{\bf less and less steep}, and ``flattens out'' completely at $x=0$
 \end{itemize}
}


\frame{
\frametitle{2.1.1 The gradient of a curve}
\begin{center}
\includegraphics[width=8cm,angle=-90]{diff1.ps}
%\caption{Lee}
\end{center}
}

\frame{
\frametitle{2.1.1 The gradient of a curve}
We know how to find the gradient of a straight line from Chapter 1, so we can \textcolor{purple}{\bf approximate} the gradient of the curve at $x=3$ by drawing a chord on the curve.  \pause

\vsp

For example, draw a chord on the curve between the points $x=3$ and $x=5$, and find the gradient of this chord \textit{[the co-ordinates will be (3,9) and (5,25)]}:
{\color{white}
\[
\textrm{\sf Gradient} = \frac{25-9}{5-3} = \frac{16}{2} = 8.
\]}
}

\sol
\frame{
\frametitle{2.1.1 The gradient of a curve}
\begin{center}
\includegraphics[width=8cm,angle=-90]{diff2.ps}
%\caption{Lee}
\end{center}
}

\normal
\frame{
\frametitle{2.1.1 The gradient of a curve}
We know how to find the gradient of a straight line from Chapter 1, so we can \textcolor{purple}{\bf approximate} the gradient of the curve at $x=3$ by drawing a chord on the curve.  

\vsp

For example, draw a chord on the curve between the points $x=3$ and $x=5$, and find the gradient of this chord \textit{[the co-ordinates will be (3,9) and (5,25)]}: \pause
\[
\textrm{\sf Gradient} = \frac{25-9}{5-3} =\pause \frac{16}{2} = 8.
\]
}

\frame{
\frametitle{2.1.1 The gradient of a curve}
Now decrease the length of the chord and bring it \textcolor{purple}{\bf closer to the curve} -- for example, draw the chord between the points $x=3$ and $x=4$ -- and find the gradient \textit{[The co-ordinates will be (3,9) and (4,16)]}:
{\color{white}
\[
\textrm{\sf Gradient} = \frac{16-9}{4-3} = \frac{7}{1} = 7.  
\]}
}

\sol
\frame{
\frametitle{2.1.1 The gradient of a curve}
\begin{center}
\includegraphics[width=8cm,angle=-90]{diff3.ps}
%\caption{Lee}
\end{center}
}

\normal
\frame{
\frametitle{2.1.1 The gradient of a curve}
Now decrease the length of the chord and bring it \textcolor{purple}{\bf closer to the curve} -- for example, draw the chord between the points $x=3$ and $x=4$ -- and find the gradient \textit{[The co-ordinates will be (3,9) and (4,16)]}: \pause
\[
\textrm{\sf Gradient} = \frac{16-9}{4-3} = \pause \frac{7}{1} = 7.  
\]
}

\normal
\frame{
\frametitle{2.1.1 The gradient of a curve}
Now decrease the length of the chord again and bring it \textcolor{purple}{\bf even closer to the curve} -- draw the chord between the points $x=3$ and $x=3.5$ -- and find the gradient \textit{[The co-ordinates will be (3,9) and (3.5,12.25)]}:
{\color{white}
\[
\textrm{\sf Gradient} = \frac{12.25-9}{3.5-3} = \pause \frac{3.25}{0.5} = 6.5.
\]}}

\sol
\frame{
\frametitle{2.1.1 The gradient of a curve}
\begin{center}
\includegraphics[width=8cm,angle=-90]{diff4.ps}
%\caption{Lee}
\end{center}
}

\frame{
\frametitle{2.1.1 The gradient of a curve}
Now decrease the length of the chord again and bring it \textcolor{purple}{\bf even closer to the curve} -- draw the chord between the points $x=3$ and $x=3.5$ -- and find the gradient \textit{[The co-ordinates will be (3,9) and (3.5,12.25)]}: \pause
\[
\textrm{\sf Gradient} = \frac{12.25-9}{3.5-3} = \pause \frac{3.25}{0.5} = 6.5.
\]
}

\sol
\frame{
\frametitle{2.1.1 The gradient of a curve}

\begin{center}
\begin{tabular}{|c|c|c|} \hline
Point of interest    &Point 2     &Gradient \\ \hline                      
$(3,9)$              &$(5,25)$    &$\displaystyle \frac{25-9}{5-3} = \textbf{8}$    \\
                     &           & \\
$(3,9)$              &$(4,16)$    &$\displaystyle \frac{16-9}{4-3} = \textbf{7}$     \\
                       & &            \\
$(3,9)$              &$(3.5,12.25)$ &$\displaystyle \frac{12.25-9}{3.5-3}=\textbf{6.5}$  \\ \pause
                       & &               \\
$(3,9)$              &$(3.25,10.5625)$ &$\displaystyle \frac{10.5625-9}{3.25-3} = \textbf{6.25}$\\ \pause
                              &      & \\ 
$(3,9)$              &$(3.1,9.61)$     &$\displaystyle \frac{9.61-9}{3.1-3} = \textbf{6.1}$ \\ \pause
                       & & \\
$(3,9)$               &$(3.01,9.0601)$  &$\displaystyle \frac{9.0601-9}{3.01-3} = \textbf{6.01}$ \\
                        & & \\ \hline
\end{tabular}
\end{center}}

\normal

\frame{
\frametitle{2.1.1 The gradient of a curve}
So it looks like at $x=3$ the gradient converges to 6.  \pause

\vsp

We can \textcolor{purple}{\bf generalise} this approach \textcolor{purple}{\bf algebraically}.\pause

\vsp

  Suppose the point of interest has co--ordinates $(x,x^{2})$ and point 2 has an $x$ co--ordinate close to that of the point of interest, say $x+\delta$.  Then the $y$ co--ordinate of point 2 is
\[
y = (x+\delta)^{2}.
\]}

\frame{
\frametitle{2.1.1 The gradient of a curve}
Thus, the gradient is given by \pause
\begin{eqnarray*}
\textrm{\sf Gradient}  &=& \frac{\textrm{\sf Change in $y$}}{\textrm{\sf Change in $x$}} \\ \pause
                           & & \\
                    &=& \frac{(x+\delta)^{2} - x^{2}}{(x+\delta)-x} \\
                         & & \\ \pause
                        &=& \frac{(x+\delta)(x+\delta)-x^{2}}{x + \delta - x} \\
                        & & \\ \pause
                                &=& \frac{x^{2}+2\delta x + \delta^{2} - x^{2}}{\delta} \\
                       & &\\ \pause
                       &=& \frac{2\delta x + \delta^{2}}{\delta}  = 2x+\delta.
\end{eqnarray*}}

\frame{
\frametitle{2.1.1 The gradient of a curve}
Now if we let $\delta$ get smaller and smaller, i.e. ``tend to zero'', we are left with just \pause
\[
\textrm{\sf Gradient} = 2x.
\]\pause
So the gradient, or \textcolor{purple}{\bf derivative}, of the curve $y=x^{2}$ is $2x$.  }


\frame{
\frametitle{2.1.1 The gradient of a curve}
We usually denote this quantity as $\displaystyle \frac{dy}{dx}$, pronounced ``dee y by dee x'', and so when \pause
\begin{eqnarray*}
y  &=& x^{2} \\
   & & \\ \pause
\frac{dy}{dx} &=& 2x.
\end{eqnarray*}  
}

\frame{
\frametitle{2.1.1 The gradient of a curve}
We can now use this derivative to find the gradient of the curve at any point $x$.  \pause

\vsp

For example, when $x=3$, the gradient is
\[
\frac{dy}{dx} = 2x = 2\times 3 = 6,
\] \pause
exactly the answer we found from first principles in the table on page 41! }

\sol

\frame{
\frametitle{2.1.1 The gradient of a curve} 

What is the gradient of the curve $y=x^{2}$ at the points $x=4$, $x=1$, $x=0$ and $x=-4$?  Do your answers make sense in relation to the graph of this function? 

\vspace{1cm}

\textbf{Solution}
\begin{eqnarray*}
x=4  &:& \frac{dy}{dx} = 2\times 4 = 8 \pause \\
  & & \\
x=1&:& \frac{dy}{dx} = 2\times 1 = 2 \pause \\
 & & \\
x=0&:& \frac{dy}{dx} = 2\times 0 =0 \pause \\
 & & \\
x=-1 &:& \frac{dy}{dx} = 2\times -1 = -2.
\end{eqnarray*}
}

\frame{
\frametitle{2.1.1 The gradient of a curve} 
Looking at the graph, these values make perfect sense: as we approach zero, we can see the curve becomes less and less steep, until at the origin the gradient is zero. \pause

\vsp

Also, the curve is symmetric about $x=0$ and so the gradient at $x=\pm 1$ will be the same, just negated.  
}

\normal

\frame{
\frametitle{2.1.2 Some general results for polynomials}
In the previous section we found that, when
\begin{eqnarray*}
y &=&x^{2}, \\
    & & \\
\frac{dy}{dx} &=& 2x.
\end{eqnarray*} \pause

Notice that the power of $x$ has been ``brought down'', in front of the $x$, and the power itself has reduced by one ($2x$ is actually $2x^{1}$).  }

\frame{
\frametitle{2.1.2 Some general results for polynomials}
In general, when
\begin{eqnarray*}
y   &=& x^{n}, \\
   & & \\ \pause
\frac{dy}{dx}  &=&nx^{n-1}.
\end{eqnarray*} \pause
More generally still, if 
\begin{eqnarray*}
y &=& kx^{n}, \qquad \textrm{\sf then} \\
  & & \\ \pause
\frac{dy}{dx} &=&nkx^{n-1}.
\end{eqnarray*}}


\frame{
\frametitle{2.1.2 Examples}

Find $\displaystyle \frac{dy}{dx}$ for each of the following:

\vspl

\begin{itemize}
\item [\textbf{1.}] $y=x^{3}$
\item [\textbf{2.}] $y=x^{5}$
\item [\textbf{3.}] $y=2x^{3}$
\item [\textbf{4.}] $y=4x^{3}-7x^{2}+2x$
\item [\textbf{5.}] $y=5x^{2}+2$
\item [\textbf{6.}] $y=\sqrt{x}+1$
\item [\textbf{7.}] $\displaystyle y=\frac{1}{x}$
\end{itemize}
}

\sol

\frame{
\frametitle{Solution to examples}
\begin{itemize}
\item [\textbf{1.}] We have $y=x^{3}$.  Bringing the power down, and then reducing the power by one, gives
\[
\frac{dy}{dx} = 3x^{2}.
\]
\pause

\vsp

\item [\textbf{2.}] We have $y=x^{5}$.  Bringing the power down, and then reducing the power, gives \pause
\[
\frac{dy}{dx} = 5x^{4}.
\]
\end{itemize}
}
\frame{
\frametitle{Solution to examples}
\begin{itemize}
\item [\textbf{3.}] We have $y=2x^{3}$.  Bringing the power down, and then reducing the power by one, gives
\[
\frac{dy}{dx} = \textbf{3}\times 2x^{2} = 6x^{2}.
\]\pause

\vsp

\item [\textbf{4.}] We have $y=4x^{3}-7x^{2}+2x^{1}$.  Bringing the powers of $x$ down, and then reducing the powers, gives \pause
\begin{eqnarray*}
\frac{dy}{dx} &=& \textbf{3}\times 4x^{2} \pause - \textbf{2}\times 7x^{1}\pause + \textbf{1}\times 2x^{0} \\
              &=&12x^{2} \pause - 14x \pause + 2.
\end{eqnarray*}
\end{itemize}
}


\frame{
\frametitle{Solution to examples}
\begin{itemize}
\item [\textbf{5.}] We have $y=5x^{2}+2$, \pause i.e. $y=5x^{2}+2x^{0}$.  Thus \pause
\begin{eqnarray*}
\frac{dy}{dx}   &=& \textbf{2}\times 5x^{1} + \textbf{0}\times 2x^{-1} \pause \\
               &=& 10x,
\end{eqnarray*} \pause
\textcolor{purple}{\bf so constants just differentiate to zero!} 
\end{itemize}
}


\frame{
\frametitle{Solution to examples}
\begin{itemize}
\item [\textbf{6.}] We have $y=\sqrt{x}+1 \pause = x^{0.5}+1$.  Thus \pause
\begin{eqnarray*}
\frac{dy}{dx}     &=& 0.5x^{-0.5}  \pause \\
                  &=& \frac{1}{2} x^{-\frac{1}{2}} \pause \\
   & & \\
                   &=& \frac{1}{2}\times \frac{1}{x^{\frac{1}{2}}} \pause \\
   & & \\
                        &=&\frac{1}{2} \times \frac{1}{\sqrt{x}} \pause \\
& & \\
                  &=& \frac{1}{2\sqrt{x}}.
\end{eqnarray*}
\end{itemize}
}

\frame{
\frametitle{Solution to examples}
\begin{itemize}
\item [\textbf{7.}] We have $\displaystyle y=\frac{1}{x} \pause = x^{-1}$. Thus \pause
\begin{eqnarray*}
\frac{dy}{dx}    &=& -1x^{-2} \pause \\
                &=& -\frac{1}{x^{2}}.
\end{eqnarray*}
\end{itemize}
}

\normal

\frame{
\frametitle{Example 2.1}
The managing director of a company is interested in modelling the relationship between her company's annual profits (\pounds $P$ million) and their annual advertising budget (\pounds $A$ thousand).  

\vsp

The graph below shows how the managing director believes $P$ changes with $A$.
}

\frame{
\frametitle{Example 2.1}
\begin{center}
\psfrag{0}[]{\sf \tiny 0}
\psfrag{10}[]{\sf \tiny 10}
\psfrag{20}[]{\sf \tiny 20}
\psfrag{30}[]{\sf \tiny 30}
\psfrag{40}[]{\sf \tiny 40}
\psfrag{-400}[]{\sf \tiny -400}
\psfrag{-300}[]{\sf \tiny -300}
\psfrag{-200}[]{\sf \tiny -200}
\psfrag{-100}[]{\sf \tiny -100}
\psfrag{A}[]{\sf \tiny \pounds $A$ thousand}
\psfrag{P}[]{\sf \tiny \pounds $P$ million}
\includegraphics[width=12cm,height=7cm]{example3.1.ps}
\end{center}
}

\frame{
\frametitle{Example 2.1}
\begin{itemize}
\item [\textbf{(a)}]  You work as part of a team of business analysts for this company.  A colleague proposes the following three profit functions:
\begin{itemize}
\item [*]$P = 80-4.3A$
\item [*]$P= 2.1+13.5A+0.5A^{2}$
\item [*]$P=2.1+6.3A-0.13A^{2}+0.0008A^{3}-0.0002A^{4}$
\end{itemize}

\vsp

Which of these do you think would be most appropriate in this situation? Why?
\end{itemize}
}

\sol

\frame{
\frametitle{Solution to Example 2.1(a)}
We clearly do not have a linear function, and so this rules out the first. \pause

\vsp

Our graph shows that the function will not be symmetric, and so we cannot have a quadratic. \pause

\vsp

Thus the quartic must be the most suitable function.  
}

\normal

\frame{
\frametitle{Example 2.1}
\begin{itemize}

\item [\textbf{(b)}] For the profit function you have chosen in part (a), find $\displaystyle \frac{dP}{dA}$. 
\end{itemize}
}

\sol

\frame{
\frametitle{Solution to Example 2.1(b)}
We have $P=2.1+6.3A^{1}-0.13A^{2}+0.0008A^{3}-0.0002A^{4}$.  

\vsp

Thus \pause
\begin{eqnarray*}
\frac{dP}{dA}   &=& \textbf{1}\times 6.3A^{0}\pause -\textbf{2}\times 0.13A^{1}\pause + \textbf{3}\times 0.0008A^{2} \pause - \textbf{4}\times 0.0002A^{3} \pause \\
 & & \\
                   &=&6.3 - 0.26A + 0.0024A^{2} - 0.0008A^{3}.
\end{eqnarray*}
}

\normal

 \frame{
\frametitle{Example 2.1}
 \begin{itemize}
\item [\textbf{(c)}] Use your answer to part (b) to find the gradient of your profit function when the company spends (i) \pounds 10,000; (ii) \pounds 15,250; (iii) \pounds 20,000 and (iv) 40,000 on advertising each year.  Do these values match up with what you see in the graph?  
\end{itemize}
}
    
\sol
\frame{
\frametitle{Solution to Example 2.1(c)}
{\scriptsize 
\begin{eqnarray*}
A=10 &:& \pause \frac{dP}{dA} = 6.3-0.26\times 10 + 0.0024\times 10^2 -0.0008\times 10^3 =  \textbf{3.14} \\ \pause
   & & \\
A=15.25 &:& \pause \frac{dP}{dA} = ... = \textbf{0.056} \pause \\
     & & \\
A=20  &:& \pause \frac{dP}{dA} = ... =  \boldsymbol{-4.34} \pause \\
 & & \\
A=40  &:& \pause \frac{dP}{dA} = ... = \boldsymbol{-51.46}
\end{eqnarray*}}
}

\normal

\frame{
\frametitle{Example 2.1}
\begin{itemize}
\item [\textbf{(d)}] What will be the value of $\frac{dP}{dA}$ when the company optimises their advertising budget (i.e. maximises profit)?
\end{itemize}}

\sol

\frame{
\frametitle{Solution to Example 2.1(d)}
From the graph, we can see that the company will maximise their profit at the peak of the curve. \pause

\vsp

This is known as a \textcolor{purple}{\bf turning point} in the graph. \pause
\vspl
\begin{itemize}
\item \textbf{Before} this point, the gradient ($\frac{dP}{dA}$) is positive \pause
\vspl
\item \textbf{After} this point, the gradient ($\frac{dP}{dA}$) is negative \pause
\vspl
\item \textbf{At} this point $\frac{dP}{dA} = 0$
\end{itemize}
}

\begin{comment}

\frame{
\frametitle{Announcements}

\begin{itemize}
\item \textbf{Case study 1} \pause

\vspl

\begin{itemize}
\item [--] Currently being marked \pause

\vspl

\item [--] Marks so far look generally good! 
\end{itemize} \pause

\vsp

\item \textbf{Prize question winners!} \pause

\vspl

\begin{itemize}
\item [--] Abigail Farnworth \pause

\vspl

\item [--] Mingrui Li \pause

\vspl

\item [--] Wine, text book, University-approved calculator
\end{itemize}
\end{itemize}
}
\normal



\normal
\frame{
\frametitle{Example 2.2}
A small firm employs five machine operators.  

\vspl

For a particular contract, the firm believes it will produce $Q=\frac{1}{2}\sqrt M$ units of a commodity, where $M$ machine operators are used.  

\vspl

The cost, per operator, is \euro 40 and the price obtained per unit is \euro 160.  

\vsp


\begin{itemize}
\item [\textbf{(a)}] Formulate a non--linear function for the firm's profit, $\pi$, in terms of $M$ only.  
\end{itemize}
}

\sol
\frame{
\frametitle{Solution to Example 2.2(a)}
\begin{eqnarray*}
\textrm{\sf Profit}   &=& \textrm{\sf Total income} - \textrm{\sf Total costs} \\ 
   & & \\
               \pi    &=& 160Q -40 M \pause \\
                     & & \\
                         &=& 160\left(\frac{1}{2}\sqrt{M}\right) - 40M \pause
\\
                      & & \\ 
                           &=&80\sqrt{M} - 40M.
\end{eqnarray*}
}

\normal

\frame{
\frametitle{Example 2.2}
\begin{itemize}
\item [\textbf{(b)}] Find $\frac{d \pi}{dM}$, and solve $\frac{d\pi}{dM} = 0$ for $M$.  Comment.     
\end{itemize}
}
\sol
\frame{
\frametitle{Solution to Example 2.2(b)}
We have $\pi = 80\sqrt{M} - 40M = 80M^{0.5}-40M$.  Thus \pause
\begin{eqnarray*}
\frac{d\pi}{dM}  &=& 0.5\times 80M^{-0.5}-40 \pause \\
                   &=& 40 \times \frac{1}{M^{0.5}} - 40 \pause \\
              &=& \frac{40}{\sqrt{M}} - 40.
\end{eqnarray*} \pause
When $\frac{d\pi}{dM} = 0$ we get \pause
\begin{eqnarray*}
\frac{40}{\sqrt{M}} &=& 40 \pause \\
       & & \\
       40      &=&40\sqrt{M} \pause \\
          1    &=& \sqrt{M},
\end{eqnarray*}
and so $M=1$. \pause This means that the turning point in our graph will occur when we use 1 machine operator.}

\normal

\frame{
\frametitle{Example 2.2}
\begin{itemize}
\item [\textbf{(c)}] Shown below is a plot of $\pi$ against $M$.  Can you see how this corresponds to your answer to part (b)?
\begin{center}
\psfrag{0}[]{\sf \tiny 0}
\psfrag{1}[]{\sf \tiny 1}
\psfrag{2}[]{\sf \tiny 2}
\psfrag{3}[]{\sf \tiny 3}
\psfrag{4}[]{\sf \tiny 4}
\psfrag{5}[]{\sf \tiny 5}
\psfrag{-20}[]{\sf \tiny -20}
\psfrag{-10}[]{\sf \tiny -10}
\psfrag{10}[]{\sf \tiny 10}
\psfrag{20}[]{\sf \tiny 20}
\psfrag{30}[]{\sf \tiny 30}
\psfrag{40}[]{\sf \tiny 40}
\psfrag{L}[]{\sf \tiny $M$}
\psfrag{P}[]{\sf \tiny $\pi$}
\includegraphics[width=11cm,height=6cm]{example3.2.ps}
\end{center}
\end{itemize}
}

\sol

\frame{
\frametitle{Solution to Example 2.2(c)}
It is clear from the graph that the turning point in this function occurs at $M=1$ -- our calculations show that this is the point at which the gradient is zero.  
}

\normal

\frame{
\frametitle{2.2 Optimisation using differentiation}
\noindent Suppose a company believes there is a non--linear relationship between it's monthly advertising budget (\pounds $x$ thousand) and their monthly profit (\pounds $y$ thousand).  \pause

\vsp

In particular, their analyst believes that the following cubic function explains how $y$ varies with $x$:
\[
y = -7.36+9.42x-1.17x^{2}+0.04x^{3}.
\]
}

\frame{
\frametitle{2.2 Optimisation using differentiation}
The company's monthly advertising budget cannot exceed \pounds 17,000; their current contractual arrangements for commercial TV and radio advertising means they must always spend at least \pounds 4,000 on advertising every month. \pause

\vsp

A graph of this cubic, between the values of $x=4$ and $x=17$, is shown overleaf.
}

\frame{
\frametitle{2.2 Optimisation using differentiation}  
\begin{center}
\psfrag{0}[]{\sf \tiny 0}
\psfrag{2}[]{\sf \tiny 2}
\psfrag{4}[]{\sf \tiny 4}
\psfrag{6}[]{\sf \tiny 6}
\psfrag{8}[]{\sf \tiny 8}
\psfrag{10}[]{\sf \tiny 10}
\psfrag{12}[]{\sf \tiny 12}
\psfrag{14}[]{\sf \tiny 14}
\psfrag{16}[]{\sf \tiny 16}
\psfrag{x}[]{\sf \tiny $x$}
\psfrag{y}[]{\sf \tiny $y=-7.36+9.42x-1.17x^{2}+0.04x^{3}$}
\includegraphics[width=11cm,height=6cm]{cubic.ps}
\end{center}
}

\frame{
\frametitle{2.2 Optimisation using differentiation}
Some things to note from the graph: \pause
\begin{itemize}
\item There are two \textcolor{purple}{\bf turning points} on the graph -- one at about $x=6$ and the other at about $x=14$; \pause

\vspl

\item One is known as a \textcolor{purple}{\bf local maximum}, the other is a \textcolor{purple}{\bf local minimum}; \pause

\vspl

\item In this example, one of these points corresponds to maximum profit, the other corresponds to minimum profit; \pause

\vspl

\item At both turning points, the gradient of the curve -- and hence $\displaystyle \frac{dy}{dx}$ -- is \textcolor{purple}{\bf zero}.
\end{itemize}
}

\frame{
\frametitle{2.2 Optimisation using differentiation}
To find the exact $x$ co--ordinate of each turning point, we can equate the derivative to zero and solve for $x$.  \pause

\vsp

For example, we know that \pause
\begin{eqnarray*}
\frac{dy}{dx} &=&  9.42-2\times1.17x + 3\times 0.04x^{2}\\ \pause
              &=&   9.42 -2.34x+0.12x^{2}.
\end{eqnarray*} \pause
At each of the turning points shown in the graph, we know that the gradient is zero.  \pause Thus, we know that
\[
9.42 - 2.34x +0.12x^{2} = 0,
\]
and we know how to solve such a quadratic equation from the material in Chapter 1!  }


\frame{
\frametitle{2.2 Optimisation using differentiation}
Using the quadratic formula, we know that
\[
x = \frac{-b \pm \sqrt{D}}{2a},
\] \pause
where $D$ is the discriminant and is equal to $b^{2}-4ac$; $a$ and $b$ are the coefficients of the $x^{2}$ and $x$ terms, respectively, and $c$ is the constant.  \pause

\vsp

In this example, $a=0.12$, $b=-2.34$ and $c=9.42$, giving  \pause
\[
D = (-2.34)^{2} - (4\times 0.12 \times 9.42) = 0.954,
\]
}

\frame{
\frametitle{2.2 Optimisation using differentiation}
and so 
\[
x = \frac{2.34\pm\sqrt{0.954}}{0.24}, \pause
\]
giving \pause
\begin{eqnarray*}
x &=& \frac{2.34+\sqrt{0.954}}{0.24} = 13.81971, \qquad \textrm{\sf or} \\ \pause
  & & \\
x &=& \frac{2.34-\sqrt{0.954}}{0.24} = 5.680295.
\end{eqnarray*}
}

\frame{
\frametitle{2.2 Optimisation using differentiation}
These are the \textcolor{purple}{\bf precise} values of $x$ at which the curve has zero gradient -- i.e. the advertising expenditure that will minimise/maximise profit -- and this can be seen in the graph above.   \pause

\vsp

So, spending \pounds 5,680 per month on advertising seems to be the optimal strategy, which will give monthly profits of  \pause
\[
y = -7.36+9.42(5.680)-1.17(5.680^{2})+0.04(5.680^{3}) = \textsf{\pounds} 15, 729.
\]
}

\frame{
\frametitle{2.2 Optimisation using differentiation}
Spending \pounds 13,820 per month on advertising seems to give the worst outcome, with monthly profits of just \pause
\[
y = -7.36+9.42(13.820)-1.17(13.820^{2})+0.04(13.820^{3}) = \textsf{\pounds} 4,944.
\]
}

\frame{
\frametitle{2.2 Optimisation using differentiation}
It is obvious from our graph which of the turning points gives the maximum profit and which gives the minimum profit.  \pause

\vsp

However, if we didn't have a graph of the function, the \textcolor{purple}{\bf second derivative test} can help us here.  \pause

\vsp

The second derivative of a function, sometimes written as
\[
\frac{d^{2}y}{dx^{2}},
\]
(``dee 2 y by dee x squared'') is just the derivative of the derivative.  \pause
}

\frame{
\frametitle{2.2 Optimisation using differentiation}
If $x$ represents the $x$ co--ordinate of our turning point,  i.e. $\displaystyle \frac{dy}{dx}(x) = 0$, then:  \pause
\begin{itemize}
\item If $\displaystyle \frac{d^{2}y}{dx^{2}}(x)<0$, our turning point is a \textcolor{purple}{\bf maximum}; \pause
\vspl
\item If $\displaystyle \frac{d^{2}y}{dx^{2}}(x)>0$, our turning point is a \textcolor{purple}{\bf minimum}.  
\end{itemize}
}

\frame{
\frametitle{2.2 Optimisation using differentiation}
In this example, 
\[
\frac{dy}{dx}=9.42 -2.34x+0.12x^{2}.
\] \pause
Thus,
\[
\frac{d^{2}y}{dx^{2}} = -2.34+0.24x.
\] \pause

At the first turning point, $x=5.680295$, giving \pause
\[
\frac{d^{2}y}{dx^{2}} = -2.34+0.24\times 5.680295 = -0.9767292,
\] \pause
which is negative, and so here we have a \textcolor{purple}{\bf maximum turning point}.
}

\frame{
\frametitle{2.2 Optimisation using differentiation}
At the second turning point $x=13.81971$, giving \pause
\[
\frac{d^{2}y}{dx^{2}} = -2.34+0.24\times 13.81971 = 0.9767304,
\] \pause
which is positive, and so here we have a \textcolor{purple}{\bf minimum turning point}.  
}


\frame{
\frametitle{2.2 Optimisation using differentiation}
\textbf{To summarise:} \pause

\begin{itemize}
\item There are two turning points: one at $x=5.680295$ and one at $x=13.81971$ \pause
\vspl
\item At $x=5.680295$, the second derivative is negative and so we have a local maximum \pause

\vspl

\item At $x=13.81971$ the second derivative is positive and so we have a local minimum \pause

\vspl
\item   The local maximum/minimum correspond to maximum/minimum profit, and so spending \pounds 5,680 pounds on advertising is the optimal strategy, giving profits of just under \pounds 16,000.
 \pause

\vspl

\item The worst strategy is to spend \pounds 13,820 on advertising, which will give a profit of just under \pounds 5,000.  
\end{itemize}
}
 
\frame{
\frametitle{Example 2.3}
\textit{Choctastic!} are a chocolate manufacturer.  

\vsp

One of their gift boxes has 27 chocolates in it, requiring a volume of 1350 cubic centimetres.  

\vsp

The company would like to work out the optimal dimensions of the required box to minimise the amount of packaging used (and hence minimise production costs).  
}

\frame{
\frametitle{Example 2.3}
The diagram below shows a ``net'' of the box that will be used; $x$ and $y$ are both in centimetres.    
\begin{center}
\includegraphics[height=8cm,angle=-90]{choc.ps}
\end{center}
}

\sol

\frame{
\frametitle{Example 2.3: Solution to part (a)}
\begin{itemize}
\item [\textbf{(a)}] Write down an expression for the volume of the box, in terms of $x$ and $y$.  \pause

\vspace{0.75cm}

\textbf{Solution}

\vsp
The volume is given by \pause
\begin{eqnarray*}
\textsf{length} \times \textsf{width} \times \textsf{height} &=& 1350 \pause \\
     & &\\
y \times x \times x &=& 1350 \pause \\
x^{2}y  &=& 1350.
\end{eqnarray*}
\end{itemize}
}

\frame{
\frametitle{Example 2.3: Solution to part (b) (1/2)}
\begin{itemize}
\item [\textbf{(b)}] Formulate an expression for the surface area $S$ of the box, in terms of $x$ only.  \pause

\vspace{0.75cm}

\textbf{Solution} \pause

\vsp

Looking at the net, there are four rectangles with area $xy$ and two squares with area $x^{2}$.  So the total surface area is \pause
\[
S = 4xy+2x^{2}. 
\]
\end{itemize}
}

\frame{
\frametitle{Example 2.3: Solution to part (b) (2/2)}
Now from (a), we know that \pause
\[
y = \frac{1350}{x^{2}}.
\] \pause
Substituting this into the equation for $S$ gives \pause
\begin{eqnarray*}
S &=& 4x\left(\frac{1350}{x^{2}}\right)+2x^{2} \pause \\
& & \\
   &=& \frac{4x \times 1350}{x^{2}} + 2x^{2} \pause \\
 & & \\
   &=& \frac{5400}{x} + 2x^{2} \pause = 5400x^{-1}+2x^{2}.
\end{eqnarray*}
}

\normal

\frame{
\frametitle{Example 2.3}
\begin{itemize}
\item [\textbf{(c)}] Find $\displaystyle \frac{dS}{dx}$, and hence show that the optimal strategy is to use a cuboid box for the chocolates.  What are the dimensions of this cuboid? 
\end{itemize} 
}

\sol

\frame{
\frametitle{Example 2.3: Solution to part (c) (1/3)}
We have 
\[
S = 5400x^{-1}+2x^{2}.
\]\pause
Thus,
\[
\frac{dS}{dx} = \pause -5400x^{-2} \pause +4x.
\]\pause
At turning points the gradient is zero.  Thus \pause
\begin{eqnarray*}
-\frac{5400}{x^{2}}+4x &=& 0 \pause \\
 & & \\
                 4x   &=&\frac{5400}{x^{2}}
\end{eqnarray*}
}
\frame{
\frametitle{Example 2.3: Solution to part (c) (2/3)}
So \pause
\begin{eqnarray*}
4x^{3}  &=&5400 \pause \\
     x^{3} &=& 1350 \pause \\
         x &=&^{3}\sqrt{1350} \pause = 11.052 \textsf{ cm}. 
\end{eqnarray*}
}

\frame{
\frametitle{Example 2.3: Solution to part (c) (3/3)}
When $x=11.052$, \pause
\[
y = \frac{1350}{x^{2}} = \frac{1350}{11.052^{2}} = 11.052 \textsf{ cm};
\]
with reference to the net, we see this will give a cuboid shape for the box!
}


\normal
\frame{
\frametitle{Example 2.3}
\begin{itemize}
\item [\textbf{(d)}] Use the second derivative test to show that you have minimised the amount of packaging used.  
\end{itemize}
}

\sol
\frame{
\frametitle{Example 2.3: Solution to part (d) (1/1)}
We know that
\[
\frac{dS}{dx} = -5400x^{-2}+4x.
\]\pause
Thus \pause
\[
\frac{d^{2}S}{dx^{2}} = 10800x^{-3}+4.
\] \pause
At our turning point, $x=11.052$, giving \pause
\[
\frac{d^{2}S}{dx^{2}} = \frac{10800}{11.052^{3}}+4 =  12,
\] \pause
which is positive -- this confirms that our turning point is a \textcolor{purple}{\bf minimum}.
}


\normal

\frame{

\frametitle{2.3 Partial differentiation}
As you will see in some of your other courses, most relationships in Economics, Accounting and Finance involve \textcolor{purple}{\bf more than two variables}. 

\vsp

 For example, the demand for a good depends not only on its own price but also on the price of substitutable or complementary goods, incomes of consumers, advertising expenditure and so on.  

\vsp

Likewise, the output from a production process depends on a variety of inputs, including land, capital and labour.  

\vsp

To analyse general economic behaviour we must extend the concept of differentiation to several variables.  
}

\sol

\frame{
\frametitle{Examples}
\begin{itemize}
\item [\textbf{1.}] If $f(x,y) = xy+2y$, evaluate
\begin{itemize}
\item [(a)] $f(3,4)$;
\item [(b)] $f(4,3)$.
\end{itemize}
\end{itemize} \pause
\begin{eqnarray*}
f(3,4) &=& 3\times 4 + 2\times 4 = 20  \\ \pause
f(4,3) &=& 4 \times 3 + 2\times 3 =18
\end{eqnarray*}
}

\frame{
\frametitle{Examples}
 \begin{itemize}
\item [\textbf{2.}] If $g(x_1,x_2,x_3)=x_{1}^2+x_{2}-3x_{3}$, evaluate
\begin{itemize}
\item [(a)] $g(5,6,10)$;
\item [(b)] $g(0,0,0)$.
\end{itemize}
\end{itemize} \pause
\begin{eqnarray*}
g(5,6,10)  &=& 5^2+6-(3\times 10) = 1 \\ \pause
g(0,0,0)  &=& 0.
\end{eqnarray*}
}

\normal

\frame{
\frametitle{2.3 Partial differentiation}
Given a function of two variables, for example
\[
z=f(x,y),
\]
we can determine two first--order derivatives. \pause  The \textit{partial derivative of $f$ with respect to $x$} is written as
\[
\frac{\partial z}{\partial x} \quad \textrm{\sf or} \quad \frac{\partial f}{\partial x} \quad \textrm{\sf or} \quad f_{x},
\]
and is found by differentiating $f$ with respect to $x$, with $y$ held constant. \pause

\vsp

 Similarly, the \textit{partial derivative of $f$ with respect to $y$} is written as 
\[
\frac{\partial z}{\partial y} \quad \textrm\sf {or} \quad \frac{\partial f}{\partial y} \quad \textrm{\sf or} \quad f_{y},
\]
and is found by differentiating $f$ with respect to $y$, with $x$ held constant.}

\sol

\frame{
  \frametitle{Examples}

 
Find the first--order partial derivatives of the functions
\begin{itemize}
\item [(a)] $f(x,y)=x^2+y^3$; \pause

\vsp

\textbf{Solution} \pause

\begin{eqnarray*}
\frac{\partial f}{\partial x} &=& 2x;\\ \pause
&& \\
\frac{\partial f}{\partial y} &=& 3y^{2}.
\end{eqnarray*}
\end{itemize}
}

\frame{
  \frametitle{Examples}
Find the first--order partial derivatives of the functions
\begin{itemize}
 
\item [(b)] $f(x,y)=x^2y$;

\vsp

\textbf{Solution} \pause

\begin{eqnarray*}
\frac{\partial f}{\partial x} &=& 2xy; \\ \pause
\frac{\partial f}{\partial y} &=& x^{2}.
\end{eqnarray*}
\end{itemize}
}

\frame{
  \frametitle{Examples}
Find the first--order partial derivatives of the functions
\begin{itemize}
 
\item [(c)]  $f(x,y)=x^2y^3-10x$.

\vsp

\textbf{Solution} \pause

\begin{eqnarray*}
\frac{\partial f}{\partial x} &=& 2xy^{3}-10; \pause\\
\frac{\partial f}{\partial y} &=& 3x^{2}y^{2}.
\end{eqnarray*}
\end{itemize}
}

\normal

\frame{
\frametitle{2.3 Partial differentiation}
In general, when we differentiate a function of two variables, the thing we end up with is itself a function of two variables. \pause

\vsp

 This suggests the possibility of differentiating a second time.\pause

\vsp

  In fact, there are four \textit{second--order partial derivatives}.
}


\frame{
\frametitle{2.3 Partial differentiation}
  We write:
\[
\frac{\partial^{2}z}{\partial x^{2}} \quad \textrm{\sf or} \quad \frac{\partial^{2}f}{\partial x^{2}} \quad \textrm{\sf or} \quad f_{xx}
\]
for the function obtained by differentiating twice with respect to $x$,\pause
\[
\frac{\partial^{2}z}{\partial y^{2}} \quad \textrm{\sf or} \quad \frac{\partial^{2}f}{\partial y^{2}} \quad \textrm{\sf or} \quad f_{yy}
\]
for the function obtained by differentiating twice with respect to $y$;
}

\frame{
\frametitle{2.3 Partial differentiation}
\[
\frac{\partial^{2}z}{\partial y \partial x} \quad \textrm{\sf or} \quad \frac{\partial^{2}f}{\partial y \partial x} \quad \textrm{\sf or} \quad f_{yx}
\]
for the function obtained by differentiating first with respect to $x$ and then with respect to $y$, and \pause
\[
\frac{\partial^{2}z}{\partial x \partial y} \quad \textrm{\sf or} \quad \frac{\partial^{2}f}{\partial x \partial y} \quad \textrm{\sf or} \quad f_{xy}
\]
for the function obtained by differentiating first with respect to $y$ and then with respect to $x$. 
}

\frame{
\frametitle{Examples}
Find expressions for the second--order partial derivatives $f_{xx}$, $f_{yy}$, $f_{yx}$ and $f_{xy}$ for the functions
\begin{itemize}
\item [(a)] $f(x,y)=x^2+y^3$;
\item [(b)] $f(x,y)=x^2y$. 
\end{itemize}
}

\sol

\frame{
\frametitle{Examples}
For part (a), we know that 
\[
f_{x} = 2x  \quad \textsf{and} \quad f_{y} = 3y^{2}.
\] \pause

Thus
\begin{eqnarray*}
f_{xx}  &=& 2; \\ \pause
f_{yy}  &=& 6y; \\ \pause
f_{xy}  &=& 0; \\ \pause
f_{yx}  &=& 0.
\end{eqnarray*}
}

\frame{
\frametitle{Examples}
For part (b), we know that
\[
f_{x} = 2xy \quad \textsf{and} \quad f_{y} = x^{2}.
\] \pause

Thus
\begin{eqnarray*}
f_{xx}   &=& 2y; \\ \pause
f_{yy}   &=& 0; \\ \pause
f_{xy}   &=&2x; \\ \pause
f_{yx}   &=&2x.
\end{eqnarray*}
}



 


\begin{comment}

\frame{
\frametitle{Plan for today}
\begin{itemize}
\item \textbf{Attendance list:} don't forget to sign in \pause (you can't email us at a later date and tell us you forgot to sign in.  Well, you \textit{can} do this, but nothing will be done about it!) \pause

\vspl

\item \textbf{Chapter 2:} Question 5, 6 and 7 on page 59 of the lecture notes (we might run through some of this stuff at the board in around 15/20 minutes) \pause

\vspl

\item \textbf{Chapter 3:} lecture notes will be given out so we can make a prompt start in the lecture this Friday 

\end{itemize}
}

\frame{
\frametitle{Plan for today}
\begin{itemize}
\item \textbf{Case study 1:}
\begin{itemize}
\item [--] Some general feedback \pause

\vspl

\item [--] Work is now available to collect from the ACC1012/1053 homework collection box, on the 3rd floor of the Herschel Building \pause

\end{itemize} 

\vspl

\item \textbf{Case study 2:} please form groups; we will then give out the case study material and you must sign up using the group membership forms
\end{itemize}
}


\frame{
\frametitle{Case study 1: General feedback}
\begin{center}
\begin{tabular}{|c c|c c|c c|c|}\hline
$n$      &$n^{*}$      &Mean     &Median     &LQ    &UQ    &SD  \\ \hline
243      &5            &20.8     &21         &20    &22    &2.45 \\ \hline
\end{tabular}
\end{center} \pause
            
\begin{center}
\includegraphics[width=7cm,height=6.65cm]{cs1marks.ps}
\end{center} \pause

}

\frame{
\frametitle{Case study 1: iPhone feedback}
\begin{itemize}
\item Generally very well done 

\vspl

\item Nearly all students were able to form linear functions for supply and demand

\vspl

\item  Most students used simultaneous equations to find the optimum price

\vspl

\item Most students forgot to give a practical interpretation of the gradient for supply and demand equations and thus lost 2 marks

\vspl

\item  Only a handful of students commented on the suitability of the linear model
\end{itemize}
}

\frame{
\frametitle{Case study 1: alcohol feedback}
\begin{itemize}

\item Once again, generally well done!

\vspl

\item Students forgot to give practical interpretation of the gradient

\vspl

\item  Students struggled with the concept of a ceiling price and most did not calculate it explicitly

\vspl

\item  Most students did not comment on the suitability of the linear model

\vspl

\item Otherwise well done, plots produced were fine

\vspl

\item Some extra research was impressive
\end{itemize}
}

\normal
\frame{

\vspace{1cm}

\huge
\textbf{Chapter 3}

\vspace{1cm}

\Large
\textbf{Collecting, presenting and }\\
\textbf{summarsing data}

}

\frame{
\frametitle{3. Data: collection, presentation and summaries}
\textcolor{purple}{\textbf{Data}} are the key to many important management decisions.

\vsp \pause

\begin{itemize}
\item Is a new product selling well? \pause
\vspl
\item Do potential customers like the new advertising campaign?
\end{itemize}

\vsp

\noindent These and many other questions can be answered with \textcolor{purple}{\textbf{data}}. 

}

\frame{
\frametitle{What we'll cover...}
\begin{itemize}
\item The different \textcolor{purple}{\bf kinds of data} that exist \pause
\vsp 
\item How to \textcolor{purple}{\bf get} data \pause
\vsp
\item How to \textcolor{purple}{\bf look at} the data we've got \pause
\vsp
\item How to \textcolor{purple}{\bf summarise} our data numerically
\end{itemize}
}


\frame{
\frametitle{Example: Sizing clothes}

\begin{center}
\includegraphics[width=4.5cm]{clothing-sizes.ps}\qquad
\includegraphics[width=3.5cm]{dress-size.ps}
\end{center}

\begin{itemize}
\item  Most clothing now comes in essentially standard 
sizes $\ldots$

\item  but where do these standards come from?

\item By sampling from the population as a whole, standards can be set around the most
common sizes.

\item  We cannot say that an individual is \alert{\textit{exactly}} a standard
size;

\item  However, we \alert{\textit{can}} say that they will \alert{\textit{probably}} fall within a range either side of a standard size.
\end{itemize}
}

\frame{
\frametitle{Example: Car maintenance}

\begin{center}
\includegraphics[width=4cm]{newcar.ps}\qquad
\includegraphics[width=4cm]{car-maintenance.ps}
\end{center}

\begin{itemize}
\item Just imagine you're buying a new car $\ldots$ \pause

\item ...it might be useful to know how much it will cost to run over the next few years. \pause

\item Obviously this cannot be predicted exactly -- 
\begin{itemize}
\item [--]each car will be slightly different;
\item [--]each user will be slightly different. \pause
\end{itemize}

\item Collecting data from people who have bought similar cars will give us some idea!
\end{itemize}
}

\frame{
\frametitle{Example: Profit versus advertising}
\begin{center}
\psfrag{10}[][]{\sf \tiny 10}
\psfrag{15}[][]{\sf \tiny 15}
\psfrag{20}[][]{\sf \tiny 20}
\psfrag{25}[][]{\sf \tiny 25}
\psfrag{30}[][]{\sf \tiny 30}
\psfrag{35}[][]{\sf \tiny 35}
\psfrag{50}[][]{\sf \tiny 50}
\psfrag{55}[][]{\sf \tiny 55}
\psfrag{60}[][]{\sf \tiny 60}
\psfrag{65}[][]{\sf \tiny 65}
\psfrag{P}[][]{\sf \tiny $P$ (Profit)}
\psfrag{A}[][]{\sf \tiny $A$ (Advertising)}
\psfrag{E}[][]{\sf \tiny $P=50.3+0.67A$}

\includegraphics[width=9cm,height=6cm]{determine.ps}
\end{center}
}
\frame{
\frametitle{Example: Profit versus advertising}
\begin{center}
\psfrag{10}[][]{\sf \tiny 10}
\psfrag{15}[][]{\sf \tiny 15}
\psfrag{20}[][]{\sf \tiny 20}
\psfrag{25}[][]{\sf \tiny 25}
\psfrag{30}[][]{\sf \tiny 30}
\psfrag{35}[][]{\sf \tiny 35}
\psfrag{50}[][]{\sf \tiny 50}
\psfrag{55}[][]{\sf \tiny 55}
\psfrag{60}[][]{\sf \tiny 60}
\psfrag{65}[][]{\sf \tiny 65}
\psfrag{P}[][]{\sf \tiny $P$ (Profit)}
\psfrag{A}[][]{\sf \tiny $A$ (Advertising)}
\psfrag{E}[][]{\sf \tiny $P=50.3+0.67A$}

\includegraphics[width=9cm,height=6cm]{determine2.ps}
\end{center}
}


\frame{
\frametitle{3.1 Important definitions}
The quantities measured in a study are called \textcolor{purple}{\textbf{random variables}}.
\pause

\vspace{0.3cm}

A particular outcome is called an \textcolor{purple}{\textbf{observation}}.

\vspace{0.3cm}

\pause
A collection of such observations is the \textcolor{purple}{\textbf{data}}.

\vspace{0.3cm}

\pause
The collection of all possible outcomes is the \textcolor{purple}{\textbf{population}}.

}

\frame{
\frametitle{3.1 Important definitions}
Suppose we are interested in the height of students on A\&F courses at Newcastle $\ldots$
\begin{center}
\includegraphics[width=1.5cm]{measuring-height.ps}
\end{center}
\begin{itemize}
\pause
\item Our \textcolor{purple}{\textbf{random variable}} is ``the height of students on A\&F courses at Newcastle''.
\pause
\item If Joe Bloggs is an A\&F student, and we measured his height, then that value would be a single \textcolor{purple}{\textbf{observation}}.
\pause
\item If we measured the height of every first year A\&F student, we would have a collection of such observations which would be our \textcolor{purple}{\textbf{data}}.
\pause
\item This would be a \textcolor{purple}{\textbf{sample}} from the
  \textcolor{purple}{\textbf{population}} which consists of all students
  registered on A\&F degrees.
\end{itemize}
}

\frame{
\frametitle{3.1 Important definitions}
\noindent Ideally, to get a true idea of what is going on, we'd like to observe the whole population (take a \textcolor{purple}{\textbf{census}}).  However, this can be difficult:
%\pause
\begin{itemize}
\item If the population is huge, then this would take ages!

\item \textit{And} it would be very costly!

\item In reality, we usually observe a subset of the population $\ldots$ but how do we choose who to observe?
\end{itemize}


\begin{center}
\includegraphics[width=3.5cm]{sample.ps}
\end{center}

}

\frame{
\frametitle{3.1 Important definitions {\small \textcolor{orange}{(Section 2.1, summer revision booklet)}}}
\noindent There are two types of variables:  \textcolor{purple}{\textbf{qualitative}} and  \textcolor{purple}{\textbf{quantitative}}. 
%\pause

\vspace{0.2cm}

\begin{itemize}
\item \textit{Qualitative} variables have non--numerical outcomes, and are usually \textcolor{purple}{\textbf{categorical}}  \pause
\begin{itemize}
\item [--]Sex of a person (categories: male or female);
\item [--]Colour of a car (categories: \textcolor{red}{red}, black, \textcolor{gray}{silver}, \textcolor{blue}{blue}, ...  --
  could code this to \textcolor{red}{1}, 2, \textcolor{gray}{3}, \textcolor{blue}{4}, ...);
\item [--]Mode of transport.
\end{itemize}

\vspace{0.2cm}

\pause
\item \textit{Quantitative} variables have numerical outcomes with a natural ordering \pause
\begin{itemize}
\item [--]people's height
\item [--]number of defective components in a batch
\end{itemize}
\end{itemize}
}

\frame{
\frametitle{3.1 Important definitions {\small \textcolor{orange}{(Section 2.1, summer revision booklet)}}}
We are most interested in \textcolor{purple}{\textbf{quantitative}} variables.

\vspace{0.5cm}

\pause
These variables can be subdivided into two types:  \pause

\begin{center}
 \textcolor{purple}{\textbf{discrete}} and  \textcolor{purple}{\textbf{continuous}}.  
\end{center}
\pause

\vspace{0.2cm}

\textbf{Discrete random variables}
\begin{itemize}
 
\item can only take a sequence of distinct values (usually
  integers);

\item are usually \textcolor{purple}{\bf{countable}} -- e.g.\ the number of people
  attending a tutorial group; 

\item can be \textcolor{purple}{\textbf{ordinal}} -- where the outcomes
  are ordered. 
\end{itemize}
}




\frame{
\frametitle{3.1 Important definitions  {\small \textcolor{orange}{(Section 2.1, summer revision booklet)}}}

\medskip

\textbf{Continuous random variables}
\begin{itemize}

\item can take any value over some continuous scale -- e.g.\ height or weight.

\item can be \textcolor{purple}{\textbf{measured}} to a very high degree
  of accuracy (provided we have the equipment to do so) $\ldots$

\item $\ldots$ however, we can never say \textit{precisely} how much someone weighs, for example,

\item might be measured to the nearest whole number -- and so could ``look'' discrete -- be careful!
\end{itemize}

\begin{center}
\includegraphics[width=3cm]{tape-measure.ps}
\includegraphics[width=3cm]{scales.ps}
\includegraphics[width=3cm]{stop-watch.ps}
\end{center}

}

\sol

\frame{
\frametitle{3.1 Important definitions}

\vspace{-2cm}

\begin{center}
\includegraphics[width=8.5cm,angle=-90]{datatree.ps}
\end{center}
}

\normal

\frame{
\frametitle{3.2 Sampling}
We can rarely observe the whole population. Instead we observe some
sub--set of this (called the \textcolor{purple}{\textbf{sample}}).
%\pause

\vspace{0.3cm}

The difficulty is in obtaining a
\textcolor{purple}{\textbf{representative}} sample. 

%\pause

\vspace{0.3cm}

For example, if you were to ask people leaving a gym if they took exercise this would produce a
\textcolor{purple}{\textbf{biased}} sample and would not be representative of the population
as a whole. 

%\pause

\vspace{0.3cm}

\textbf{The importance of obtaining a representative sample cannot be stressed too highly}.
}

\frame{
\frametitle{3.2 Sampling}
\noindent There are three general forms of sampling techniques:

\vsp

\pause
\begin{itemize}
\item [\textbf{1.}]\textcolor{purple}{\textbf{\textit{Random sampling}}}
  -- where the members of the sample are chosen by some random
  (i.e.\ unpredictable) mechanism.
\pause

\vspl

\item [\textbf{2.}] \textcolor{purple}{\textbf{\textit{Quasi--random sampling}}} --  where the mechanism for choosing the sample is only partly random.
\pause

\vspl

\item [\textbf{3.}]\textcolor{purple}{\textbf{\textit{Non--random
        sampling}}} --  where the sample is specifically selected rather than randomly selected.
\end{itemize}
}

\frame{
\frametitle{3.2.1 Simple random sampling...}
This method is the \textcolor{purple}{\textbf{simplest to understand}}. \pause



\vspace{0.3cm}

\noindent If we had a population of 200 students we could put all their names into a hat and draw out 20
names as our sample.  


\begin{center}
\includegraphics[width=1.75cm]{hat.ps}
\end{center}

\vspace{0.3cm}\pause

We cannot predict with certainty which 20 names will be drawn, and so
the sample is unpredictable, and therefore completely \textcolor{purple}{\textbf{random}}.  \pause

\vspace{0.3cm}

Each name has an \textcolor{purple}{\textbf{equally likely chance}} of being
drawn.



\vspace{0.3cm}

Furthermore each possible \textcolor{purple}{\textbf{sample of 20}} has an equal chance of being selected. 

}

\frame{
\frametitle{3.2.1 Simple random sampling...}


\vspace{0.3cm}


%This defines a \textcolor{purple}{\textbf{simple random sample}}.


\vspace{0.3cm}
%\pause

In reality the drawing
of the names would be done by a computer and the population and
samples would be considerably larger. 
}

\frame{
\frametitle{... and some disadvantages}

We often don't have a \textcolor{purple}{\textbf{complete list}} of the population. \pause


\vspace{0.3cm}

For example, if you were surveying the market for some new software, the population would be everybody with a compatible computer! \pause

\vspace{0.3cm}

 Not all elements of the population are \textcolor{purple}{\textbf{equally accessible}}. \pause

\vspace{0.3cm}

Purely by chance, you could pick an \textcolor{purple}{\textbf{unrepresentative sample}}!
}

\frame{ 
\frametitle{3.2.2 Stratified sampling...}
This is a form of random sample where clearly defined groups, or \textcolor{purple}{\textbf{strata}}, exist
within the population. \pause



\vspace{0.3cm}

If we know the overall proportion
of the population that falls into each of these groups, we can take a
simple random sample from each of the groups and then adjust the results according to the known proportions. \pause



\vspace{0.3cm}

 For example, if we assume that the
population is 55\% female and 45\% male and we wanted a sample of
1000, we would \pause

\begin{itemize}
 \item decide to have 550 females and 450 males in our sample, and then \pause

\item  pick the members of our sample from their respective groups randomly.
\end{itemize}


}
\frame{
\frametitle{... and some disadvantages}
We need clear information on the \textcolor{purple}{\textbf{size}} and
\textcolor{purple}{\textbf{composition}} of each stratum which can be difficult to
obtain.


\vspace{0.3cm}

\noindent We still need a \textcolor{purple}{\textbf{list of the entire population}} to sample from. 
}

\frame{
\frametitle{3.2.3 Systematic sampling...}
This is a form of \textcolor{purple}{\textbf{quasi--random sampling}} which can be used when the
population is clearly structured.  \pause



\vspace{0.3cm}

For example, if you were interested in
obtaining a 10\% sample from a batch of components being manufactured, 
you would 
\begin{itemize}

\item select the first component at random, and then \pause

\item pick every 10th item to come off the production line after that
\end{itemize}

\begin{center}
\includegraphics[width=3cm]{conveyorbelt.ps}
\end{center}

\vspace{0.3cm}

This scheme is \textcolor{purple}{\textbf{very easy to implement}}!
}

\frame{
\frametitle{... and some disadvantages}
This method is \textcolor{purple}{\textbf{not entirely random}}! \pause



\vspace{0.3cm}

If there is a pattern in the process, it is very easy to obtain a \textcolor{purple}{\textbf{biased sample}}.
}


\begin{frame}
\frametitle{Other types of sampling}

Read through Sections 3.2.4 to 3.2.8 of the notes before your tutorial
session next week. 

\medskip
\begin{itemize}
\item Multi-stage sampling
\medskip
\item Cluster sampling
\medskip
\item Judgemental sampling
\medskip
\item Accessibility sampling
\medskip
\item Quota sampling
\end{itemize}
\begin{center}
\includegraphics[width=3cm]{bookworm.ps}
\end{center}


\end{frame}


\frame{
\frametitle{3.2.9 Sample size}

\begin{center}
\includegraphics[width=5cm]{sample_size_tshirt.ps}
\end{center}

\pause
\medskip

\begin{itemize}
\item Larger samples will generally give more precise information
  about the population. 
\item Expense and time tend to limit the size of the sample.
\item E.g.\ national opinion polls often rely on samples in the region of
  just 1000. 
\end{itemize}

}
\frame{
\frametitle{3.3 Frequency tables}

\begin{itemize}
\item After collecting data, the first stage of any analysis is to
  present them in a simple, easily understood way. \pause

\vsp

\item \textcolor{purple}{\textbf{Tables}} are perhaps the simplest means of presenting data. \pause

\vsp

\item Tables can be informative, but some tables can be difficult to
  interpret, especially if they contain vast amounts of data.
\end{itemize}

}

\frame{
\frametitle{3.3 Frequency tables}

\begin{itemize}
\item \textcolor{purple}{\textbf{Frequency tables}} are amongst the most commonly-used tables and are perhaps the easiest to understand. \pause

\vsp

\item They can be used with continuous, discrete, categorical and
  ordinal data. \pause

\vsp

\item Frequency tables have uses in some of the techniques we will see
  in the next lecture. 
\end{itemize}

}

\frame{
\frametitle{3.3.1 Frequency tables for categorical data}
The following table presents the modes of transport used daily by 30
students to get to and from University.
\begin{center}
\begin{tabular}{|c|c||c|c||c|c|}
\hline
\textcolor{magenta}{\textbf{Student}} & \textcolor{magenta}{\textbf{Mode}} & \textcolor{magenta}{\textbf{Student}} & \textcolor{magenta}{\textbf{Mode}} &
\textcolor{magenta}{\textbf{Student}} & \textcolor{magenta}{\textbf{Mode}}\\ 
\hline
1 & Car & 11 & Walk & 21 & Walk\\
2 & Walk & 12 & Walk & 22 & Metro\\
3 & Car & 13 & Metro & 23 & Car\\
4 & Walk & 14 & Bus & 24 & Car\\
5 & Bus & 15 & Train & 25 & Car\\
6 & Metro & 16 & Bike & 26 & Bus\\
7 & Car & 17 & Bus & 27 & Car\\
8 & Bike & 18 & Bike & 28 & Walk\\
9 & Walk & 19 & Bike & 29 & Car\\
10 & Car & 20 & Metro & 30 & Car\\
\hline
\end{tabular}
\end{center}
}
\frame{
\frametitle{3.3.1 Frequency tables for categorical data}
\noindent The table obviously contains much information. However, it is difficult
to see which method of transport is the most widely used.  

\vspace{0.3cm}

\pause
\textbf{Idea:} count the number of students using each mode of
transport! 
\pause
\begin{center}
\begin{tabular}{|c | c|}
\hline
\textcolor{magenta}{\textbf{Mode}} & \textcolor{magenta}{\textbf{Frequency}}\\
\hline
Car & 10\\
Walk & 7\\
Bike & 4\\
Bus & 4\\
Metro & 4\\
Train & 1\\
\hline
\textbf{Total} & 30\\
\hline
\end{tabular}
\end{center}
This gives us a much clearer picture of the methods of transport used.
}

\frame{
\frametitle{3.3.1 Frequency tables for categorical data}
\noindent Also of interest might be the \textcolor{purple}{\textbf{\textit{relative}}} frequency of each of the
modes of transport. 

\vspace{0.3cm}

This is simply the frequency
expressed as a proportion of the total number of students surveyed. If this is given as a percentage, as here,
this is known as the \textcolor{purple}{\textbf{percentage relative frequency}}.  


\begin{center}
\begin{tabular}{|c | c | c|}
\hline
\textcolor{blue}{\textbf{Mode}} & \textcolor{blue}{\textbf{Frequency}} & \textcolor{blue}{\textbf{Relative Frequency
(\%)}}\\
\hline
Car & 10 & 33.3\\
Walk & 7 & 23.4\\
Bike & 4 & 13.3\\
Bus & 4 & 13.3\\
Metro & 4 & 13.3\\
Train & 1 & 3.4\\
\hline
\textbf{Total} & 30 & 100\\
\hline
\end{tabular}
\end{center}
}


\frame{
\frametitle{3.3.2 Frequency tables for count data}

\begin{center}
\includegraphics[width=4cm]{showroom.ps}
\end{center}


 The following table shows the raw data for car
sales at a new car showroom over a two week period in July.

\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\textcolor{blue}{\textbf{Date}} & \textcolor{blue}{\textbf{Cars Sold}} & \textcolor{blue}{\textbf{Date}} & \textcolor{blue}{\textbf{Cars Sold}}\\
\hline
1st July & ~9 & 8th July & 10\\
2nd July & ~8 & 9th July & ~5\\
3rd July & ~6 & 10th July & ~8\\
4th July & ~7 & 11th July & ~4\\
5th July & ~7 & 12th July & ~6\\
6th July & 10 & 13th July & ~8\\
7th July & 11 & 14th July & ~9\\
\hline
\end{tabular}
\end{center}
}

\frame{
\frametitle{Example 3.1}
Present these data in a relative frequency table by number of days on which different numbers of cars were sold.  
}

\sol

\frame{
\frametitle{Solution to Example 3.1}
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\textcolor{blue}{\textbf{Cars Sold}} & \textcolor{blue}{\textbf{Tally}} & 
\textcolor{blue}{\textbf{Frequency}} & \textcolor{blue}{\textbf{Relative Frequency \%}}\\
\hline
1 	& &\textcolor{white}{0} &\textcolor{white}{0} \\	
2  	& &\textcolor{white}{0} &\textcolor{white}{0} \\	
3 	& &\textcolor{white}{0} &\textcolor{white}{0} \\	
4 	&\textcolor{white}{l} &\textcolor{white}{1} &\textcolor{white}{7.14} \\	
5 	&\textcolor{white}{l} &\textcolor{white}{1} &\textcolor{white}{7.14} \\	
6 	&\textcolor{white}{ll} &\textcolor{white}{2} &\textcolor{white}{14.29} \\	
7 	&\textcolor{white}{ll} &\textcolor{white}{2} &\textcolor{white}{14.29} \\	
8 	&\textcolor{white}{lll} &\textcolor{white}{3} &\textcolor{white}{21.43} \\
9 	&\textcolor{white}{ll} &\textcolor{white}{2} &\textcolor{white}{14.29} \\
10 	&\textcolor{white}{ll} &\textcolor{white}{2} &\textcolor{white}{14.29}\\
11	&\textcolor{white}{l} &\textcolor{white}{1} &\textcolor{white}{7.14} \\
\hline
\textbf{Totals} &\textcolor{white}{14} &\textcolor{white}{14} &\textcolor{white}{100} \\
\hline
\end{tabular}
\end{center}
}

\frame{
\frametitle{Solution to Example 3.1}
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\textcolor{blue}{\textbf{Cars Sold}} & \textcolor{blue}{\textbf{Tally}} & 
\textcolor{blue}{\textbf{Frequency}} & \textcolor{blue}{\textbf{Relative Frequency \%}}\\
\hline
1 	& &\textcolor{white}{0} &\textcolor{white}{0} \\	
2  	& &\textcolor{white}{0} &\textcolor{white}{0} \\	
3 	& &\textcolor{white}{0} &\textcolor{white}{0} \\	
4 	&l &\textcolor{white}{1} &\textcolor{white}{7.14} \\	
5 	&l &\textcolor{white}{1} &\textcolor{white}{7.14} \\	
6 	&ll &\textcolor{white}{2} &\textcolor{white}{14.29} \\	
7 	&ll &\textcolor{white}{2} &\textcolor{white}{14.29} \\	
8 	&lll &\textcolor{white}{3} &\textcolor{white}{21.43} \\
9 	&ll &\textcolor{white}{2} &\textcolor{white}{14.29} \\
10 	&ll &\textcolor{white}{2} &\textcolor{white}{14.29}\\
11	&l &\textcolor{white}{1} &\textcolor{white}{7.14} \\
\hline
\textbf{Totals} &14 &\textcolor{white}{14} &\textcolor{white}{100} \\
\hline
\end{tabular}
\end{center}
}

\frame{
\frametitle{Solution to Example 3.1}
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\textcolor{blue}{\textbf{Cars Sold}} & \textcolor{blue}{\textbf{Tally}} & 
\textcolor{blue}{\textbf{Frequency}} & \textcolor{blue}{\textbf{Relative Frequency \%}}\\
\hline
1 	& &0 &\textcolor{white}{0} \\	
2  	& &0 &\textcolor{white}{0} \\	
3 	& &0 &\textcolor{white}{0} \\	
4 	&l &1 &\textcolor{white}{7.14} \\	
5 	&l &1 &\textcolor{white}{7.14} \\	
6 	&ll &2 &\textcolor{white}{14.29} \\	
7 	&ll &2 &\textcolor{white}{14.29} \\	
8 	&lll &3 &\textcolor{white}{21.43} \\
9 	&ll &2 &\textcolor{white}{14.29} \\
10 	&ll &2 &\textcolor{white}{14.29}\\
11	&l &1 &\textcolor{white}{7.14} \\
\hline
\textbf{Totals} &14 &14 &\textcolor{white}{100} \\
\hline
\end{tabular}
\end{center}
}

\frame{
\frametitle{Solution to Example 3.1}
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\textcolor{blue}{\textbf{Cars Sold}} & \textcolor{blue}{\textbf{Tally}} & 
\textcolor{blue}{\textbf{Frequency}} & \textcolor{blue}{\textbf{Relative Frequency \%}}\\
\hline
1 	& &0 &0 \\	
2  	& &0 &0 \\	
3 	& &0 &0 \\	
4 	&l &1 &7.14 \\	
5 	&l &1 &7.14 \\	
6 	&ll &2 &14.29 \\	
7 	&ll &2 &14.29 \\	
8 	&lll &3 &21.43 \\
9 	&ll &2 &14.29\\
10 	&ll &2 &14.29\\
11	&l &1 &7.14 \\
\hline
\textbf{Totals} &14 &14 &100 \\
\hline
\end{tabular}
\end{center}
}

\normal

\frame{
\frametitle{3.3.3 Frequency tables for continuous data}
With discrete data it is easy to
count the quantities in the defined categories. With \textcolor{purple}{\textbf{continuous data}}
this is not possible. \pause

\vsp

 For example, the following
data set represents the service time in seconds for callers to a
credit card call centre.


\begin{center}
\begin{tabular}{|c c c c c|}
\hline
 214.8 & 220.6 & 216.7 & 195.1 & 211.4\\
 195.8 & 201.1 & 185.8 & 183.4 & 178.8\\
 196.3 & 199.7 & 206.7 & 203.8 & 203.1\\
 200.8 & 201.3 & 205.6 & 181.6 & 201.7\\
 180.2 & 193.3 & 188.2 & 199.9 & 204.7\\
 198.3 & 193.1 & 204.0 & 197.2 & 193.5\\
 205.5 & 217.5 & 208.8 & 197.7 & 212.3\\
 209.9 & 197.6 & 204.9 & 203.1 & 192.9\\
 208.9 & 202.0 & 195.0 & 192.7 & 219.8\\
 208.8 & 200.7 & 191.9 & 188.8 & 206.8\\
\hline
\end{tabular}
\end{center}
}

\frame{
\frametitle{3.3.3 Frequency tables for continuous data}

This is what we do...
\begin{enumerate}
\item[\textbf{1.}] Divide the range of the variable into smaller ranges called \textcolor{purple}{\textbf{class intervals}}. \pause

\vspl

\item[\textbf{2.}] There should be \textcolor{purple}{\textbf{no gaps}} between these intervals. \pause

\vspl

\item[\textbf{3.}] The class interval width should be a convenient number (e.g. 5, 10, 100, depending on the data). \pause

\vspl

\item[\textbf{4.}] You should aim for no more than about \textcolor{purple}{\textbf{ten to fifteen classes}}.
\end{enumerate}
}

\frame{
\frametitle{Example 3.2}
Create a frequency table for the call centre data.  

\vsp

Also, find the relative frequencies in each class interval.
}

\sol

%\setbeamercolor{structure}{fg=red!80!black}

\frame{
\frametitle{Solution to Example 3.2}
For the call centre data, we might get:
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\textcolor{blue}{\textbf{Class Interval}} & \textcolor{blue}{\textbf{Tally}} & \textcolor{blue}{\textbf{Frequency}} &
\textcolor{blue}{\textbf{Relative Frequency \%}}\\
\hline
175 $\leq$ time $<$ 180                    & \textcolor{white}{l} &\textcolor{white}{1} &\textcolor{white}{2} \\
180 $\leq$ time $<$ 185 & \textcolor{white}{lll} &\textcolor{white}{3} &\textcolor{white}{6} \\
185 $\leq$ time $<$ 190 & \textcolor{white}{lll} &\textcolor{white}{3} &\textcolor{white}{6} \\
190 $\leq$ time $<$ 195 & \textcolor{white}{\sout{llll} l} & \textcolor{white}{6} & \textcolor{white}{12}\\
195 $\leq$ time $<$ 200 & \textcolor{white}{l}\textcolor{white}{\sout{llll} \sout{llll}} & \textcolor{white}{10}& \textcolor{white}{20}\\
200 $\leq$ time $<$ 205 & \textcolor{white}{\sout{llll} \sout{llll} ll} & \textcolor{white}{12} & \textcolor{white}{24}\\
205 $\leq$ time $<$ 210 & \textcolor{white}{\sout{llll} lll} & \textcolor{white}{8}& \textcolor{white}{16}\\
210 $\leq$ time $<$ 215 & \textcolor{white}{lll} & \textcolor{white}{3}& \textcolor{white}{6}\\
215 $\leq$ time $<$ 220 & \textcolor{white}{lll} & \textcolor{white}{3}& \textcolor{white}{6}\\
220 $\leq$ time $<$ 225                    & \textcolor{white}{l} & \textcolor{white}{1}& \textcolor{white}{2}\\
\hline
\textbf{Totals} & &\textcolor{white}{50} &\textcolor{white}{100} \\
\hline
\end{tabular}
\end{center}
}

\frame{
\frametitle{Solution to Example 3.2}
For the call centre data, we might get:
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\textcolor{blue}{\textbf{Class Interval}} & \textcolor{blue}{\textbf{Tally}} & \textcolor{blue}{\textbf{Frequency}} &
\textcolor{blue}{\textbf{Relative Frequency \%}}\\
\hline
175 $\leq$ time $<$ 180   & \textcolor{white}{l} &\textcolor{white}{1} &\textcolor{white}{2} \\
180 $\leq$ time $<$ 185 & \textcolor{white}{lll} &\textcolor{white}{3} &\textcolor{white}{6} \\
185 $\leq$ time $<$ 190 & \textcolor{white}{lll} &\textcolor{white}{3} &\textcolor{white}{6} \\
190 $\leq$ time $<$ 195 & \textcolor{white}{\sout{llll} l} & \textcolor{white}{6} & \textcolor{white}{12}\\
195 $\leq$ time $<$ 200 & \textcolor{white}{l}\textcolor{white}{\sout{llll} \sout{llll}} & \textcolor{white}{10}& \textcolor{white}{20}\\
200 $\leq$ time $<$ 205 & \textcolor{white}{\sout{llll} \sout{llll} ll} & \textcolor{white}{12} & \textcolor{white}{24}\\
205 $\leq$ time $<$ 210 & \textcolor{white}{\sout{llll} lll} & \textcolor{white}{8}& \textcolor{white}{16}\\
210 $\leq$ time $<$ 215 & l\textcolor{white}{ll} & \textcolor{white}{3}& \textcolor{white}{6}\\
215 $\leq$ time $<$ 220 & \textcolor{white}{lll} & \textcolor{white}{3}& \textcolor{white}{6}\\
220 $\leq$ time $<$ 225                  & \textcolor{white}{l} & \textcolor{white}{1}& \textcolor{white}{2}\\
\hline
\textbf{Totals} & &\textcolor{white}{50} &\textcolor{white}{100} \\
\hline
\end{tabular}
\end{center}
}

\frame{
\frametitle{Solution to Example 3.2}
For the call centre data, we might get:
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\textcolor{blue}{\textbf{Class Interval}} & \textcolor{blue}{\textbf{Tally}} & \textcolor{blue}{\textbf{Frequency}} &
\textcolor{blue}{\textbf{Relative Frequency \%}}\\
\hline
175 $\leq$ time $<$ 180 & \textcolor{white}{l} &\textcolor{white}{1} &\textcolor{white}{2} \\
180 $\leq$ time $<$ 185 & \textcolor{white}{lll} &\textcolor{white}{3} &\textcolor{white}{6} \\
185 $\leq$ time $<$ 190 & \textcolor{white}{lll} &\textcolor{white}{3} &\textcolor{white}{6} \\
190 $\leq$ time $<$ 195 & \textcolor{white}{\sout{llll} l} & \textcolor{white}{6} & \textcolor{white}{12}\\
195 $\leq$ time $<$ 200 & \textcolor{white}{l}\textcolor{white}{\sout{llll} \sout{llll}} & \textcolor{white}{10}& \textcolor{white}{20}\\
200 $\leq$ time $<$ 205 & \textcolor{white}{\sout{llll} \sout{llll} ll} & \textcolor{white}{12} & \textcolor{white}{24}\\
205 $\leq$ time $<$ 210 & \textcolor{white}{\sout{llll} lll} & \textcolor{white}{8}& \textcolor{white}{16}\\
210 $\leq$ time $<$ 215 & l\textcolor{white}{ll} & \textcolor{white}{3}& \textcolor{white}{6}\\
215 $\leq$ time $<$ 220 & \textcolor{white}{lll} & \textcolor{white}{3}& \textcolor{white}{6}\\
220 $\leq$ time $<$ 225 & l & \textcolor{white}{1}& \textcolor{white}{2}\\
\hline
\textbf{Totals} & &\textcolor{white}{50} &\textcolor{white}{100} \\
\hline
\end{tabular}
\end{center}
}

\frame{
\frametitle{Solution to Example 3.2}
For the call centre data, we might get:
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\textcolor{blue}{\textbf{Class Interval}} & \textcolor{blue}{\textbf{Tally}} & \textcolor{blue}{\textbf{Frequency}} &
\textcolor{blue}{\textbf{Relative Frequency \%}}\\
\hline
175 $\leq$ time $<$ 180 & \textcolor{white}{l} &\textcolor{white}{1} &\textcolor{white}{2} \\
180 $\leq$ time $<$ 185& \textcolor{white}{lll} &\textcolor{white}{3} &\textcolor{white}{6} \\
185 $\leq$ time $<$ 190 & \textcolor{white}{lll} &\textcolor{white}{3} &\textcolor{white}{6} \\
190 $\leq$ time $<$ 195 & \textcolor{white}{\sout{llll} l} & \textcolor{white}{6} & \textcolor{white}{12}\\
195 $\leq$ time $<$ 200 & \textcolor{white}{l}\textcolor{white}{\sout{llll} \sout{llll}} & \textcolor{white}{10}& \textcolor{white}{20}\\
200 $\leq$ time $<$ 205 & \textcolor{white}{\sout{llll} \sout{llll} ll} & \textcolor{white}{12} & \textcolor{white}{24}\\
205 $\leq$ time $<$ 210 & \textcolor{white}{\sout{llll} lll} & \textcolor{white}{8}& \textcolor{white}{16}\\
210 $\leq$ time $<$ 215 & l\textcolor{white}{ll} & \textcolor{white}{3}& \textcolor{white}{6}\\
215 $\leq$ time $<$ 220 & l\textcolor{white}{ll} & \textcolor{white}{3}& \textcolor{white}{6}\\
220 $\leq$ time $<$ 225 & l & \textcolor{white}{1}& \textcolor{white}{2}\\
\hline
\textbf{Totals} & &\textcolor{white}{50} &\textcolor{white}{100} \\
\hline
\end{tabular}
\end{center}
}

\frame{
\frametitle{Solution to Example 3.2}
For the call centre data, we might get:
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\textcolor{blue}{\textbf{Class Interval}} & \textcolor{blue}{\textbf{Tally}} & \textcolor{blue}{\textbf{Frequency}} &
\textcolor{blue}{\textbf{Relative Frequency \%}}\\
\hline
175 $\leq$ time $<$ 180 & \textcolor{white}{l} &\textcolor{white}{1} &\textcolor{white}{2} \\
180 $\leq$ time $<$ 185 & \textcolor{white}{lll} &\textcolor{white}{3} &\textcolor{white}{6} \\
185 $\leq$ time $<$ 190  & \textcolor{white}{lll} &\textcolor{white}{3} &\textcolor{white}{6} \\
190 $\leq$ time $<$ 195 & \textcolor{white}{\sout{llll} l} & \textcolor{white}{6} & \textcolor{white}{12}\\
195 $\leq$ time $<$ 200  & l\textcolor{white}{\sout{llll} \sout{llll}} & \textcolor{white}{10}& \textcolor{white}{20}\\
200 $\leq$ time $<$ 205 & \textcolor{white}{\sout{llll} \sout{llll} ll} & \textcolor{white}{12} & \textcolor{white}{24}\\
205 $\leq$ time $<$ 210 & \textcolor{white}{\sout{llll} lll} & \textcolor{white}{8}& \textcolor{white}{16}\\
210 $\leq$ time $<$ 215 & l\textcolor{white}{ll} & \textcolor{white}{3}& \textcolor{white}{6}\\
215 $\leq$ time $<$ 220 & l\textcolor{white}{ll} & \textcolor{white}{3}& \textcolor{white}{6}\\
220 $\leq$ time $<$ 225 & l & \textcolor{white}{1}& \textcolor{white}{2}\\
\hline
\textbf{Totals} & &\textcolor{white}{50} &\textcolor{white}{100} \\
\hline
\end{tabular}
\end{center}
}

\frame{
\frametitle{Solution to Example 3.2}
For the call centre data, we might get:
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\textcolor{blue}{\textbf{Class Interval}} & \textcolor{blue}{\textbf{Tally}} & \textcolor{blue}{\textbf{Frequency}} &
\textcolor{blue}{\textbf{Relative Frequency \%}}\\
\hline
175 $\leq$ time $<$ 180                     & \textcolor{white}{l} &\textcolor{white}{1} &\textcolor{white}{2} \\
180 $\leq$ time $<$ 185  & \textcolor{white}{lll} &\textcolor{white}{3} &\textcolor{white}{6} \\
185 $\leq$ time $<$ 190  & \textcolor{white}{lll} &\textcolor{white}{3} &\textcolor{white}{6} \\
190 $\leq$ time $<$ 195& \textcolor{white}{\sout{llll} l} & \textcolor{white}{6} & \textcolor{white}{12}\\
195 $\leq$ time $<$ 200 & l\textcolor{white}{\sout{llll} \sout{llll}} & \textcolor{white}{10}& \textcolor{white}{20}\\
200 $\leq$ time $<$ 205 & \textcolor{white}{\sout{llll} \sout{llll} ll} & \textcolor{white}{12} & \textcolor{white}{24}\\
205 $\leq$ time $<$ 210 & \textcolor{white}{\sout{llll} lll} & \textcolor{white}{8}& \textcolor{white}{16}\\
210 $\leq$ time $<$ 215  & ll\textcolor{white}{l} & \textcolor{white}{3}& \textcolor{white}{6}\\
215 $\leq$ time $<$ 220 & l\textcolor{white}{ll} & \textcolor{white}{3}& \textcolor{white}{6}\\
220 $\leq$ time $<$ 225 & l & \textcolor{white}{1}& \textcolor{white}{2}\\
\hline
\textbf{Totals} & &\textcolor{white}{50} &\textcolor{white}{100} \\
\hline
\end{tabular}
\end{center}
}

\frame{
\frametitle{Solution to Example 3.2}
For the call centre data, we might get:
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\textcolor{blue}{\textbf{Class Interval}} & \textcolor{blue}{\textbf{Tally}} & \textcolor{blue}{\textbf{Frequency}} &
\textcolor{blue}{\textbf{Relative Frequency \%}}\\
\hline
175 $\leq$ time $<$ 180 & l &\textcolor{white}{1} &\textcolor{white}{2} \\
180 $\leq$ time $<$ 185 & lll &\textcolor{white}{3} &\textcolor{white}{6} \\
185 $\leq$ time $<$ 190 & lll &\textcolor{white}{3} &\textcolor{white}{6} \\
190 $\leq$ time $<$ 195 & \sout{llll} l & \textcolor{white}{6} & \textcolor{white}{12}\\
195 $\leq$ time $<$ 200& \textcolor{white}{l}\sout{llll} \sout{llll} & \textcolor{white}{10}& \textcolor{white}{20}\\
200 $\leq$ time $<$ 205 & \sout{llll} \sout{llll} ll & \textcolor{white}{12} & \textcolor{white}{24}\\
205 $\leq$ time $<$ 210 & \sout{llll} lll & \textcolor{white}{8}& \textcolor{white}{16}\\
210 $\leq$ time $<$ 215 & lll & \textcolor{white}{3}& \textcolor{white}{6}\\
215 $\leq$ time $<$ 220 & lll & \textcolor{white}{3}& \textcolor{white}{6}\\
220 $\leq$ time $<$ 225 & l & \textcolor{white}{1}& \textcolor{white}{2}\\
\hline
\textbf{Totals} & &\textcolor{white}{50} &\textcolor{white}{100} \\
\hline
\end{tabular}
\end{center}
}

\frame{
\frametitle{Solution to Example 3.2}
For the call centre data, we might get:
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\textcolor{blue}{\textbf{Class Interval}} & \textcolor{blue}{\textbf{Tally}} & \textcolor{blue}{\textbf{Frequency}} &
\textcolor{blue}{\textbf{Relative Frequency \%}}\\
\hline
175 $\leq$ time $<$ 180  & l &1 &\textcolor{white}{2} \\
180 $\leq$ time $<$ 185 & lll &3 &\textcolor{white}{6} \\
185 $\leq$ time $<$ 190 & lll &3 &\textcolor{white}{6} \\
190 $\leq$ time $<$ 195 & \sout{llll} l & 6 & \textcolor{white}{12}\\
195 $\leq$ time $<$ 200 & \textcolor{white}{l}\sout{llll} \sout{llll} & 10& \textcolor{white}{20}\\
200 $\leq$ time $<$ 205 & \sout{llll} \sout{llll} ll & 12 & \textcolor{white}{24}\\
205 $\leq$ time $<$ 210 & \sout{llll} lll & 8& \textcolor{white}{16}\\
210 $\leq$ time $<$ 215 & lll & 3& \textcolor{white}{6}\\
215 $\leq$ time $<$ 220 & lll & 3& \textcolor{white}{6}\\
220 $\leq$ time $<$ 225 & l & 1& \textcolor{white}{2}\\
\hline
\textbf{Totals} & &50  &\textcolor{white}{100} \\
\hline
\end{tabular}
\end{center}
}

\frame{
\frametitle{Solution to Example 3.2}
For the call centre data, we might get:
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\textcolor{blue}{\textbf{Class Interval}} & \textcolor{blue}{\textbf{Tally}} & \textcolor{blue}{\textbf{Frequency}} &
\textcolor{blue}{\textbf{Relative Frequency \%}}\\
\hline
175 $\leq$ time $<$ 180                   & l &1 &2 \\
180 $\leq$ time $<$ 185 & lll &3 &6 \\
185 $\leq$ time $<$ 190  & lll &3 &6 \\
190 $\leq$ time $<$ 195 & \sout{llll} l & 6 & 12\\
195 $\leq$ time $<$ 200 & \textcolor{white}{l}\sout{llll} \sout{llll} & 10& 20\\
200 $\leq$ time $<$ 205 & \sout{llll} \sout{llll} ll & 12 & 24\\
205 $\leq$ time $<$ 210 & \sout{llll} lll & 8& 16\\
210 $\leq$ time $<$ 215& lll & 3& 6\\
215 $\leq$ time $<$ 220  & lll & 3& 6\\
220 $\leq$ time $<$ 225 & l & 1& 2\\
\hline
\textbf{Totals} & &50  &100 \\
\hline
\end{tabular}
\end{center}
}


\normal

\frame{

\frametitle{3.4 Graphical methods for presenting data}
\noindent So far  we have looked at \pause
\vspl
%\pause
\begin{itemize}
\item different types of \textcolor{purple}{\textbf{data}}, \pause
%\pause
%\item how to take \textcolor{red}{\textbf{surveys}}
%\pause
%\item how to \textcolor{red}{\textbf{sample}} from the \textcolor{red}{\textbf{population}}
%\pause
\item and how to summarise data in a \textcolor{purple}{\textbf{frequency table}}
%\begin{itemize}
%\item [--]frequency tables
%\item [--]\textit{relative} frequency tables
%\end{itemize}
\end{itemize} \pause

\vspace{0.5cm}
%\pause
We now look at how to display data \textcolor{purple}{\textbf{graphically}}. \pause

\bigskip

Allows us to see the \textcolor{purple}{\bf main features} of a dataset quickly and
  clearly.  \pause
\medskip

\begin{itemize}
\item Is the distribution symmetric or asymmetric? \pause
\vspl
\item Are the data spread out or tightly concentrated? \pause
\vspl
\item Do there appear to be groupings/clusters within the data? 
\end{itemize}
}

\frame{
\frametitle{3.4.1 Stem and leaf plots}

\noindent \textcolor{purple}{\textbf{Stem and leaf plots}} are a quick and easy way of 
representing data graphically. \pause

\vspace{0.3cm}

\noindent They can be used with both \textcolor{purple}{\textbf{discrete}} and \textcolor{purple}{\textbf{continuous}} data. \pause

\vspace{0.3cm}

\noindent A bit like constructing a frequency table -- but carries visual information about the shape of the distribution. \pause

\vspace{0.3cm}

\noindent Best seen via an example!
 
}

\frame{
\frametitle{Example: Percentage returns on a share}
\noindent  The following numbers show the percentage returns on an ordinary share for 23 consecutive months:
\begin{center}
\begin{tabular}{c c c c c c c c }

\textcolor{blue}{\textbf{0.2}}	& \textcolor{blue}{\textbf{--2.1}}	& \textcolor{blue}{\textbf{1.0}}	& \textcolor{blue}{\textbf{0.1}}	& \textcolor{blue}{\textbf{--0.5}}	& \textcolor{blue}{\textbf{2.4}}	& \textcolor{blue}{\textbf{--2.3}}	& \textcolor{blue}{\textbf{1.5}}	\\
 \textcolor{blue}{\textbf{1.2}}	& \textcolor{blue}{\textbf{--0.6}}	& \textcolor{blue}{\textbf{2.4}}	& \textcolor{blue}{\textbf{--1.2}}	& \textcolor{blue}{\textbf{1.7}}	& \textcolor{blue}{\textbf{--1.3}}	& \textcolor{blue}{\textbf{--1.2}}	& \textcolor{blue}{\textbf{0.9}}	\\
\textcolor{blue}{\textbf{0.5}}	& \textcolor{blue}{\textbf{0.1}}	& \textcolor{blue}{\textbf{--0.1}}	& \textcolor{blue}{\textbf{0.3}}	& \textcolor{blue}{\textbf{--0.4}}	& \textcolor{blue}{\textbf{0.5}}	&\textcolor{blue}{\textbf{0.9}}	&	\\
\end{tabular}
\end{center}
%\pause
\begin{itemize}
\item The largest value is 2.4 and the smallest --2.3, and we have lots of decimal values in between
\item It seems sensible to have a \textcolor{purple}{\textbf{stem unit}} of 1 and a \textcolor{purple}{\textbf{leaf unit}} of 0.1 
\end{itemize}
}

\frame{
\frametitle{Example: Percentage returns on a share}
A stem and leaf diagram for this set of returns might look like: \pause

\begin{center}
\begin{tabular}{c | c c c c c c c c }
\textbf{--2} 	& 3 & 1 & &  & & & & \\
\textbf{--1} 	& 3 & 2 & 2 & & & & &\\
\textbf{--0} 	& 6 & 5 & 4 & 1 & & & & \\
\textbf{0}	& 1 & 1 & 2 & 3 & 5 & 5 & 9 & 9	\\
\textbf{1}	& 0 & 2 & 5 & 7 & & & &\\
\textbf{2}	& 4 & 4 & & & & & & 	\\	
\noalign{\medskip}
\multicolumn{1}{l}{\textcolor{purple}{\textbf{Stem}}}&\multicolumn{8}{l}{\textcolor{purple}{\textbf{Leaf}}}\\  
\end{tabular}

$n=23$,\quad $\text{stem unit}=1$,\quad $\text{leaf unit}= 0.1$.
\end{center} 
}
\frame{
\frametitle{Example: Production line data}

\noindent If there is more than one significant figure in the data, the extra
digits are \textcolor{purple}{\textbf{cut}}, not \textcolor{purple}{\textbf{rounded}} -- e.g. $2.97$ would be ``cut'' to 2.9.  

\vspace{0.3cm}

\pause
\noindent Consider the following data on
lengths of items on a production line (in cm):
\begin{center}
\begin{tabular}{c c c c c}
\textcolor{blue}{\textbf{2.97}} &\textcolor{blue}{\textbf{3.81}} &\textcolor{blue}{\textbf{2.54}} &\textcolor{blue}{\textbf{2.01}} &\textcolor{blue}{\textbf{3.49}} 	\\
\textcolor{blue}{\textbf{3.09}} &\textcolor{blue}{\textbf{1.99}} &\textcolor{blue}{\textbf{2.64}} &\textcolor{blue}{\textbf{2.31}} & \textcolor{blue}{\textbf{2.22}}
\end{tabular}
\end{center}
\pause
\noindent The stem and leaf plot for this is as follows:
\begin{center}
\begin{tabular}{l| c c ccccccc}

\noalign{\medskip} 
\textbf{1} & 9\\
\textbf{2} & 0 & 2 & 3\\
\textbf{2} & 5 & 6 & 9\\
\textbf{3} & 0 & 4\\
\textbf{3} & 8\\
\noalign{\medskip} 
\multicolumn{10}{l}{$n=10, \quad \text{stem unit}=1$ cm,\quad $\text{leaf unit}=0.1$ cm.}
\end{tabular}
\end{center}
}

\sol

\frame{
\frametitle{Example: Production line data}
Why do you think we \textcolor{purple}{\bf cut} the extra digits? \pause

\vsp

So values such as 2.97 do not end up in the wrong row!
}

\normal

\sol
\frame{
\frametitle{Example 3.3}
The observations in the table below are the recorded time it takes to get through to an 
operator at a telephone call centre (in seconds). \pause

\begin{center}
\begin{tabular}{| c c c c c c c c c c|}
\hline  
54 & 56 & 50 & 67 & 55 & 38 & 49 & 45 & 39 & 50\\
45 & 51 & 47 & 53 & 29 & 42 & 44 & 61 & 51 & 50\\
30 & 39 & 65 & 54 & 44 & 54 & 72 & 65 & 58 & 62\\
\hline
\end{tabular} 
\end{center}
\pause
\begin{center}
\begin{tabular}{c | c c c c c c c c c c c c}

\noalign{\medskip} 
\textbf{2}	 &9	&	&	&	&	&	&	&	&	&	&	&	\\
\textbf{3}	 &0	&8	&9	&9	&	&	&	&	&	&	&	&	\\
\textbf{4}	 &2	&4	&4	&5	&5	&7	&9	&	&	&	&	& 	\\
\textbf{5}	 &0	&0	&0	&1	&1	&3	&4	&4	&4	&5	&6	&8	\\
\textbf{6}	 &1	&2	&5	&5	&7 	&	&	&	&	&	&	&	\\
\textbf{7}	 &2	&	&	&	&	&	&	&	&	&	&	&	\\	
\noalign{\medskip} 
\multicolumn{1}{l}{\textcolor{purple}{\textbf{Stem}}}&\multicolumn{12}{l}{\textcolor{purple}{\textbf{Leaf}}}\\  
\noalign{\medskip} 
\multicolumn{13}{l}{$n=30, \quad \text{stem unit}=10, \quad \text{leaf unit}=1$}
\end{tabular}
\end{center}
}

\normal



\frame{
\frametitle{Example 3.4}
The stem and leaf plot below represents the marks on a test for 52
students.  Comment on the distribution of these marks.   

\begin{center}
\begin{tabular}{l|ccccccccccccccccc}
\noalign{\medskip} 
  1 & 4\\
  1 & 5&7&7\\
  2 & 1&1&2&3\\
  2 & 5&5&6&7&8&8 \\
  3 & 2&3&3&3&4&4&4\\
  3 & 5&5&6&7&7&8&8&9&9&9&9\\
  4 & 0&0&1&1&1&2&2&4&4&4\\
  4 & 5&7&7&8&8&8&9\\
  5 & 0&0&0\\
\noalign{\medskip} 
\multicolumn{17}{l}{$n=52, \quad \text{stem unit}=10$,\quad $\text{leaf unit}=1$.}
\end{tabular}
\end{center}
}

\sol

\frame{
\frametitle{Solution to Example 3.4}
\begin{itemize}
\item \textcolor{purple}{\bf Asymmetric distribution} of marks \pause -- in fact, marks are \textcolor{purple}{\bf negatively skewed} \pause
\vsp
\item Majority of students achieve marks in the 30s/40s \pause
\vsp
\item The \textcolor{purple}{\bf modal class} is 35--39 \pause
\vsp
\item Large \textcolor{purple}{\bf spread} of marks
\end{itemize}
}

\normal
\frame{
\frametitle{3.4.2 Bar charts}
\noindent \textcolor{purple}{\textbf{Bar charts}} are a commonly--used and clear way of presenting categorical data or ungrouped discrete frequency observations.  \pause See \textcolor{orange}{\bf section 2.3.2} of the \textcolor{orange}{\bf summer revision booklet}.  

\vspl

Recall the example on students' modes of transport:
\begin{center}
\begin{tabular}{|c | c|| c| c|| c| c|}
\hline
\textcolor{purple}{\textbf{Student}} & \textcolor{purple}{\textbf{Mode}} & \textcolor{purple}{\textbf{Student}} & \textcolor{purple}{\textbf{Mode}} &
\textcolor{purple}{\textbf{Student}} & \textcolor{purple}{\textbf{Mode}}\\ 
\hline
1 & Car & 11 & Walk & 21 & Walk\\
2 & Walk & 12 & Walk & 22 & Metro\\
3 & Car & 13 & Metro & 23 & Car\\
4 & Walk & 14 & Bus & 24 & Car\\
5 & Bus & 15 & Train & 25 & Car\\
6 & Metro & 16 & Bike & 26 & Bus\\
7 & Car & 17 & Bus & 27 & Car\\
8 & Bike & 18 & Bike & 28 & Walk\\
9 & Walk & 19 & Bike & 29 & Car\\
10 & Car & 20 & Metro & 30 & Car\\
\hline
\end{tabular}
\end{center}
%\noindent \textbf{Draw a bar chart to represent these data}
}


\frame{
\frametitle{3.4.2 Bar charts}
\begin{center}
\includegraphics[angle=270,width=10.5cm]{transport2.ps}
\end{center}
}


\frame{
\frametitle{3.4.3 Pie charts}
These charts are commonly used within industry to
communicate simple ideas, for example market share. 

\vsp

They are used to show the proportions of a whole. 

\vsp

They are best used when there
are only a handful of categories to display.   

\vsp

See \textcolor{orange}{Section 2.3.3} of the \textcolor{orange}{summer revision booklet} for more details. 
}

\begin{comment}

\frame{
\frametitle{Announcements}
\begin{itemize}
\item Last week: \textit{definitions}; how we \textit{get} data; how we \textit{look at} data using tables; \textit{relative frequency} \pause

\vspl

\item This week in seminars: \textit{stem-and-leaf plots}, and mentioned \textit{bar charts} and \textit{pie charts} \pause

\vspl

\item Today: More graphical techniques, and some numerical techniques, for summarising data \pause

\vspl

\item \textbf{CBA2} goes live in practice mode next week (assessed mode the week after)
\end{itemize}
}

\normal

\frame{
\frametitle{3.4.4 Histograms}
\noindent Bar charts have their limitations, one of which is that they cannot be used to present \textcolor{purple}{\textbf{continuous data}}. \pause

%\pause

\vspace{0.3cm}

\noindent When dealing with continuous random  variables a different kind of graph is required -- one such graph is the \textcolor{purple}{\textbf{histogram}}.

\vspace{0.3cm}

%\pause
}


%\setbeamercolor{structure}{fg=red!80!black}
\frame{
\frametitle{3.4.4 Histograms}
\noindent Consider the following data, which show service times (in seconds) for a telephone call centre. 

\begin{center}
\begin{tabular}{|c c c c c|}
\hline
 214.8412 & 220.6484 & 216.7294 & 195.1217 & 211.4795\\
 195.8980 & 201.1724 & 185.8529 & 183.4600 & 178.8625\\
 196.3321 & 199.7596 & 206.7053 & 203.8093 & 203.1321\\
 200.8080 & 201.3215 & 205.6930 & 181.6718 & 201.7461\\
 180.2062 & 193.3125 & 188.2127 & 199.9597 & 204.7813\\
 198.3838 & 193.1742 & 204.0352 & 197.2206 & 193.5201\\
 205.5048 & 217.5945 & 208.8684 & 197.7658 & 212.3491\\
 209.9000 & 197.6215 & 204.9101 & 203.1654 & 192.9706\\
 208.9901 & 202.0090 & 195.0241 & 192.7098 & 219.8277\\
 208.8920 & 200.7965 & 191.9784 & 188.8587 & 206.8912\\
\hline
\end{tabular}
\end{center}

%\noindent \textbf{Produce a histogram to display these data graphically}
}

\frame{
\frametitle{3.4.4 Histograms}
\noindent Producing a histogram is much like producing a bar chart. \pause

\vspace{0.3cm}

%\pause

\noindent It is often best to produce a frequency table first which collects all the data together in an ordered
format.  \pause

\vspace{0.3cm}

%\pause
\begin{center}
\begin{tabular}{|c|c|}
\hline
\textcolor{purple}{\textbf{Service time}} & \textcolor{purple}{\textbf{Frequency}}\\
\hline
$175\leq \textrm{\sf time} <180$ & 1\\
$180\leq \textrm{\sf time} <185$ &  3\\
$185\leq \textrm{\sf time} <190$ &  3\\
$190\leq \textrm{\sf time} <195$ &  6\\
$195\leq \textrm{\sf time} <200$ & 10\\
$200\leq \textrm{\sf time} <205$ & 12\\
$205\leq \textrm{\sf time} <210$ &  8\\
$210\leq \textrm{\sf time} <215$ &  3\\
$215\leq \textrm{\sf time} <220$ &  3\\
$220\leq \textrm{\sf time} <225$ &  1\\
\hline
\textbf{Total} & 50\\
\hline
\end{tabular}
\end{center}
}

\frame{
\frametitle{3.4.4 Histograms}
%\begin{center}
\hspace*{-1cm}
\includegraphics[height=7.3cm]{hist.eps}%\includegraphics[height=7.5cm]{callcentre.ps}
%\end{center}
}


\begin{frame}
\frametitle{3.4.4 Histograms}

\noindent At first sight histograms 
look similar to bar charts.  There are, however, some critical
differences:
%\pause

\bigskip

\begin{itemize}
\item The horizontal ($x$-axis) is a \textcolor{purple}{\bf continuous scale}\pause
\vspl
\item As a result there are \textcolor{purple}{\bf no gaps between the bars}\pause
\vspl 
\item Strictly speaking, the \textcolor{purple}{\bf area} of the bar is proportional to the frequency.  
\end{itemize}
\end{frame}

\frame{
\frametitle{Example 3.5}
The \textit{Holiday Hypermarket} travel agency received 64 telephone calls yesterday morning.  The table below gives information of the lengths, in minutes, of these telephone calls.
\begin{center}
\begin{tabular}{|c|c|c|} \hline
\textbf{Length ($\boldsymbol{x}$) minutes}  &\textbf{Frequency}   &\textbf{Frequency density} \\ \hline
$0\leq x < 5$  &4      &0.8 \\
$5\leq x <15$  &10     &1.0 \\
$15\leq x <30$ &24     &   \\
$30\leq x <40$ &20     &   \\
$40 \leq x<45$ &6     &   \\ \hline
\end{tabular}
\end{center}
Complete this table, and construct a histogram for these data.  What is the \textit{modal class} here?
}

\sol

\frame{
\frametitle{Solution to Example 3.5 (1/3)}
First, the \textcolor{purple}{\bf frequency densities}, or bar heights.  \pause

\vsp

Now we know that the area of the bar represents frequency.  \pause

\vsp

The width of the first is 5, and the area must be 4, so \pause
\begin{eqnarray*}
\textrm{\sf Area} &=& \textrm{\sf Base} \times \textrm{\sf Height} \pause \\
      4           &=& 5 \times \textrm{\sf Height} 
\end{eqnarray*} \pause
and so \pause
\[
\textrm{\sf Height} = 4/5 = 0.8.
\]
}

\sol

\frame{
\frametitle{Solution to Example 3.5 (3/3)}
\begin{center}
\includegraphics[angle=-90,width=11cm]{histy1.ps}
\end{center}
}

\frame{
\frametitle{Solution to Example 3.5 (3/3)}
\begin{center}
\includegraphics[angle=-90,width=11cm]{histy2.ps}
\end{center}
}

\frame{
\frametitle{Solution to Example 3.5 (3/3)}
\begin{center}
\includegraphics[angle=-90,width=11cm]{histy3.ps}
\end{center}
}

\frame{
\frametitle{Solution to Example 3.5 (3/3)}
\begin{center}
\includegraphics[angle=-90,width=11cm]{histy4.ps}
\end{center}
}

\frame{
\frametitle{Solution to Example 3.5 (3/3)}
\begin{center}
\includegraphics[angle=-90,width=11cm]{histy5.ps}
\end{center}
}

\normal

\frame{
\frametitle{3.4.4 Histograms}
\textbf{Summary}
\vsp
\begin{itemize}
\item Like a bar chart, but for continous data \pause
\vspl
\item First step: Collect your data into a frequency table \pause
\vspl
\item If the width of all class intervals is equal, just have ``frequency'' on the $y$--axis \pause
\vspl
\item Otherwise, you will need to think about ``frequency density'' 
\end{itemize}
}

\frame{
\frametitle{3.4.5 Percentage relative frequency histograms}
\noindent Instead of using \textcolor{purple}{\textbf{frequency}} on the vertical axis ($y$-axis), you \textit{could} use the
\textcolor{purple}{\textbf{percentage relative frequency}}. \pause For example:\pause

\begin{center}
\begin{tabular}{|c|c|c|}
\hline
\textcolor{blue}{\textbf{Service time}} &  \textcolor{blue}{\textbf{Frequency}} &\textcolor{blue}{\textbf{Relative Frequency (\%)}}\\
\hline
$175\leq \textrm{\sf time}<180$ &  1 &  2\\
$180\leq \textrm{\sf time}<185$ &  3 &  6\\
$185\leq \textrm{\sf time}<190$ &  3 &  6\\
$190\leq \textrm{\sf time}<195$ &  6 &  12\\
$195\leq \textrm{\sf time}<200$ &   10 &  20\\
$200\leq \textrm{\sf time}<205$ &   12 &  24\\
$205\leq \textrm{\sf time}<210$ &  8 &  16\\
$210\leq \textrm{\sf time}<215$ &  3 &  6\\
$215\leq \textrm{\sf time}<220$ &  3 &  6\\
$220\leq \textrm{\sf time}<225$ &  1 &  2\\
\hline
\textbf{Totals} & \textbf{50} & \textbf{100}\\
\hline
\end{tabular}
\end{center}
%\pause
}

%\setbeamercolor{structure}{fg=red!80!black}
\frame{
\frametitle{3.4.5 Percentage relative frequency histograms}
\begin{center}
\hspace*{-1cm}
\includegraphics[height=7.3cm]{percrelfreqhist.eps}%\includegraphics[height=7.5cm]{callcentre2.ps}
\end{center}
}
\frame{
\frametitle{3.4.5 Percentage relative frequency histograms}
\begin{center}
\hspace*{-0.8cm}
\includegraphics[height=7.3cm]{hist.eps}%\includegraphics[height=7.5cm]{callcentre2.ps}
\end{center}
}

\frame{
\frametitle{Why use percentage relative frequency?}
\textbf{It is useful for comparing two or more histograms}

\vsp

\begin{itemize}
\item [--] If one sample were larger than the other, the standard histograms would look different just because of the different sample sizes.  \pause
\vspl
\item [--] Looking at percentages ``\textcolor{purple}{\textbf{puts both samples on the same scale}}'' and removes this difference.\pause
\vspl
\item [--] This enables us to look at \textcolor{purple}{\textbf{relative}} differences.
\end{itemize}
}
\frame{
\frametitle{Why use percentage relative frequency?}
\noindent The following (frequency) histograms were created from two samples, one of size 100 and one of size 400 ...
\begin{center}
\includegraphics[height=6.75cm]{overlay1.ps}
\end{center}
}
\frame{

\frametitle{Why use percentage relative frequency?}
\noindent ... and this is what happens when we use \textcolor{purple}{\textbf{\% relative frequency}} 

\begin{center}
\includegraphics[height=6.75cm]{overlay2.ps}
\end{center}

}


\frame{
\frametitle{3.4.6 Polygons}
\noindent So percentage relative frequency histograms are useful for comparing two groups. \pause

\vspace{0.3cm}

\noindent However, can you imagine how \textcolor{purple}{\textbf{messy}} these ``superimposed'' histograms would get if we had three or more groups?

\vspace{0.3cm}

\pause
\noindent To get round this \textcolor{purple}{\textbf{messy problem}} we use \textcolor{purple}{\textbf{polygons}}.
}


\frame{
\frametitle{3.4.6 Polygons}
\begin{center}
\includegraphics[angle=-90,width=11cm]{histy99.ps}
\end{center}
}

\frame{
\frametitle{3.4.6 Polygons}
\begin{center}
\includegraphics[angle=-90,width=11cm]{histy999.ps}
\end{center}
}

\frame{
\frametitle{3.4.6 Polygons}
\begin{center}
\includegraphics[angle=-90,width=11cm]{histy9999.ps}
\end{center}
}

\frame{
\frametitle{3.4.6 Polygons}
\begin{center}
\includegraphics[angle=-90,width=11cm]{histy99999.ps}
\end{center}
}


\frame{
\frametitle{3.4.6 Polygons}
\begin{center}
\includegraphics[height=7cm]{Income.ps}
\end{center}
}

\frame{
\frametitle{3.4.7 Cumulative relative frequency polygons (Ogives)}
%\noindent \textcolor{red}{\textbf{Cumulative}} percentage relative frequency is also a useful tool.

%\vspace{0.3cm}

\noindent The \textcolor{purple}{\textbf{cumulative}} percentage relative frequency is simply the sum of the
percentage relative frequencies at the end of each class
interval.

\vspace{0.3cm}

\noindent In other words, we add the frequencies up as we go along!

\vspace{0.3cm}

\pause
\noindent \textbf{Consider the simple example:}
\begin{center}
\begin{tabular}{|c|c|c|}
\hline
\textcolor{red}{\textbf{Class Interval}} & \textcolor{red}{\textbf{ \% Relative Frequency}} &
\textcolor{red}{\textbf{Cum. \% Rel. Freq.}}\\
\hline
$0 \leq x < 10$  & 10 &  10\\
$10 \leq x < 20$ & 20 &  30\\
$20 \leq x < 30$ & 35 &  65\\
$30 \leq x < 40$ & 25 &  90\\
$40 \leq x < 50$ & 10 & 100\\
\hline 
\end{tabular}
\end{center}
}

\frame{
\frametitle{3.4.7 Cumulative relative frequency polygons (Ogives)}
The corresponding graph, or \textcolor{purple}{\textbf{ogive}}, is simple
to produce by hand -- watch out though!  For these plots we use the
\textcolor{purple}{\textbf{end--points}} instead of the
\textcolor{purple}{\textbf{mid--points}}!  %Why?!

}


\frame{
\frametitle{3.4.7 Cumulative relative frequency polygons (Ogives)}
\begin{center}
\includegraphics[height=8cm]{simple-ogive}%\includegraphics[height=7cm]{ogive.ps}
\end{center}
}

\frame{
\frametitle{3.4.7 Cumulative relative frequency polygons (Ogives)}
\noindent For the income data on West Road and Jesmond Road, we get:
\begin{center}
\includegraphics[height=7cm]{Ogivesforincome.ps}
\end{center}
}



\frame{
\frametitle{Other graphical summaries}


There are many other forms of graphical summary, including: 

\vsp

\pause

\begin{itemize}
\item Multiple Bar Charts
\vspl

\item Scatter plots
\vspl

\item Time series plots
\end{itemize}

\vsp
These are widely used in business presentations.

\vsp

\pause
\begin{center}
\includegraphics[width=3cm]{bookworm.ps}
\end{center}
}



\frame{
\frametitle{3.5 Numerical summaries of data}
\noindent So far we have only considered graphical methods for presenting
data -- \pause useful starting points. \pause

\vsp

 As we shall see, however, for many purposes we might also require \textcolor{purple}{\bf numerical} methods for summarising data.  \pause

\vsp

Before we introduce some ways of summarising data numerically, let us first think about some notation.  
}


\frame{
\frametitle{3.5.1 Mathematical notation}
\noindent Before we can talk more about numerical techniques we first need to
define some basic notation. 

\vsp

This will allow us to generalise all
situations with a \textcolor{purple}{\bf simple shorthand}.

}



\frame{
\frametitle{3.5.1 Mathematical notation}
Very often in statistics we replace actual numbers with letters in
order to be able to write \textcolor{purple}{\bf general formulae}. 

\vsp

We generally use a single \textcolor{purple}{\bf upper case} letter to represent our random variable and the \textcolor{purple}{\bf lower case} to represent sample data, with subscripts to distinguish individual observations in the sample. 

\vsp

 Amongst the most common letters to use is $x$, although $y$ and $z$ are frequently used as well. 
}


\frame{
\frametitle{3.5.1 Mathematical notation}
For example, suppose we ask a random sample of three people how many
mobile phone calls they made yesterday. 

\vsp

We might get the following data: \textcolor{brown}{\bf 1}, \textcolor{brown}{\bf 5}, \textcolor{brown}{\bf 7}. \pause

\vsp

If
we take another sample we will most likely get different data, say \textcolor{brown}{\bf 2}, \textcolor{brown}{\bf 0}, \textcolor{brown}{\bf 3}.
}

\frame{
\frametitle{3.5.1 Mathematical notation}
 Using algebra we can represent the \textcolor{purple}{\bf general case} as $x_1$, $x_2$, $x_3$: \pause
\begin{center}
\begin{tabular}{lc c c}
\textcolor{brown}{\bf 1st sample} & 1 & 5 & 7\\ \pause
\textcolor{brown}{\bf 2nd sample} & 2 & 0 & 3\\ \hline \pause
\textcolor{brown}{\bf typical sample} & $x_1$ & $x_2$ & $x_3$
\end{tabular}
\end{center}
}


\frame{
\frametitle{3.5.1 Mathematical notation}
\begin{center}
\begin{tabular}{lc c c}
\textcolor{brown}{\bf 1st sample} & 1 & 5 & 7\\ \pause
\textcolor{brown}{\bf 2nd sample} & 2 & 0 & 3\\ \hline \pause
\textcolor{brown}{\bf typical sample} & $x_1$ & $x_2$ & $x_3$
\end{tabular}
\end{center}
This can be generalised further by referring to the random variable \textcolor{purple}{\bf as a whole} as $X$ and the $i\text{th}$ observation in the sample as $x_i$. \pause

\vsp

Hence, in
the first sample above, the second observation is $x_2=5$
whilst in the second sample it is $x_2=0$. 

\vsp

The letters $i$ and $j$ are
most commonly used as the index numbers for the subscripts.

\vsp

\noindent The total number of observations in a sample is usually referred to by the letter $n$. Hence in our simple example above $n=3$.}


\frame{
\frametitle{3.5.1 Mathematical notation}
\noindent The next important piece of notation to introduce is the symbol

\LARGE
\[
\boldsymbol{\sum}
\]

\normalsize

\vsp

This is the upper case of the Greek letter \textcolor{purple}{\bf sigma}.  

\vsp

It is used to represent the phrase ``\textcolor{purple}{\bf sum the values}''. 
}

\frame{
\frametitle{3.5.1 Mathematical notation}
This symbol is used as follows: \pause
\begin{eqnarray*}
\sum_{i=1}^n x_i &=&\pause x_1 \pause + x_2 \pause + x_3 \pause + \dots + x_n.
\end{eqnarray*} \pause

\noindent This notation is used to represent the sum of all the values in our
data (from the first $i=1$ to the last $i=n$). \pause

\vsp This is often
abbreviated to $\sum x$ when we sum over all the data in our sample.
}

\frame{
\frametitle{3.5.2 Measures of Location}

\noindent These are also referred to as measures of \textcolor{purple}{\bf centrality} or, more commonly, \textcolor{purple}{\bf averages}.

\vsp

 In general terms, they tell us the value of a ``\textcolor{purple}{\bf typical}'' observation. 

\vsp

There are three measures which are commonly used: \pause
\vspl
\begin{itemize}
\item the \textcolor{purple}{\bf mean}; \pause
\vspl
\item  the \textcolor{purple}{\bf median}, and \pause
\vspl
\item the \textcolor{purple}{\bf mode}.\pause
\end{itemize}

\vsp We will consider these in turn.}


\frame{
\frametitle{3.5.2 The Arithmetic Mean}

\noindent The \textcolor{purple}{\bf arithmetic mean} is perhaps the most commonly used measure of location. 

\vsp

We
often refer to it as \underline{the} average or just the \textcolor{purple}{\bf mean}. 

\vsp

The arithmetic mean is calculated by simply adding all our
data together and dividing by the number of data we have. 

\vsp

So if our data were \textcolor{brown}{\bf 10},\textcolor{brown}{\bf 12}, and \textcolor{brown}{\bf 14}, then our mean would be \pause
\begin{align*} 
\frac{10 + 12 + 14}{3} &= \frac{36}{3} = 12.
\end{align*} 
}

\frame{
\frametitle{3.5.2 The Arithmetic Mean}
We denote the mean of our sample, or sample mean, using the notation
$\bar x$ (``$x$ bar'').  

\vsp

In general, the mean is calculated using the formula
\[
\bar x = \frac{1}{n}\sum_{i=1}^{n} x_i
\] 
or equivalently as \pause
\[
\bar x=\frac{\sum x}{n}.
\] \pause
 
\noindent For small data sets this is easy to calculate \textcolor{purple}{\bf by hand}, though this is simplified by using the \textcolor{purple}{\bf statistics mode} on a University
approved calculator (see next week's tutorials). 
}


\frame{
\frametitle{3.5.2 The Arithmetic Mean}
\noindent Sometimes we might not have the raw data; instead, the data might be available in the form of a \textcolor{purple}{\bf table}. 

\vsp

It is still possible to calculate the mean from such
data. 
}

\frame{
\frametitle{3.5.2 The Arithmetic Mean}
Let us first consider the case where we have some \textcolor{purple}{\bf ungrouped discrete data}. \pause

\vsp

Previously we have seen the data:
\begin{center}
\begin{tabular}{|c|c||c|c|}
\hline
\textbf{Date} & \textbf{Cars Sold} & \textbf{Date} & \textbf{Cars
Sold}\\
\hline
01/07/12 & 9 & 08/07/12 & 10\\
02/07/12 & 8 & 09/07/12 & 5\\
03/07/12 & 6 & 10/07/12 & 8\\
04/07/12 & 7 & 11/07/12 & 4\\
05/07/12 & 7 & 12/07/12 & 6\\
06/07/12 & 10 & 13/07/12 & 8\\
07/07/12 & 11 & 14/07/12 & 9\\
\hline
\end{tabular}
\end{center}
\noindent The mean number of cars sold per day is \pause
\begin{align*}
\bar x = \frac{9 + 8 + \ldots + 8 + 9}{14} = 7.71.
\end{align*}}

\frame{
\frametitle{3.5.2 The Arithmetic Mean}
\noindent These data can be presented as the \textcolor{purple}{\bf frequency table}:
{\normalsize 
\begin{center}
\begin{tabular}{|c|c c c c c c c c|}
\hline
\textbf{Cars Sold $(x_{(j)})$} &4  &5  &6  &7  &8  &9  &10  &11 \\ \hline
\textbf{Frequency $(f_j)$}     &1  &1  &2  &2  &3  &2  &2  &1  \\ \hline
\end{tabular}
\end{center}} \pause

\noindent The sample mean can be calculated from these data as
\begin{eqnarray*}
\bar x &=& \frac{4+5+\overbrace{6+6}^{\times 2}+\overbrace{7+7}^{\times 2}+\overbrace{8+8+8}^{\times 3}+\overbrace{9+9}^{\times 2}+\overbrace{10+10}^{\times 2}+11}{14}\\ \pause
& & \\
& & \\
 &=&\frac{(\textbf{4} \times 1) + (\textbf{5} \times 1) + (\textbf{6} \times 2) + (\textbf{7}\times 2)+ \cdots +(\textbf{11} \times 1)}{14} \\ \pause
 & & \\ 
& & \\
&=& 7.71.
\end{eqnarray*}
}


\frame{
\frametitle{3.5.2 The Arithmetic Mean}
\noindent We can express this calculation of the sample mean from discrete
tabulated data as \pause
\[
\bar x = \frac{1}{n}\sum_{j=1}^{k}f_j x_{(j)} .
\] \pause
\noindent Here the different values of $X$ which occur in the data are $ x_{(1)}, x_{(2)}, \ldots , 
x_{(k)}$. 

\pause

\vsp


In this example $ x_{(1)}=4,\ x_{(2)}=5, \ldots, x_{(k)}=11 $ and $ k=8. $
}

\frame{
\frametitle{3.5.2 The Arithmetic Mean}
\noindent If we only have \textcolor{purple}{\bf grouped frequency data}, it is still possible to \emph{approximate} the value of the sample mean. \pause

\vsp

Consider the following (ordered) data:
\begin{center}
\begin{tabular}{rrrrrrrrrr}
8.4 & 8.7 & 9.0 & 9.0 & 9.2 & 9.3 & 9.3 & 9.5 & 9.6 & 9.6 \\ 
9.6 & 9.7 & 9.7 & 9.9 & 10.3 & 10.4 & 10.5 & 10.7 & 10.8 & 11.4
\end{tabular} \pause
\end{center}
\noindent The sample mean of these data is \textbf{9.73}.} % s=0.75818}

\frame{
\frametitle{3.5.2 The Arithmetic Mean} 
Grouping these data into a frequency table gives
\begin{center}
\begin{tabular}{|c|c|c|}
\hline
\textbf{Class Interval} & \textbf{mid--point $(m_j)$} &
\textbf{Frequency $(f_j)$}\\
\hline
$8.0 \leq x <8.5$ &  8.25 & 1\\
$8.5 \leq x <9.0$ &  8.75 & 1\\
$9.0 \leq x <9.5$ &  9.25 & 5\\
$9.5 \leq x <10.0$ &  9.75 & 7\\
$10.0 \leq x <10.5$ & 10.25 & 2\\
$10.5 \leq x <11.0$ & 10.75 & 3\\
$11.0 \leq x <11.5$ & 11.25 & 1\\
\hline
\textbf{Total ($n$)} & & 20\\
\hline
\end{tabular}
\end{center}
}

\frame{
\frametitle{3.5.2 The Arithmetic Mean}
\noindent Therefore, the (approximate) sample mean
is calculated using the the frequencies ($f_j$) and the mid--points
($m_j$) as
\[
\bar x = \frac{1}{n}\sum_{j=1}^{k} f_j m_j.
\] \pause
\noindent For the grouped data above, we obtain \pause
\[
\bar x = \frac{1}{20}\left(1\times 8.25 + 1\times 8.75 + \cdots 
+ 3\times 10.75 + 1\times 11.25\right)= 9.775.
\]
\pause
\noindent This value is fairly close to the correct sample mean and is a reasonable approximation given the partial information we have in the
table.}


\frame{
\frametitle{3.5.2 The Median}

\noindent The \textcolor{purple}{\bf median} is occasionally used instead of the mean, particularly when the data have an \textcolor{purple}{\bf asymmetric profile}.  \pause

\vsp

The median is the \textcolor{purple}{\bf middle value} of the observations when they are listed in
ascending order. \pause

\vsp

It is straightforward to determine the median for
small data sets, particularly via a stem and leaf plot. \pause

\vsp

For larger
data sets, the calculation is more easily done using \texttt{Minitab} (see Semester 2).  
}


\frame{
\frametitle{3.5.2 The Median}
\noindent The median is that value that has half the observations above it and half below. 

\vsp

If the sample size ($n$) is an odd number, we have: \pause
\[
\text{\sf median}= \left(\frac{n + 1}{2}\right)^{th} \text{\sf largest observation}.
\] 
}
\frame{
\frametitle{3.5.2 The Median}
\noindent For example, if our data were 
\begin{center}
\textcolor{brown}{\bf 2}, \textcolor{brown}{\bf 3}, \textcolor{brown}{\bf 3}, \textcolor{brown}{\bf 5}, \textcolor{brown}{\bf 6}, \textcolor{brown}{\bf 7}, \textcolor{brown}{\bf 9}, \pause
\end{center} 
then the sample size ($n=7$) is an odd number and therefore the median is the \pause
\begin{align*}
\frac{7 + 1}{2} &= 4^{th} \text{ \sf largest observation},
\end{align*} \pause
that is, the median is the fourth largest (or smallest) ranked
observation.  \pause

\vsp

For these data the $\text{\sf median}=5$.
}

\frame{
\frametitle{3.5.2 The Median}
\noindent If the sample size ($n$) is an even number the process is slightly
more complicated:
\begin{eqnarray*}
\text{\sf median}&= &\text{\sf average of the } \left(\frac{n}{2}\right)^{th}\\
& &\\ 
& & \hspace{1cm} \textrm{\sf  and the } \left(\frac{n}{2} +1\right)^{th} \textrm{\sf largest observations}.
\end{eqnarray*}
}

\frame{
\frametitle{3.5.2 The Median}
For example, if our data were 
\begin{center}
\textcolor{brown}{\bf 2}, \textcolor{brown}{\bf  3}, \textcolor{brown}{\bf 3}, \textcolor{brown}{\bf 5}, \textcolor{brown}{\bf 6}, \textcolor{brown}{\bf 7}, \textcolor{brown}{\bf 9}, \textcolor{brown}{\bf 10},
\end{center} \pause
 then the sample size ($n=8$) is an even number and therefore \pause
\begin{eqnarray*}
\text{\sf median}&=&\textrm{\sf average of the } \left(\frac{8}{2}\right)^{th}\\
& & \\ 
& & \hspace{1cm} \textrm{\sf and the } \left(\frac{8}{2} +1\right)^{th} \text{\sf largest
observations}\\ \pause
& & \\
&=& \frac{5 + 6}{2}\\
& & \\
&=& 5.5.
\end{eqnarray*}
}


\frame{
\frametitle{3.5.2 The Median}
\noindent It is possible to estimate the median value from an \textcolor{purple}{\bf ogive} as it is
half way through the ordered data and hence is at the 50\% level of
the cumulative frequency. \pause

\vsp

The accuracy of this estimate will depend on
the accuracy of the ogive drawn.
}



\frame{
\frametitle{3.5.2 The Mode}

\noindent This is the final measure of location we will look at. 

\vsp

It is the value of the random variable in the sample which \textcolor{purple}{\bf occurs with the highest frequency}.

\vsp

 It is usually found by inspection (no formula).   

}

\frame{
\frametitle{3.5.2 The Mode}
For discrete data this is easy -- the mode is simply the most common value. 

\vsp

So, on a bar chart, it would be the category with the \textcolor{purple}{\bf highest bar}. \pause

\vsp

For example, consider the
following data: \pause

\begin{center}
\textcolor{brown}{\bf 2}, \textcolor{brown}{\bf 2}, \textcolor{brown}{\bf 2}, \textcolor{brown}{\bf 3}, \textcolor{brown}{\bf 3}, \textcolor{brown}{\bf 4}, \textcolor{brown}{\bf 5}.\pause
\end{center}

Quite obviously the mode is 2 as it
occurs most often.
}

\frame{
\frametitle{3.5.2 The Mode}
\noindent It is possible to refer to \textcolor{purple}{\bf modal classes} with grouped data. 

\vsp

This is
simply the class with the greatest frequency of observations. \pause

\vsp
For
example, the model class of 
\begin{center}
\begin{tabular}{|c|c|}
\hline
\textbf{Class} & \textbf{Frequency}\\
\hline
$10 \leq x < 20$ & 10\\
$20 \leq x < 30$ & 15\\
$30 \leq x < 40$ & 30\\
\hline
\end{tabular}
\end{center}
is obviously $30 \leq x < 40$. 
}

\frame{
\frametitle{3.5.3 Measures of Spread}

\noindent A measure of location is insufficient in itself to summarise data as
it only describes the value of a \textcolor{purple}{\bf typical outcome} and not how much
\textcolor{purple}{\bf variation} there is in the data. For example:
\begin{center}
\begin{tabular}{c|c c c}
\textbf{Dataset 1} &\textcolor{brown}{\bf 6}  & \textcolor{brown}{\bf 22} &\textcolor{brown}{\bf 38} \\
\textbf{Dataset 2} &\textcolor{brown}{\bf 21} &\textcolor{brown}{\bf 22} &\textcolor{brown}{\bf 23}\end{tabular}
\end{center} \pause 

\vspl

For both of these datasets, $\bar{x}=\textsf{median}=22$.  However,\pause

\vspl

\begin{itemize}
\item dataset 1 ranges considerably from these average values; \pause
\vspl
\item dataset 2 is very tightly concentrated around these averages.
\end{itemize} 
}

\frame{
\frametitle{3.5.3 Measures of Spread}
 The mean or the median does not fully represent
the data. \pause

\vsp

There are three basic \textcolor{purple}{\bf measures of spread} which we will
consider: \pause

\vsp

\begin{itemize}
\item the \textcolor{purple}{\bf range} \pause
\vspl 
\item the \textcolor{purple}{\bf inter--quartile range}, and \pause
\vspl
\item the \textcolor{purple}{\bf sample variance}/\textcolor{purple}{\bf standard deviation}.
\end{itemize}
}

\frame{
\frametitle{3.5.3 The Range}

\noindent This is the \textcolor{purple}{\bf simplest measure of spread}.\pause

\vsp

 It is simply the difference between the largest and smallest observations. \pause

\vsp

In our simple example above: \pause
\begin{eqnarray*}
\textsf{Range for dataset 1} &=&38 - 6 = 32 \pause \\
& & \\
\textsf{Range for dataset 2} &=&23 - 21 = 2
\end{eqnarray*} \pause
 These clearly describe very different data sets. The first set has a much wider range (data more spread out) than the second. 
}

\frame{
\frametitle{3.5.3 The Range}
\noindent There are two problems with the range as a measure of spread. \pause

\vsp

\begin{itemize}
\item Uses the two most extreme data points -- value can be unduly influenced by one particularly large/small value (\textcolor{purple}{\bf outliers})   \pause

\vspl

\item Only suitable for comparing (roughly) equally--sized samples
\end{itemize}
}


\frame{
\frametitle{3.5.3 The Inter--Quartile Range}

\noindent The inter--quartile range describes the range of the \textcolor{purple}{\bf middle half of the
data} and so is less prone to the influence of the extreme values. \pause

\vsp

\noindent To calculate the inter--quartile range (IQR) we simply divide the the
ordered data into \textcolor{purple}{\bf four quarters}.\pause

\vsp

 The three values that split the data into these quarters are called the \textcolor{purple}{\bf quartiles}. }


\frame{
\frametitle{3.5.3 The Inter--Quartile Range}
\begin{itemize}
\item The first quartile (\textcolor{purple}{\bf lower quartile}, $Q1$) has 25\% of the data below it \pause
\vspl
\item The second quartile (\textcolor{purple}{\bf median}, $Q2$) has 50\% of the data below it \pause
\vspl
\item The third quartile (\textcolor{purple}{\bf upper quartile}, $Q3$) has 75\% of the data below it. \pause
\end{itemize}}

\frame{
\frametitle{3.5.3 The Inter--Quartile Range}
We already know how to find the
median, and the other quartiles are calculated as follows: \pause
\begin{eqnarray*}
Q1 &=& \frac{(n+1)}{4}\text{th}\text{ \sf smallest observation}\\
& & \\
Q3 &=& \frac{3(n+1)}{4}\text{th}\text{ \sf smallest observation}.
\end{eqnarray*} \pause
\noindent Just as with the median, these quartiles might not correspond to
actual observations. 

\vsp

For example, in a dataset with $n=20$ values, the
lower quartile is the 
\[
\frac{21}{4} = 5\,\frac{1}{4}^{\sf th} \textsf{ largest observation,}
\]
that is, a quarter of the way between the 5th and 6th largest
observations.}

\frame{
\frametitle{3.5.3 The Inter--Quartile Range}
Consider again the data $(n=20)$: \pause
\begin{center}
\begin{tabular}{rrrrrrrrrr}
8.4 & 8.7 & 9.0 & 9.0 & 9.2 & 9.3 & 9.3 & 9.5 & 9.6 & 9.6 \\ 
9.6 & 9.7 & 9.7 & 9.9 & 10.3 & 10.4 & 10.5 & 10.7 & 10.8 & 11.4
\end{tabular}
\end{center}
\noindent Here the 5th and 6th smallest observations are 9.2 and 9.3
respectively. Therefore, the lower quartile is $Q1=9.225$. \pause

\vsp

Similarly, the upper quartile is the 
\[
\frac{3 \times 21}{4}=15\frac{3}{4}^{\sf th} \textsf{ smallest observation,}
\]
that is, three quarters of the way between 10.3 and 10.4; so $Q3=10.375$.
}

\frame{
\frametitle{3.5.3 The Inter--Quartile Range}
\noindent The inter--quartile range is simply the difference between the upper
and lower quartiles, that is \pause
\begin{eqnarray*}
IQR &=& Q3 - Q1 \\
 & & \\
 &=&10.375-9.225 \\
 & & \\
&=&1.15.
\end{eqnarray*}
}

\frame{
\frametitle{3.5.3 The Inter--Quartile Range}
\noindent The interquartile range can also be \emph{estimated} from the ogives
in a similar manner to the median. \pause

\vsp

Simply draw the ogive and then read
off the values for 75\% and 25\% and calculate the difference between
them. This is especially useful if you only have grouped data. 

\vsp

Again
the accuracy depends on the quality of your graph. \pause

\vsp

\noindent The inter--quartile range is useful as it allows us to make
comparisons between the ranges of two data sets, without the problems
caused by \textcolor{purple}{\bf outliers} or \textcolor{purple}{\bf unequal sample sizes}.
}


\frame{
\frametitle{3.5.3 The Sample Variance and Standard Deviation}

\noindent The \textcolor{purple}{\bf sample variance} is the standard measure of spread used in statistics. 

\vsp

It is usually denoted by $s^2$ and is simply the ``average'' of the squared distances of the observations from the sample mean. \pause

\vsp

We use the formula \pause
\[
s^2 = \frac{\left( x_1 - \bar x \right)^2 + \left( x_2-\bar x
\right)^2 + \ldots + \left( x_n - \bar x \right)^2}{n-1};
\]\pause
the $(n-1)$ divisor will be explained in semester 2. 
}

\frame{
\frametitle{3.5.3 The Sample Variance and Standard Deviation}
\noindent We can rewrite this using more condensed mathematical notation: \pause
\begin{align*}
s^2 &= \frac{1}{n-1} \sum_{i=1}^n \left(x_i - \bar x \right)^2,\\
\intertext{\sf or equivalently as} \\
s^2 &= \frac{1}{n-1}\left\{ \sum_{i=1}^n x_i^2 - n \left(\bar x
\right)^2 \right\}.
\end{align*} \pause
\noindent Note that the notation $x_i^2$ represents the squared value of the
observation $x_i.$ That is, $x_i^2=(x_i)^2$. \pause

\vsp

\noindent The \textcolor{purple}{\bf sample standard deviation} $s$ is the positive square root of the sample variance. }

\frame{
\frametitle{3.5.3 The Sample Variance and Standard Deviation}

\noindent A different calculation is needed when the data are given in the form
of a grouped frequency table with frequencies ($f_i$) in intervals
with mid--points ($m_i$). \pause

\vsp

First the sample mean $\bar x$ is approximated
(as described earlier) and then the sample variance is approximated as
\[
s^2 = \frac{1}{n-1}\left\{ \sum_{i=1}^k f_i m_i^2 - n \left(\bar x
\right)^2 \right\}.
\]
}


\frame{
\frametitle{Example 3.6}
Consider again the data
\begin{center}
\begin{tabular}{rrrrrrrrrr}
8.4 & 8.7 & 9.0 & 9.0 & 9.2 & 9.3 & 9.3 & 9.5 & 9.6 & 9.6 \\ 
9.6 & 9.7 & 9.7 & 9.9 & 10.3 & 10.4 & 10.5 & 10.7 & 10.8 & 11.4
\end{tabular}
\end{center}
Calculate the sample variance and hence the sample standard deviation.  
}

\sol

\frame{
\frametitle{Example 3.6: Solution (1/2)}
The \textcolor{purple}{\bf sample mean} is
\[
\bar{x} = 9.73.
\]\pause
If we use the second version of the formula
\[
s^2 = \frac{1}{n-1}\left\{ \sum_{i=1}^n x_i^2 - n \left(\bar x
\right)^2 \right\},
\]
we also need $\sum x^{2}$, which is:
\[
8.4^{2}+8.7^{2}+9.0^{2} + \ldots + 11.4^{2} = 1904.38.
\]
}
\frame{
\frametitle{Example 3.6: Solution (2/2)}
So \pause
\begin{eqnarray*}
s^2 &=& \frac{1}{\textcolor{blue}{\bf 20}-1}\left\{\textcolor{blue}{\bf 1904.38} - \textcolor{blue}{\bf 20} \left(\textcolor{blue}{\bf 9.73}\right)^2 \right\} \\
  & & \\
     &=& 0.5748.
\end{eqnarray*} \pause

The standard deviation is just the square root of this, i.e. \pause
\[
s = \sqrt{0.5748} = 0.7582.
\]
}


\normal

\frame{
\frametitle{3.5.4 Box--and--whisker plots}
\noindent Box and whisker plots are another graphical method for displaying data
and are particularly useful in highlighting differences between
groups. \pause

\vsp

These plots use some of the key summary statistics we have looked at
earlier -- the \textcolor{purple}{\bf quartiles} -- and also the \textcolor{purple}{\bf maximum} and \textcolor{purple}{\bf minimum} observations.
}

\frame{
\frametitle{3.5.4 Box--and--whisker plots}
\noindent The plot is constructed as follows: \pause

\vsp

\begin{itemize}
\item  Lay out an $x$--axis for the full range of the data \pause
\vspl
\item Draw a rectangle with ends at the the upper and lower quartiles\pause
\vspl
\item  Split the rectangle into two at the median: You now have the ``\textcolor{purple}{\bf box}'' \pause
\vspl
\item Finally, draw lines from the box to
the minimum and maximum values -- these are the ``\textcolor{purple}{\bf whiskers}''
\end{itemize}
}

\frame{
\frametitle{Example 3.7}
\noindent Suppose that, from our data, we obtain the following summary statistics:
\begin{center}
\begin{tabular}{l c l}
Minimum & & $min=10$\\
Lower quartile & & $Q1=40$\\
Median & & $Q2=43$\\
Upper quartile & & $Q3=45$\\
Maximum & & $max=50$
\end{tabular}
\end{center}
\noindent Complete the associated box--and--whisker plot, and comment. 
}

\frame{
\frametitle{Example 3.7: Solution}

\begin{center}
\includegraphics[width=8cm,angle=-90]{box1.ps}
\end{center}
}

\sol
\frame{
\frametitle{Example 3.7: Solution}

\begin{center}
\includegraphics[width=8cm,angle=-90]{box2.ps}
\end{center}
}

\frame{
\frametitle{Example 3.7: Solution}

\begin{center}
\includegraphics[width=8cm,angle=-90]{box3.ps}
\end{center}
}


\frame{
\frametitle{Example 3.7: Solution}

\begin{center}
\includegraphics[width=8cm,angle=-90]{box4.ps}
\end{center}

}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\normal


\frame{
\frametitle{Announcements}
\begin{itemize}
\item \textbf{CBA 2:} \pause

\vspl

\begin{itemize}

\item [--] Now live in practice mode \pause

\vspl

\item [--] Assessed mode opens on Monday \pause

\vspl

\item [--] Deadline: \textbf{23:59, Sunday 20th December} \pause

\vspl

\item [--] Some questions relate to material in chapter 4  
\end{itemize} \pause

\vsp

\item \textbf{Prize question winners:} Apex Tshisekedi, Arjun Jain, Rahil Gandhi, Zhong Tong Tong, Mingrui Li, Sarah Koullapi, Sharon Tan! And Abigail Farnworth from last time...

\end{itemize}
}

\frame{
\frametitle{Announcements}
\begin{itemize}
\item Case study 2: \pause

\vspl

\begin{itemize}
\item [--] Due in by \textbf{4pm, Friday 15th January} -- hand-in arrangements as before...\pause

\vspl

\item [--]After today's lecture, \textit{should} be OK to complete \underline{\textit{most}} of the work \pause

\vspl

\item [--]Assessed questions in next week's workshops \pause

\vspl

\item [--] Graphical summaries: be selective!  Use the most appropriate graph for the data.  \textbf{Must be hand-drawn!} \pause

\vspl

\item [--] Numerical summaries: usually \textbf{one} measure of average AND \textbf{one} measure of spread for each dataset: be selective! \pause

\vspl

\item [--] Comments: shape of the distribution (symmetric/asymmetric); outliers; comparisons between groups (percentage scale for graphs?) \pause 

\vspl

\item [--] Two pages - graphs separate (in an Appendix at the end, correctly referenced)

\end{itemize}
\end{itemize}
}
%\end{comment}

\normal
\frame{

\vspace{1cm}

\huge
\textbf{Chapter 4}

\vspace{1cm}

\Large
\textbf{Probability}

}

\frame{
\frametitle{What we'll cover...}
\begin{itemize}
\item \textcolor{purple}{\bf Definitions}: Experiments, outcomes, sample space... \pause
\vspl
\item \textcolor{purple}{\bf Interpretations} of probability: \textit{Classical}, \textit{Frequentist}, \textit{Bayesian} \pause
\vspl
\item \textcolor{purple}{\bf Laws} of probability \pause
\vspl
\item Probability \textcolor{purple}{\bf trees} \pause
\vspl
\item The \textcolor{purple}{\bf binomial} distribution \pause
\vspl
\item The \textcolor{purple}{\bf Poisson} distribution
\end{itemize}
}

\normal

\frame{
\frametitle{4. Probability}

\noindent \textcolor{purple}{\bf Probability} is the language we use to model uncertainty. \pause
\vspl
\begin{itemize}
\item Few things in life are certain \pause
\vspl
\item Usually an element of uncertainty around outcomes of our choices \pause
\vspl
\item This can make all the difference between a good investment and a poor one! \pause
\vspl
\item Hence the importance of probability!
\end{itemize}
}


\frame{
\frametitle{4.1 Definitions}

\vsp

\noindent We often use the letter $P$ to represent a probability. \pause For example, $P(Rain)$ would be the probability that it rains.   \pause

\vsp

An \textcolor{purple}{\bf Experiment} is an activity where we do not know for certain what will happen, but we will \textit{observe} what happens. For example: \pause
\begin{itemize}
\item We will ask someone whether or not they have used our product. \pause
\item We will observe the temperature at midday tomorrow. \pause
\item We will toss a coin and observe whether it shows ``heads'' or ``tails''.
\end{itemize}
}

\frame{
\frametitle{4.1 Definitions}
An \textcolor{purple}{\bf outcome}, or \textcolor{purple}{\bf elementary event}, is one of the possible things that can happen. \pause

\vsp

For example, suppose that we are interested in the (UK) shoe size of the next customer to come into a shoe shop. Possible outcomes: \pause
\vspl
\begin{itemize}
\item  ``eight''
\item ``twelve'' 
\item ``nine and a half'' 
\end{itemize}

\vspl

In any experiment, \textbf{one}, \textbf{and only one}, outcome occurs.
}

\frame{
\frametitle{4.1 Definitions}
The \textcolor{purple}{\bf sample space} is the set of all possible outcomes. For example, it could be the set of all shoe sizes. \pause

\vspace{0.5cm}

An \textcolor{purple}{\bf event} is a set of outcomes. \pause

\vsp

For example ``the shoe size of the next customer is less than 9'' is an event. 

\vsp

It is made up of all of the outcomes where the shoe size is less than 9.
}


\frame{
\frametitle{4.1 Definitions}
\noindent Probabilities are usually expressed in terms of fractions or decimal
numbers or percentages. 

\vsp

Therefore we could express the probability of it raining today as
\[
P(\textrm{\sf Rain}) = \frac{1}{20} = 0.05 = 5\%.
\] \pause

\noindent All probabilities are measured on a scale ranging from \textcolor{purple}{\bf 0} $\rightarrow$ \textcolor{purple}{\bf 1}. 
\vspl
\begin{itemize}
\item An event with probability zero is an \textcolor{purple}{\bf impossible} event \pause
\vspl
\item An event with probability one is a \textcolor{purple}{\bf certain} event. \pause

\vspl
\item The collection of all possible outcomes, that is the \textcolor{purple}{\bf sample space}, has a probability of 1. 

\vspl

For example, if an event consists of only two outcomes -- \textit{success} or
\textit{failure} -- then $P(success\text{ or }failure)=1$.
\end{itemize}
}


\frame{
\frametitle{4.1 Definitions}
\noindent Two events are said to be \textcolor{purple}{\bf mutually exclusive} if both cannot
occur simultaneously: \pause In the example above, the outcomes
\textit{success} and \textit{failure} are mutually exclusive. \pause

\vsp

\noindent Two events are said to be \textcolor{purple}{\bf independent} if the occurrence of one does not affect the probability of the second occurring. \pause

\vsp

For example, if you toss a coin and look out of the window, it would be reasonable to suppose that the events ``get heads'' and ``it is raining'' would be independent.}




\frame{
\frametitle{4.2 How do we measure Probability?}

\noindent There are three main ways in which we can measure probability: \pause
\vspl
\begin{itemize}
\item The \textcolor{purple}{\bf classical} interpretation \pause
\vspl
\item The \textcolor{purple}{\bf frequentist} interpretation \pause
\vspl
\item The \textcolor{purple}{\bf subjective} or \textcolor{purple}{\bf Bayesian} inteperetation
\end{itemize} \pause

\vsp

All three obey the basic rules described above. 

\vsp

Different people argue in favour of the different views of probability and some will argue that each kind has its uses depending on the circumstances.
}

\frame{
\frametitle{4.2.1 The classical interpretation}

\noindent If all possible outcomes are ``\textcolor{purple}{\bf equally likely}'' then we can adopt the
\textcolor{purple}{\bf classical} approach to measuring probability. \pause

\vsp

For example, if we tossed a fair coin, there are only two possible outcomes -- a head or a
tail -- both of which are equally likely, and hence \pause
\[
P(Head)=\frac{1}{2}\quad\text{\sf and}\quad
P(Tail)=\frac{1}{2}.
\]
}

\frame{
\frametitle{4.2.1 The classical interpretation}
\noindent The underlying idea behind this view of probability is
\textcolor{purple}{\bf symmetry}. \pause

\vsp

In this example, there is no reason to think that
the outcome \textit{Head} and the outcome \textit{Tail} have different
probabilities and so they should have the same probability. \pause

\vsp

Since there are two outcomes and one of them must occur, both outcomes must
have probability 1/2. \pause

\vsp

\noindent Generally,
\[
P(\textsf{\sf Event})=\frac{\textsf{\sf Total number of outcomes in which event occurs}}{\textrm{\sf Total number of possible outcomes}}.
\]
}




%\frame{
%\frametitle{4.2.1 The classical interpretation}
%\noindent Another commonly--used example is rolling dice. 
%
%\vsp%
%
%There are six possible
%outcomes (1, 2, 3, 4, 5, 6) when a die is rolled and each of them should have an equal chance of
%occurring. \pause
%
%\vsp
%
%Hence 
%\[
%P(1) = \frac{1}{6}, P(2) = \frac{1}{6}, \ldots~.  \pause
%\]
%\pause
%
%\noindent Other calculations can be made such as \pause
%\[
%P(\textrm{\sf Even Number}) = \frac{3}{6} = \frac{1}{2}. \pause
%\]
%This follows from the formula \pause
%\[
%P(\textrm{\sf Event})=\frac{\textrm{\sf Total number of outcomes in which event occurs}}{\textrm{\sf Total number of possible outcomes}}.
%\]
%}

%\noindent Note that this formula only works when all possible events are equally
%likely -- not a practical assumption for most real life situations.

\frame{
\frametitle{4.2.2 The frequentist interpretation}
When the outcomes of an experiment are \textbf{not} equally likely, we can
\textcolor{purple}{\bf conduct experiments} to give us some idea of how likely the different outcomes are. \pause

\vsp

 For example, suppose we were interested in
measuring the probability of producing a defective item in a manufacturing
process. \pause

\vspl
\begin{itemize}
\item Monitor the process over a long period \pause
\vspl
\item Calculate the proportion of defective items \pause
\end{itemize}

\vspl

\textbf{What constitutes a ``long period of time''?} \pause

\vspl

Generally, 
\[
P(\textrm{\sf Event})=\frac{\textrm{\sf Number of times an event
occurs}}{\textrm{\sf Total number of times experiment done}}.
\] 

}


%\frame{
%\frametitle{4.2.2 The frequentist interpretation}
% In a more simple case, if we
%did not believe that a coin was fair, we could toss the coin a large
%number of times and see how often we obtained a head. \pause
%
%\vsp
%
%In both cases we
%perform the same experiment a large number of times and observe the
%outcome. \pause
%
%\vsp
%
%This is the basis of the \textcolor{purple}{\bf frequentist} view. \pause
%
%\vsp
%
%By conducting experiments, the probability of an event can easily be
%estimated using the following formula: \pause
%\[
%P(\textrm{\sf Event})=\frac{\textrm{\sf Number of times an event
%occurs}}{\textrm{\sf Total number of times experiment done}}.
%\] \pause
%
%\noindent The larger the experiment, the closer this probability is to the
%``true'' probability. 
%}


%\frame{
%\frametitle{4.2.2 The frequentist interpretation}
%\begin{itemize}
%\item Probability is a ``property of nature'' \pause
%\vspl
%\item In practice, we cannot conduct \textcolor{purple}{\bf infinite} sequences of trials... \pause
%\vspl
%\item ... therefore, we never really know the ``true'' values of probabilities \pause
%\vspl
%\item We have to be able to imagine a long sequence of \textcolor{purple}{\bf identical trials}... \pause
%\vspl
%\item ... not appropriate for \textcolor{purple}{\bf one--off} experiments like the launch of a new product.
%\end{itemize}
%}

\frame{
\frametitle{4.2.3 The Subjective/Bayesian interpretation}

We are probably all intuitively familiar with this method of assigning probabilities: \pause
\vspl
\begin{itemize}
\item When we board a plane, we judge the probability of it
crashing to be sufficiently small that we are happy to undertake the
journey. \pause
\vspl
\item Similarly, the odds given by bookmakers on a horse race reflect
people's beliefs about which horse will win. 
\end{itemize} \pause
\vspl
This probability does not fit within the frequentist definition as the same race cannot be run a large number of times. 
}

%\frame{
%\frametitle{4.2.3 The Subjective/Bayesian interpretation}
%\noindent One potential difficulty with using subjective probabilities is that it {\em is} subjective.  \pause
%
%\vsp
%
%So the probabilities which two people assign to the same event can be different. \pause
%
%\vsp
%
%This becomes important if these probabilities are to be used in decision
%making.  For example: \pause
%\vspl
%\begin{itemize}
%\item  Should we launch a new product? \pause
%\vspl
%\item Two people have very different ideas about how likely success/failure will be \pause
%\vspl
%\item Decision to go ahead is controversial! \pause
%\vspl
%\item Need a way to reconcile these differences!
%\end{itemize} 
%}

%\frame{
%\frametitle{4.2.3 The Subjective/Bayesian interpretation}
% Subjective probability is still subject to the same rules as the other
%forms of probability: \pause
%\vspl
%\begin{itemize}
%\item All probabilities $\geq 0$ \pause
%\vspl
%\item The probability of all outcomes should sum to one
%\end{itemize}
%}

\frame{
\frametitle{Example 4.1}
\noindent  A fast--food chain with 700 outlets describes the geographic location of its restaurants with the following table:
{\small
\begin{center}
\begin{tabular}{c c |c c c c} 
	&		&\multicolumn{4}{c}{\textbf{Region}}	\\ 
	&		&NE		&SE		&SW		&NW		\\ \hline
	&Under 10,000	&35		&42		&21		&70		\\
\textbf{Population}&10,000--100,000&70		&105		&84		&35		\\
	&Over 100,000	&175		&28		&35		&0		\\ \hline
\end{tabular}
\end{center}  }   
\noindent A health and safety organisation selects a restaurant at random for a hygiene inspection.  
\begin{itemize}
\item [\textbf{(a)}] Which of the three approaches to probability would you use to find:
\begin{itemize}
\item [(i)]  $P(\textrm{\sf NE restaurant chosen})$,
%\item [(ii)] $P(\textrm{\sf Restaurant chosen from a city with a population $>$ 100,000})$, and
\item [(ii)]$P(\textrm{\sf SW and city with a population $<$ 100,000})$?
\end{itemize}
\item [\textbf{(b)}] Now use this approach to find the probabilities given above.  
\end{itemize}
}

\sol
\frame{
\frametitle{Example 4.1: Solution to part (a)}
A restaurant is chosen at random -- all outcomes are equally likely -- so \textbf{classical}.
  
\pause

\vsp



\textit{[Not that important, really...]}
}

\frame{
\frametitle{Example 4.1: Solution to part (b)(i)}
{\small
\begin{center}
\begin{tabular}{c c |c c c c} 
	&		&\multicolumn{4}{c}{\textbf{Region}}	\\ 
	&		&NE		&SE		&SW		&NW		\\ \hline
	&Under 10,000	&35		&42		&21		&70		\\
\textbf{Population}&10,000--100,000&70		&105		&84		&35		\\
	&Over 100,000	&175		&28		&35		&0		\\ \hline
\end{tabular}
\end{center}  }   

\begin{eqnarray*}
P(\textsf{NE restaurant chosen})  &=& \pause \frac{35+70+175}{700} \pause \\
   & & \\
                   &=& \frac{280}{700}  \\
 & & \\
 &=& 0.4
\end{eqnarray*}
}

\frame{
\frametitle{Example 4.1: Solution to part (b)(ii)}
{\small
\begin{center}
\begin{tabular}{c c |c c c c} 
	&		&\multicolumn{4}{c}{\textbf{Region}}	\\ 
	&		&NE		&SE		&SW		&NW		\\ \hline
	&Under 10,000	&35		&42		&21		&70		\\
\textbf{Population}&10,000--100,000&70		&105		&84		&35		\\
	&Over 100,000	&175		&28		&35		&0		\\ \hline
\end{tabular}
\end{center}  }  
\begin{eqnarray*}
P(\textrm{\sf SW and city with a population $<$ 100,000})  &=& \pause \frac{21+84}{700} \pause \\
 & & \\
&=& \frac{105}{700} \\ \pause
 & & \\
 &=&0.15
\end{eqnarray*}
}

\normal

%\frame{
%\frametitle{Another example}
%The spinner shown below is spun once.  
%\begin{center}
%\includegraphics[width=7cm]{spinner.ps}
%\end{center}
%}

%\frame{
%\frametitle{Another example}
%\begin{itemize}
%\item [(a)] Which of the three approaches to probability would you use to find:
%\begin{itemize}
%\item [(i)] $P(\textrm{\sf lands red})$,
%\item [(ii)] $P(\textrm{\sf lands triangle})$, and
%\item [(iii)] $P(\textrm{\sf lands quadrilateral})$?
%\end{itemize}
%\item [(b)] Now use this approach to find the probabilities given above.  
%\end{itemize}
%}

%\sol

%\frame{
%\frametitle{Solution to part (a)}
%We can use the \pause
%\begin{center}
%\huge
%\textbf{Classical} approach
%\end{center}
%\normalsize
%to probability since all outcomes are equally likely.
%}

%\frame{
%\frametitle{Solution to part (b)}
%\includegraphics[width=4cm]{spinner.ps}
%
%\begin{eqnarray*}
%P(\textsf{lands red}) &=& \frac{1}{6} \\ \pause
%& & \\
%P(\textsf{lands triangle}) &=& \frac{1}{6} \\ \pause
%& & \\
%P(\textsf{lands quadrilateral}) &=& \frac{4}{6} = \frac{2}{3}
%\end{eqnarray*}
%}

\normal


%\frame{
%\frametitle{Another example!}
%
%\noindent On the probability scale, how likely do you think it is that Newcastle United will finish in a top--six position this season?  Which approach to probability would you use to estimate this?
%}


%\normal

\frame{
\frametitle{4.3.1 Laws of Probability: Multiplication law}


The probability of two \textcolor{purple}{\bf independent} events $E_1$ and $E_2$ both occurring can be written as
\[
P(E_1 \text{ \textbf{and} } E_2) = P(E_1) \times P(E_2),
\]\pause
\noindent and this is known as the \textcolor{purple}{\bf multiplication law} of probability.  \pause

\vsp

For example, the probability of throwing a six followed by
another six on two rolls of a die is calculated as follows:\pause
\vspl
\begin{itemize}
\item The outcomes of the two rolls of the die are \textcolor{purple}{\bf independent} \pause
\vspl
\item Let $E_1$ denote a six on the first roll and $E_2$ a six on the second roll. \pause
\vspl
\item \begin{eqnarray*}
P(\text{\sf two sixes})&=&P(E_1 \text{ \sf and } E_2) \\ \pause
&=& P(E_1) \times P(E_2) \\ \pause
&=& \frac{1}{6} \times  \frac{1}{6} =\frac{1}{36}.
\end{eqnarray*}
\end{itemize}
}

%\frame{
%\frametitle{4.3.1 Laws of Probability: Multiplication law}
%\noindent This method of calculating probabilities extends to when there are
%many \textcolor{purple}{\bf independent} events: \pause
%\[
%P(E_1\text{ and } E_2 \text{ and }\cdots\text{ and } E_n)
%=P(E_1)\times P(E_2)\times\cdots\times P(E_n).
%\] }

\frame{
\frametitle{4.3.2 Laws of probability: Addition Law}
The multiplication law is concerned with the probability of two or
more independent events occurring. \pause

\vsp

The \textcolor{purple}{\bf addition law} describes
the probability of any of two \textbf{or} more events occurring. \pause

\vsp

The addition
law for two events $E_1$ and $E_2$ is
\[
P(E_1\text{ \textbf{or} }E_2)=P(E_1)+P(E_2)-P(E_1\text{ and }E_2).
\]
This describes the probability of \textit{either} event $E_1$
\textit{or} event $E_2$ happening. 
}


%\frame{
%\frametitle{Example 4.2}
%\noindent Consider the following information: \pause
%\vspl
%\begin{itemize}
%\item 50 percent of families in a city subscribe to the morning newspaper
%\vspl
%\item 65 percent subscribe to the afternoon newspaper 
%\vspl
%\item 30 percent of the families subscribe to \textbf{both} newspapers 
%\end{itemize} \pause
%\vsp

%What proportion of families subscribe to at least one newspaper?
%}

%\frame{
%\frametitle{Example 4.2: Solution}
%\noindent We are told $P(\text{\sf Morning})=0.5$, $P(\text{\sf Afternoon})=0.65$ and $P(\text{Morning and Afternoon})=0.3$. \pause
%
%\vsp
%We could show this information on a \textcolor{purple}{\bf Venn diagram}: \pause
%
%
%\begin{center}
%\includegraphics[width=7cm,angle=-90]{venn.ps}
%\end{center} \pause
%
%Clearly, 
%\[
%P(\text{\sf at least one paper})=P(\text{\sf Morning or Afternoon}) = 0.85.
%\]
%}


%\frame{
%\frametitle{Example 4.2: Solution}
%Also, using the \textcolor{purple}{\bf addition law}: 
%\begin{eqnarray*}
%P(\text{\sf at least one paper})&=&P(\text{\sf Morning or Afternoon})\\
%& &\\ 
%&=&P(\text{\sf Morning})+P(\text{\sf Afternoon})\\
%  & &-P(\text{\sf Morning and Afternoon})\\
%& &\\
%&=& 0.5+0.65-0.3\\
%&=& 0.85.
%\end{eqnarray*}
%}

\frame{
\frametitle{4.3.2 Laws of probability: Addition Law}
\noindent A more basic version of the rule works where events are \textcolor{purple}{\bf mutually exclusive}. \pause

\vsp

If events $E_1$ and $E_2$ are mutually exclusive then
\[
P(E_1\text{ or }E_2)=P(E_1)+P(E_2).
\] 
This simplification occurs because when two events are mutually
exclusive they cannot happen together and so $P(E_1\text{ \sf and
}E_2)=0$.
}

%\frame{
%\frametitle{4.4 Tree Diagrams}
%\noindent \textcolor{purple}{\bf Tree diagrams} or \textcolor{purple}{\bf probability trees} are simple clear ways of presenting
%probabilistic information. \pause
%
%\vsp
%
%Let us first consider a simple example in which a die is rolled twice. \pause
%
%\vsp
%
%Suppose we are interested in the probability that we score
%a six on both rolls. }



%frame{
%\frametitle{4.4 Tree Diagrams}
%This probability can be calculated as
%\begin{eqnarray*}
%P(\text{ \sf Six and Six})&=&P(\text{ \sf Six on 1st throw})\times P(\text{ \sf Six on 2nd throw})\\
%& & \\
%&=&\frac{1}{6}\times \frac{1}{6}\\
%& & \\
%&=&\frac{1}{36}.
%\end{eqnarray*} 
%}

\frame{
\frametitle{4.4 Tree Diagrams}
\noindent This example can be represented as a tree diagram in which experiments are represented by circles (called \textcolor{purple}{\bf nodes}) and the outcomes of the experiments as \textcolor{purple}{\bf branches}: \pause

\begin{center}
\includegraphics[width=8cm,height=5cm]{probtree-coin.eps}
\end{center}
}

\frame{
\frametitle{Example 4.3}

A machine is used to produce components. Each time it produces a component there is a chance that the component will be defective. 

\vsp

When the machine is working correctly the probability that a component is defective is 0.05. Sometimes, though, the machine requires adjustment and, when this is the case, the probability that a component is defective is 0.2. 

\vsp

At the time in question there is a probability of 0.1 that the machine requires adjustment. 

}

\sol
\frame{
\frametitle{Solution to Example 4.3}
\begin{center}
\includegraphics[width=11.7cm]{tree1.eps}
\end{center}
}

\frame{
\frametitle{Solution to Example 4.3}
\begin{center}
\includegraphics[width=11.7cm]{tree2.eps}
\end{center}
}

\frame{
\frametitle{Solution to Example 4.3}
\begin{center}
\includegraphics[width=11.7cm]{tree3.eps}
\end{center}
}

\normal
\frame{
\frametitle{Example 4.3}
Components produced by the machine are tested and either accepted or rejected.  A component which is not defective is accepted with probability 0.97 or (falsely) rejected with probability 0.03.  

\vsp

A defective component is (falsely) accepted with probability 0.15 and rejected with probability 0.85.
}

\sol

\frame{
\frametitle{Solution to Example 4.3}
\begin{center}
\includegraphics[width=11.7cm]{tree4.eps}
\end{center}
}

\frame{
\frametitle{Solution to Example 4.3}
\begin{center}
\includegraphics[width=11.7cm]{tree5.eps}
\end{center}
}



\announce
\frame{
\frametitle{Welcome back!}
\begin{itemize}
\item \textbf{My name:}  Lee Fawcett \pause

\vspl

\item \textbf{Where you can find me:} 2.07, 2nd floor Herschel \pause

\vspl

\item \textbf{What I do:} Teach Stats \pause

\vspl

\item \textbf{This semester:} \pause

\vspl

\begin{itemize}
\item [--] Lecture every Friday, 12--1, Herschel LT1 \pause

\vspl

\item [--] Workshops the following week -- new days/times!  \pause

\vspl

\item [--] All compulsory; bring your notes, stationary and calculators! \pause

\vspl

\item [--] Four assignments: Two CBAs, one case study and one computing assignment using Minitab \pause

\vspl

\item [--] See webpage: \texttt{www.mas.ncl.ac.uk/$\sim$nlf8/teaching/acc1012}

\end{itemize}
\end{itemize}
}



\normal

\frame{
\frametitle{4.5 The binomial distribution}
Suppose we are interested in the \textcolor{purple}{\bf number of sixes} we get from 3 rolls of a die.  

\vsp

Each roll of the die is an experiment or  trial
which gives a ``\textcolor{purple}{\bf six}'' (success, or $\textcolor{orange}{\it s}$) or ``\textcolor{purple}{\bf not a six}'' (failure, or $\textcolor{blue}{\it f}$). 

\vsp

The probability of a success is $p=P(\textrm{\sf six})=1/6$. 

\vsp

We have $n=3$ \textcolor{purple}{\bf independent} experiments or trials (rolls of the die). 
}

\frame{
\frametitle{4.5 The binomial distribution}
Let $X$ be the number of sixes obtained.  \pause

\vsp

We can now obtain the full \textcolor{purple}{\bf probability distribution} of $X$; \pause a probability distribution is a list of all the possible outcomes for $X$ with along with their associated probabilities.  
}


\frame{
\frametitle{4.5 The binomial distribution}
\noindent For example, suppose we want to work out the probability of obtaining \textbf{three} sixes: (three ``\textcolor{purple}{\bf successes}'' --- i.e. $\textcolor{orange}{\it sss}$ --- or $P(X=3)$).  \pause

\vsp

Since the rolls of the die can be considered independent, we get (using the \textcolor{purple}{\bf multiplication law}): \pause
\[
P(\textcolor{orange}{\it sss})= P(\textcolor{orange}{\it s}) \times P(\textcolor{orange}{\it s}) \times P(\textcolor{orange}{\it s}) = \frac{1}{6}\times \frac{1}{6} \times \frac{1}{6}=\left(\frac{1}{6}\right)^{3}
\]
}

\frame{
\frametitle{4.5 The binomial distribution}
\noindent That one's easy!  

\vsp

What about the probability that we get \textbf{two} sixes --- i.e. $P(X=2)$? \pause

\vsp

This one's a bit more tricky, because that means we need two $\textcolor{orange}{\it s}$'s and one $\textcolor{blue}{\it f}$... \pause

\vsp

...but the $\textcolor{blue}{\it f}$ (``not six'') could appear on the first roll, or the
second roll, or the third! \pause

\vsp

Thinking about it, there are actually \textbf{eight} possible outcomes for the
three rolls of the die:
}

\normal

\frame{
\frametitle{4.5 The binomial distribution}
\medskip
\begin{center}
\psfragscanon
\psfrag{s}[][][1.3][0]{\tiny $\textcolor{orange}{\it s}$}
\psfrag{f}[][][1.3][0]{\tiny$\textcolor{blue}{\it f}$}
\psfrag{1/6}[][][1.3][0]{\tiny$\frac{1}{6}$}
\psfrag{5/6}[][][1.3][0]{\tiny$\frac{5}{6}$}
\psfrag{(1/6)^3}[][][1.3][0]{\tiny$(\frac{1}{6})^3$}
\psfrag{(1/6)^2*(5/6)}[][][1.3][0]{\tiny$(\frac{1}{6})^2(\frac{5}{6})$}
\psfrag{(1/6)*(5/6)^2}[][][1.3][0]{\tiny$(\frac{1}{6})(\frac{5}{6})^2$}
\psfrag{(5/6)^3}[][][1.3][0]{\tiny$(\frac{5}{6})^3$}
\includegraphics[width=11cm,height=7cm]{probtree-3dice.eps}
\end{center}
}

\frame{
\frametitle{4.5 The binomial distribution}
\noindent So, for $P(X=2)$, we \textit{could} have: \pause
\begin{eqnarray*}
P(\textcolor{blue}{\it f}\textcolor{orange}{\it ss})	&=& \frac{5}{6}\times \frac{1}{6} \times \frac{1}{6}= \left(\frac{1}{6}\right)^{2}\times\frac{5}{6},
\end{eqnarray*} \pause
or we \textit{could} have:\pause
\begin{eqnarray*}
P(\textcolor{orange}{\it s}\textcolor{blue}{\it f}\textcolor{orange}{\it s})	&=& \frac{1}{6}\times \frac{5}{6} \times \frac{1}{6}= \left(\frac{1}{6}\right)^{2}\times\frac{5}{6},
\end{eqnarray*}
\textit{or even}: \pause
\begin{eqnarray*}
P(\textcolor{orange}{\it ss}\textcolor{blue}{\it f})	&=& \frac{1}{6}\times \frac{1}{6} \times \frac{5}{6}= \left(\frac{1}{6}\right)^{2}\times\frac{5}{6},
\end{eqnarray*}
}

\frame{
\frametitle{4.5 The binomial distribution}
\noindent Can you see that we therefore get: \pause
\begin{eqnarray*}
P(X=2)	&=& 3 \times \left(\frac{1}{6}\right)^{2}\times\frac{5}{6}.
\end{eqnarray*} \pause

\noindent Which takes the form:
\begin{eqnarray*}
P(X=2)&=&\text{\sf Number of ways to get two sixes} \\
       & &\\
       & & \times P(\text{\sf 2 sixes})\times P(\text{\sf 1 ``not six''}).
\end{eqnarray*}
}



\frame{
\frametitle{4.5 The binomial distribution}
\noindent Using the same argument as above we can calculate the other probabilities: \pause
\begin{eqnarray*}
P(X=0)	&=& \left(\frac{5}{6}\right)^{3} = 0.579\\ \pause
& & \\
P(X=1)	&=& 3 \times \left(\frac{1}{6}\right)\times \left(\frac{5}{6}\right)^{2} = 0.347 \pause	\\
& & \\
P(X=2)	&=& 3 \times \left(\frac{1}{6}\right)^{2}\times\frac{5}{6} = 0.069	\\ \pause
& & \\
P(X=3)	&=& \left(\frac{1}{6}\right)^{3} = 0.005...
\end{eqnarray*}
}

\frame{
\frametitle{4.5 The binomial distribution}
... and so the full \textcolor{purple}{\bf probability distribution} for $X$ is: \pause
\begin{center}
\begin{tabular}{|c|c c c c|} \hline
$x$		&0		&1	&2	&3	\\ \hline
$P(X=x)$	&0.579		&0.347	&0.069	&0.005	\\ \hline
\end{tabular}
\end{center} \pause

\vsp

\noindent This probability distribution shows that most of the time we would get either 0 or 1 sixes and, for example, 3 sixes would be quite
rare. \pause

\vsp

Try your own experiment! 

\vsp

\texttt{Minitab}
}




\frame{
\frametitle{4.5 The binomial distribution}
\noindent Now this is a bit long--winded $\ldots$ and that was just
for \textbf{three} rolls of the die!

\vsp

Imagine what it would be like to calculate for \textbf{100} rolls of the die! 

\vsp

\noindent We would like a more concise way of working these
probabilities out without having to list all the possible outcomes as
we did above. 

}

\frame{
\frametitle{4.5 The binomial distribution}
 You should see from the tree diagram that we can construct a \textcolor{purple}{\bf general formula}, taking the form: \pause 

\begin{eqnarray*}
P(X=r)&=&\text{\sf \# ways to get $r$ successes out of $n$ trials} \\
& & \\
 & &  \times P(\text{\sf $r$ successes})\times P(\text{\sf $n-r$ failures})
\end{eqnarray*}}



\frame{
\frametitle{4.5.1 The binomial distribution: notation}
\noindent In many surveys and experiments data is collected in the form of
\textcolor{purple}{\bf counts}. For example: \pause
\vspl
\begin{itemize}
\item  The number of people in the survey who bought a CD in the past month \pause
\vspl
\item  The number of people who said they would vote Labour at the next election \pause
\vspl
\item  The number of defective items in a sample taken from a production line
\end{itemize}
}

\frame{
\frametitle{4.5.1 The binomial distribution: notation}
All these variables have common features: \pause

\vspl

\begin{itemize}
\item [1.]Each person/item has only two possible (exclusive) responses
(Yes/No, Defective/Not defective etc)\\
 --- this is referred to as a \textcolor{purple}{\bf trial} which results in a
\textcolor{purple}{\bf success} or \textcolor{purple}{\bf failure}. \pause

\vspl
 
\item [2.]The survey/experiment takes the form of a random sample\\
--- the responses are \textcolor{purple}{\bf independent}. \pause

\vspl

\item [3.]The probability of a success in each trial is $p$ (in which case the probability of a failure is $1-p$). \pause

\vspl
 
\item [4.] We are interested in the random variable $X$, the total number of successes out of $n$ trials.  
\end{itemize}
}

\frame{
\frametitle{4.5.1 The binomial distribution: notation}
If these conditions are met, then $X$ has a \textcolor{purple}{\bf binomial distribution} with index $n$ and probability $p$.  \pause

\vsp

We write this as $X\sim Bin(n,p)$, which reads as ``$X$ has a binomial distribution with index $n$ and probability $p$''. \pause

\vsp

Here, $n$ and $p$ are known as the \textcolor{purple}{\bf parameters} of the binomial distribution. 
}

\frame{
\frametitle{4.5.1 The binomial distribution: notation} 
Returning to the dice--rolling experiment earlier: we were interested in the number of sixes obtained from three rolls of a six--sided die.  \pause

\vsp

Treating each roll of the die as a \textcolor{purple}{\bf trial}, with  a six representing a \textcolor{purple}{\bf success} and ``not a six'' representing a \textcolor{purple}{\bf failure}, we can see that: \pause
\vspl
\begin{itemize}
\item We have $n=3$ independent trials; \pause
\vspl
\item Each trial has probability of success $p=1/6$. 
\end{itemize} \pause

\vsp

 Thus if $X$ represents the number of sixes on the three rolls, we have that 
\[
X \sim Bin(3,1/6).
\]
}

\frame{
\frametitle{4.5.2 Probability calculations}
Recall our derived formula for working out probabilities in the die example: \pause
\begin{eqnarray*}
P(X=r)&=&\text{\sf \# ways to get $r$ successes out of $n$ trials} \\
 & & \\
  & &\times P(\text{\sf $r$ successes}) \times P(\text{\sf $n-r$ failures}).
\end{eqnarray*} \pause

We can write this more succinctly as

\begin{center}
\framebox[7cm]{ \parbox[t]{6cm}{

\vspace{0.1cm}
\begin{align*}
P(X=r)&=\comb{n}{r}\times p^{r}\times(1-p)^{n-r}.
\end{align*}}}
\end{center}
}

\frame{
\frametitle{4.5.2 Probability calculations}
\begin{center}
\framebox[7cm]{ \parbox[t]{6cm}{

\vspace{0.1cm}
\begin{align*}
P(X=r)&=\comb{n}{r}\times p^{r}\times(1-p)^{n-r}.
\end{align*}}}
\end{center}

The \textcolor{purple}{\bf binomial coefficient} $\comb{n}{r}$ works out how many ways we can choose $r$ objects out of $n$, and so is commonly read as ``$n$ choose $r$''.  \pause

\vsp

There is a formula for this, but it is more easily obtained using the $nCr$ button on the calculator!}


\frame{
\frametitle{4.5.2 Probability calculations}
\begin{center}
\framebox[7cm]{ \parbox[t]{6cm}{

\vspace{0.1cm}
\begin{align*}
P(X=r)&=\comb{n}{r}\times p^{r}\times(1-p)^{n-r}.
\end{align*}}}
\end{center}

 The expression for $P(X=2)$ in the die rolling
example can be calculated using this formula. \pause

\vsp

In this example,
\begin{itemize}
\item  $n=3$ \pause
\item $r=2$ \pause
\item The probability of success is $p=\frac{1}{6}$ \pause
\item The probability of failure is $1-p=\frac{5}{6}$. 
\end{itemize} \pause
}

\frame{
\frametitle{4.5.2 Probability calculations}
So,
\begin{eqnarray*}
P(X=2)	&=&\comb{3}{2} \times \left(\frac{1}{6}\right)^2 \times \left(1-\frac{1}{6}\right)^{3-2}\\ \pause
& & \\
 &=&3 \times \left(\frac{1}{6}\right)^{2}\times\frac{5}{6} \\ \pause
& & \\
&=& 0.069,
\end{eqnarray*} \pause
which matches up exactly with what we calculated before (as it should)! \pause

\vsp

You should try this formula for $r$ = 0, 1 and 3 to make sure you can recover the other values in the table on \st{page 112} page 108. }

\frame{
\frametitle{4.5.3 Mean and variance}
\noindent If we have the probability distribution for $X$ rather than the raw observations: \pause
\vspl
\begin{itemize}
\item We denote the mean for $X$ not by $\bar{x}$ but by $E[X]$ (``expectation of $X$'') \pause
\vspl
\item We denote the variance by $Var(X)$, and the standard deviation by $SD(X)$
\end{itemize} \pause  

\vspl

If $X$ is a random variable with Binomial $Bin(n,p)$ distribution, then its mean and variance are
\[
E[X] = n\times p \qquad Var(X) = n\times p \times (1-p).
\]
}


\frame{
\frametitle{4.5.3 Mean and variance}
For example, in the die--rolling experiment, \pause
\[
E[X] = 3\times \frac{1}{6} = 0.5
\] \pause
and
\begin{eqnarray*}
Var(X) &=& 3 \times \frac{1}{6}\times \frac{5}{6} = 0.417 \qquad \textrm{\sf and so}\\ \pause
SD(X)&=&\sqrt{0.417} = 0.645.
\end{eqnarray*}}

\frame{
\frametitle{Example 4.4}
 A salesperson has a 40\% chance of making a sale on a customer visit and she arranges 6 visits in a day. Suppose that the salesperson's visits result in sales \textit{independently}. 

\vspl 

\begin{itemize}
\item [\textbf{(a)}] What are the probabilities of her making 0, 1, 2, 3, 4, 5 and 6 sales? 

\vspl

\item [\textbf{(b)}] Find the salesperson's expected number of sales.  What is the standard deviation?
\end{itemize}}

\sol

\frame{
\frametitle{Solution to Example 4.4 (a)}
Let $X$: number of sales.  Then we have that \pause
\[
X \sim Bin(6,0.4)
\] \pause
Thus \pause
\begin{eqnarray*}
P(X=0) &=& \comb{6}{0}\times 0.4^0 \times 0.6^6 = \pause 0.047 \pause\\
P(X=1) &=& \comb{6}{1}\times 0.4^1 \times 0.6^5 = \pause 0.187 \pause\\
P(X=2) &=& \comb{6}{2}\times 0.4^2 \times 0.6^4 = \pause 0.311 \pause \\
 & & \\
\vdots &\vdots& \vdots \\
& & \\
P(X=6) &=& \comb{6}{6} \times 0.4^6 \times 0.6^0 = 0.004.
\end{eqnarray*}

}


\frame{
\frametitle{Solution to Example 4.4 (b)}
If $X\sim Bin(n,p)$, 
\vspl
\begin{itemize}
\item$E[X] = n\times p$ and 
\vspl
\item $Var(X) = n\times p \times (1-p)$,
\end{itemize}

\vspl

giving \pause
\begin{eqnarray*}
E[X]   &=& 6 \times 0.4 = 2.4 \textrm{ \sf sales.}
\end{eqnarray*} \pause
Also,
\begin{eqnarray*}
Var(X) &=& 6 \times 0.4 \times 0.6 = 1.44 \qquad \textrm{\sf so} \\
SD(X)   &=&\sqrt{1.44} = 1.2 \textrm{ \sf sales}.
\end{eqnarray*}
}


\begin{comment}

\frame{
\frametitle{Welcome back!}
\begin{itemize}
\item \textcolor{purple}{\bf New lecture time:} Friday \textbf{12 noon}, Bedson Building LT1\pause

\vspl

\item \textcolor{purple}{\bf New workshop times:} including some computer practical sessions in the CHART cluster (every third week, you'll be reminded when it's a computer week) \pause

\vspl

\item Your \textcolor{purple}{\bf marked case studies} will be returned soon, with feedback \pause

\end{itemize}
}

\frame{
\frametitle{Welcome back!}
\begin{itemize}
\item This semester: \pause

\vspl

\begin{itemize}
\item [--] Two more CBAs -- deadlines: \textbf{1st March}, \textbf{10th May} \pause

\vspl

\item [--] One more case study -- deadline: \textbf{8th May} \pause

\vspl

\item [--] Computer practical work -- deadline: \textbf{13th March}
\end{itemize} \pause

\vspl

\item This week: \pause

\vspl

\begin{itemize}
\item [--] We will probably finish Chapter 4 in this Friday's lecture \pause

\vspl
\item [--] Please collect your notes for Chapter 5 from the Maths General Office at some point this week -- any time from Wednesday lunchtime onwards
\end{itemize}

\end{itemize}
}

\end{comment}

\begin{comment}
\normal

\frame{
\frametitle{Recap: The binomial distribution}
If, for our discrete random variable $X$, we have:

\vspl

\begin{itemize}
\item A \textcolor{purple}{\bf finite number of "trials"}; \\
\textcolor{gray}{\textit{[e.g. roll a fair die three times -- number of trials $n=3$]}}\pause

\vspl

\item and each trial has \textcolor{purple}{\bf two outcomes}  -- "success" and "failure"; \\ 
\textcolor{gray}{\textit{[e.g. "get a six" and "do not get a six"]}}\pause

\vspl 

\item if we know the \textcolor{purple}{\bf probability of "success"}; \\
\textcolor{gray}{\textit{[e.g. here, $p=1/6$]}} \pause

\vspl

\item and if the outcome of each trial is \textcolor{purple}{\bf independent} of every other trial... \\
\textcolor{gray}{\textit{[e.g. the outcome of each roll has no influence over all the other outcomes]}}\pause

\end{itemize}

\vspl

... then we can say that 
\[
X\sim \textsf{Bin}(n,p)
\]

}

\frame{
\frametitle{Recap: The binomial distribution}
In the last lecture, we "derived" the following key formula for a binomial random variable, where $X\sim \textsf{Bin}(n,p)$:

\vsp

\begin{itemize}

\item $P(X=r) = \comb{n}{r} \times p^{r} \times (1-p)^{n-r}$  \pause

\vsp

\item $E[X] = n\times p $ \pause

\vsp

\item $\textit{\sf Var}(X) = n \times p \times (1-p)$
\end{itemize}
}

\frame{
\frametitle{Recap: The binomial distribution}
\noindent \textbf{Example from last lecture:} Suppose 
\[
X: \textsf{Number of sixes on three rolls of a die}. \pause
\]
You should see that we can say:
\[
X \sim \textsf{Bin}(3,1/6),
\] \pause
and that, for example, 
\[
P(X=2) = \comb{3}{2}\times\left(\frac{1}{6}\right)^{2} \times \left(\frac{5}{6}\right) = 0.069.
\] \pause

Also,
\begin{eqnarray*}
E[X] &=& 3 \times \frac{1}{6} = 0.5 \qquad \textsf{and}
\\
\textsf{Var}(X) &=& 3 \times \frac{1}{6} \times \frac{5}{6} = 0.417.
\end{eqnarray*}
}

\frame{
\frametitle{Your turn...}
Now try 

\vsp


\begin{itemize}
\item \textbf{Question 6} -- think carefully about part (d) 

\vspl

\item \textbf{Question 8 }(Alicia, Robyn, Josh -- sorry if you don't like McDonald's!)

\vspl

\item \textbf{Question 9} -- think carefully about part (c)  

\vspl

\item \textbf{Question 11} -- hard!
\end{itemize} \pause

\vsp

Don't forget to ask if you have any questions, and please sign the attendance list! 
}


\end{comment}
 


\normal

\frame{
\frametitle{4.6 The Poisson distribution}
 The \textcolor{purple}{\bf Poisson distribution} is a very important discrete
probability distribution which arises in many different contexts.

\vsp

Typically, Poisson random quantities are used in place of binomial
random quantities in situations where $n$ is large, $p$ is small, and
both $np$ and $n(1-p)$ exceed~5. \pause

\vsp

In general, it is used to model data which are counts of (random) events in a certain area or time interval, \underline{without a known/fixed upper limit} but with a known \textcolor{purple}{\bf rate} of occurrence.  
}


\frame{
\frametitle{4.6 The Poisson distribution}
\noindent For example, consider the number of calls made in a 1 minute interval
to an Internet service provider (ISP). \pause

\vsp

The ISP has thousands of subscribers, but each one will call with a very small probability. \pause

\vsp

If the ISP knows that on average 5 calls will be made in the interval,
the actual number of calls will be a Poisson random variable, with
mean 5.
}


\frame{
\frametitle{4.6.1 Notation and probability calculations}
\noindent If $X$ is a random variable with a Poisson distribution with
parameter~$\lambda$ (Greek lower case ``lambda''), then the
probability it takes different values is \pause
\[
P(X=r)=\frac{\lambda^r\,e^{-\lambda}}{r!}, \quad r=0,1,2,\ldots~.
\]\pause
We write this as $X\sim Po(\lambda)$.  The parameter $\lambda$ has a
very simple interpretation as the \textcolor{purple}{\bf rate} at which events occur. }

\frame{
\frametitle{4.6.2 Mean and variance}
The Poisson distribution has mean and variance
\[
E(X)=\lambda,\qquad Var(X)=\lambda.
\] 
}

\frame{
\frametitle{4.6 The Poisson distribution}
\noindent Returning to the ISP example, suppose we want to know the
probabilities of different numbers of calls made to the ISP. \pause

\vsp

Let $X$ be the number of calls made in a minute. Then $X\sim Po(5)$ and, for
example, the probability of receiving \textcolor{blue}{\bf 4} calls is \pause
\[
P(X=\textcolor{blue}{\bf 4})=\frac{5^{\textcolor{blue}{\bf 4}}e^{-5}}{\textcolor{blue}{\bf 4}!}= 0.1755.
\] \pause
Similarly, the probability of receiving \textcolor{blue}{\bf 7} calls is \pause
\[
P(X=\textcolor{blue}{\bf 7}) = \frac{5^{\textcolor{blue}{\bf 7}}e^{-5}}{\textcolor{blue}{\bf 7}!} = 0.1044.
\]
}
\frame{
\frametitle{4.6 The Poisson distribution}
\noindent We can use the formula for Poisson probabilities to calculate the
probability of all possible outcomes:
{\small
\begin{center}
\begin{tabular}{c c c}
$r$ & $P(X=r)$ & $P(X\leq r)$ \\
\hline
0 & \textcolor{white}{0.0067} & \textcolor{white}{0.0067}\\
1 &  \textcolor{white}{0.0337} &  \textcolor{white}{0.0404}\\
2 &  \textcolor{white}{0.0843}&  \textcolor{white}{0.1247}\\
3 &  \textcolor{white}{0.1403} &  \textcolor{white}{0.2650}\\
4 & 0.1755 &  \textcolor{white}{0.4405}\\
5 &  \textcolor{white}{0.1755} &  \textcolor{white}{0.6160}\\
6 &  \textcolor{white}{0.1462} &  \textcolor{white}{0.7622}\\
7 & 0.1044 &  \textcolor{white}{0.8666}\\
8 &  \textcolor{white}{0.0653} &  \textcolor{white}{0.9319}\\
$\vdots$ & \textcolor{white}{$\vdots$} &  \textcolor{white}{$\vdots$} \\
\hline
sum  &  \textcolor{white}{1.000000} & \\
\end{tabular}
\end{center}}
{\color{white}
\noindent Therefore the probability of receiving between 2 and 8 calls is
\[
P(2\leq X\leq 8)=P(X\leq 8)-P(X\leq 1)=0.9319-0.0404=0.8915
\]}
}

\frame{
\frametitle{4.6 The Poisson distribution}
\noindent We can use the formula for Poisson probabilities to calculate the
probability of all possible outcomes:
{\small
\begin{center}
\begin{tabular}{c c c}
$r$ & $P(X=r)$ & $P(X\leq r)$ \\
\hline
0 & 0.0067 & \textcolor{white}{0.0067}\\
1 & 0.0337 &  \textcolor{white}{0.0404}\\
2 & 0.0843 &  \textcolor{white}{0.1247}\\
3 & 0.1403 &  \textcolor{white}{0.2650}\\
4 & 0.1755 &  \textcolor{white}{0.4405}\\
5 & 0.1755 &  \textcolor{white}{0.6160}\\
6 & 0.1462 &  \textcolor{white}{0.7622}\\
7 & 0.1044 &  \textcolor{white}{0.8666}\\
8 & 0.0653 &  \textcolor{white}{0.9319}\\
$\vdots$ & $\vdots$ &  \textcolor{white}{$\vdots$} \\
\hline
sum  & 1.000000 & \\
\end{tabular}
\end{center}}
{\color{white}
\noindent Therefore the probability of receiving between 2 and 8 calls is
\[
P(2\leq X\leq 8)=P(X\leq 8)-P(X\leq 1)=0.9319-0.0404=0.8915
\]}
}

\frame{
\frametitle{4.6 The Poisson distribution}
\noindent We can use the formula for Poisson probabilities to calculate the
probability of all possible outcomes:
{\small
\begin{center}
\begin{tabular}{c c c}
$r$ & $P(X=r)$ & $P(X\leq r)$ \\
\hline
0 & 0.0067 & 0.0067\\
1 & 0.0337 & 0.0404\\
2 & 0.0843 & 0.1247\\
3 & 0.1403 & 0.2650\\
4 & 0.1755 & 0.4405\\
5 & 0.1755 & 0.6160\\
6 & 0.1462 & 0.7622\\
7 & 0.1044 & 0.8666\\
8 & 0.0653 & 0.9319\\
$\vdots$ & $\vdots$ & $\vdots$ \\
\hline
sum  & 1.000000 & \\
\end{tabular}
\end{center}}
{\color{white}
\noindent Therefore the probability of receiving between 2 and 8 calls is
\[
P(2\leq X\leq 8)=P(X\leq 8)-P(X\leq 1)=0.9319-0.0404=0.8915
\]}
}

\frame{
\frametitle{4.6 The Poisson distribution}
\noindent We can use the formula for Poisson probabilities to calculate the
probability of all possible outcomes:
{\small
\begin{center}
\begin{tabular}{c c c}
$r$ & $P(X=r)$ & $P(X\leq r)$ \\
\hline
0 & 0.0067 & 0.0067\\
1 & 0.0337 & 0.0404\\
2 & \textcolor{orange}{\bf 0.0843} & 0.1247\\
3 & \textcolor{orange}{\bf 0.1403} & 0.2650\\
4 & \textcolor{orange}{\bf 0.1755} & 0.4405\\
5 & \textcolor{orange}{\bf 0.1755} & 0.6160\\
6 & \textcolor{orange}{\bf 0.1462} & 0.7622\\
7 & \textcolor{orange}{\bf 0.1044} & 0.8666\\
8 & \textcolor{orange}{\bf 0.0653} & 0.9319\\
$\vdots$ & $\vdots$ & $\vdots$ \\
\hline
sum  & 1.000000 & \\
\end{tabular}
\end{center}}
\noindent Therefore the probability of receiving between 2 and 8 calls is
{\color{white}
\[
P(2\leq X\leq 8)=P(X\leq 8)-P(X\leq 1)=0.9319-0.0404=0.8915
\]}
}

\frame{
\frametitle{4.6 The Poisson distribution}
\noindent We can use the formula for Poisson probabilities to calculate the
probability of all possible outcomes:
{\small
\begin{center}
\begin{tabular}{c c c}
$r$ & $P(X=r)$ & $P(X\leq r)$ \\
\hline
0 & 0.0067 & 0.0067\\
1 & 0.0337 & \textbf{0.0404}\\
2 & \textcolor{orange}{\bf 0.0843} & 0.1247\\
3 & \textcolor{orange}{\bf 0.1403} & 0.2650\\
4 & \textcolor{orange}{\bf 0.1755} & 0.4405\\
5 & \textcolor{orange}{\bf 0.1755} & 0.6160\\
6 & \textcolor{orange}{\bf 0.1462} & 0.7622\\
7 & \textcolor{orange}{\bf 0.1044} & 0.8666\\
8 & \textcolor{orange}{\bf 0.0653} & \textbf{0.9319}\\
$\vdots$ & $\vdots$ & $\vdots$ \\
\hline
sum  & 1.000000 & \\
\end{tabular}
\end{center}}
\noindent Therefore the probability of receiving between 2 and 8 calls is \pause
\[
P(2\leq X\leq 8)=P(X\leq 8)-P(X\leq 1)=0.9319-0.0404=0.8915
\]
}

\frame{
\frametitle{4.6 The Poisson distribution}
Probability calculations such as this enable ISPs to calibrate the likely demand for their service and hence the resources they need to provide the service.

\vsp

Using such a model we can also account for ``extreme'' situations. 

\vsp

For example, suppose that, for this ISP, we observed the following number of calls per minute over a five minute period: \textcolor{brown}{\bf 6}, \textcolor{brown}{\bf 3}, \textcolor{brown}{\bf 5}, \textcolor{brown}{\bf 4}, \textcolor{brown}{\bf 6}. \pause

\vsp

 Using simple frequentist reasoning, we would have
\begin{eqnarray*}
P(\textrm{\sf 7 calls made}) 	&=& \frac{0}{5} = 0,
\end{eqnarray*}
i.e. we will \textit{never} observe seven calls in any one minute period!
}

\frame{
\frametitle{4.6 The Poisson distribution}
However, using the Poisson model, we have
\begin{eqnarray*}
P(X=7)	&=& 0.1044,
\end{eqnarray*}
which is probably more realistic.  \pause

\vsp

You can see from the previous table of probabilities that, although when $r$ is large the associated probabilities are small, at least they are accounted for and are, more realistically, non--zero. 
}


\normal

\frame{
\frametitle{Review: Binomial and Poisson distributions}
\textbf{Binomial:} $X \sim \textsf{Bin}(n,p)$ \pause

\vsp

\begin{itemize}

\item $n$ is the number of ``trials'' \pause

\vspl

\item $p$ is the ``success'' probability \pause

\vspl

\item Each trial must have two possible outcomes (``success'' and ``failure'') \pause

\vspl

\item Each trial must be independent of every other trial \pause

\vspl

\item Since $n$ is known, there is a \textcolor{purple}{\bf known upper limit to the random variable}
\end{itemize}
}

\frame{
\frametitle{Review: Binomial and Poisson distributions}
\textbf{Poisson:} $X\sim \textsf{Po}(\lambda)$ \pause

\vsp

\begin{itemize}
\item $\lambda$ is the ``rate of occurrence'' \pause

\vspl

\item Often used when we are counting something over a fixed time interval \pause

\pause

\item The value of $\lambda$ is constant across time \pause

\vspl

\item We usually \textcolor{purple}{\bf don't know the upper limit of the random variable}
\end{itemize}
}


\frame{

\frametitle{Review: Binomial and Poisson distributions}

\textbf{Key formulae} \pause
\begin{center}
\begin{tabular}{|c|c|c|c|} \hline
              &$P(X=r)$   &Expectation &Variance \\ \hline
              &                           &             &         \\
Binomial      &$\comb{n}{r}p^{r}(1-p)^{n-r}$ &$np$  &$np(1-p)$ \\
               &                           &             & \\ \hline
         & & & \\
Poisson         &$\displaystyle \frac{e^{-\lambda}\lambda^{r}}{r!}$  &$\lambda$ &$\lambda$ \\
      & & & \\ \hline
\end{tabular}
\end{center}
}


\normal


\frame{
\frametitle{Example 4.5}
\textit{Pronto Pizzeria} have recently opened a new restaurant in Newcastle.  They have noticed that, during any one hour period on a Saturday night, they usually see about eight parties of customers arrive.
\vspl
\begin{itemize}
\item [\textbf{(a)}] What probability distribution might be appropriate for $X$, the number of parties that arrive between 7pm and 8pm this Saturday evening?

\vspl

\item [\textbf{(b)}] What is the probability that, between 7pm and 8pm this Saturday, at least three parties of customers arrive at the restaurant?

\vspl

\item [\textbf{(c)}] The management are considering a Half Price Happy Hour Menu between 6pm and 7pm every Saturday night.  Why might the model you proposed in part (a) no longer be valid?
\end{itemize}
}

\sol

\frame{
\frametitle{Solution to Example 4.5(a)}
\textbf{Poisson} distribution -- we have a rate (8 per hour), and we do not know the upper limit for the number of parties. \pause

\vsp

If $X$: Number of parties arriving in a one hour period. then
\[
X \sim Po(8).
\]
}


\frame{
\frametitle{Solution to Example 4.5(b)}
\begin{eqnarray*}
P(X\geq 3)   &=& \pause 1-P(X\leq 2)  \pause \\
             &=& 1-\left\{P(X=0)+P(X=1)+P(X=2) \right\} \\ \pause
 & & \\
             &=& 1 -\left\{\frac{e^{-8}8^{0}}{0!}+\frac{e^{-8}8^{1}}{1!}+\frac{e^{-8}8^{2}}{2!}\right\}  \pause \\
  & & \\
              &=& 1- \left\{0.0003+0.0027+0.0107 \right\} \pause \\
           & & \\
                &=&0.9863.
\end{eqnarray*}
}

\frame{
\frametitle{Solution to Example 4.5(c)}
We might expect more people to come to the restaurant during the Happy Hour -- therefore we cannot assume the same rate of occurrence.

\vsp

Specifically, we might expect $\lambda>8$.
}

\normal

\frame{
\frametitle{Example 4.6}
Consider the following two scenarios: \pause

\vsp
\textbf{Scenario 1} 

\vspl

\noindent \textit{RyanJet} currently leads all European airlines in on--time arrivals, with 82.5\% of it's flights arriving on time or earlier.  Of the next 6 scheduled \textit{RyanJet} flights, $X$ is the number that will land on time. \pause

\vsp
  
\textbf{Scenario 2}

\vspl

\noindent Customer bookings on the \textit{RyanJet} website occur at a rate of 20 per hour.  Due to a technical problem, the \textit{RyanJet} website will be down for maintenance between 17:30 and 18:00 this evening.  We are interested in $Y$, the number of bookings we can expect \textit{RyanJet} to lose, because of this website down--time. 
}


\frame{
\frametitle{Example 4.6}
\begin{itemize}
\item [\textbf{1.}] Would you use the binomial distribution or the Poisson distribution to model the scenarios outlined above?  

\vsp

In each case explain why, and state fully the most appropriate distribution, including the values of the associated parameters. 
\end{itemize}
 
}

\sol

\frame{
\frametitle{Example 4.6: Solution (1/2)}
\textbf{Scenario 1} --  \pause \textcolor{purple}{\bf Binomial distribution} \pause
\vspl
\begin{itemize}
\item Finite number of trials ($n=6$) \pause
\vspl
\item Each trial has two outcomes (success = land on time, failure = dosen't land on time) \pause
\vspl
\item We know that $p=0.825$ \pause 
\vspl
\item Assuming independence, we have $X\sim \textsf{Bin}(6,0.825)$.
\end{itemize}
}

\frame{
\frametitle{Example 4.6: Solution (2/2)}

\textbf{Scenario 2} -- \pause \textcolor{purple}{\bf Poisson distribution} \pause
\vspl
\begin{itemize}
\item Don't know the upper bound for $Y$ \pause
\vspl
\item We have a rate of occurrence: $\lambda=20$ per hour \pause
\vspl
\item Assuming a constant rate, we have $Y\sim \textsf{Po}(10)$
\end{itemize}
}


\normal

\frame{
\frametitle{Example 4.6}
\begin{itemize}
\item [\textbf{2.}] Find the expectation, and standard deviation, of the number of on--time flights of the next 6 scheduled \textit{RyanJet} flights.  

\vsp

Also find the expected number of lost \textit{RyanJet} bookings between 17:30 and 18:00, with the associated standard deviation. 
\end{itemize}  
}

\sol

\frame{
\frametitle{Example 4.6: Solution (1/1)}
Since $X\sim \textsf{Bin}(6,0.825)$, then \pause

\vspl

\begin{itemize}
\item $E[X] = n \times p = 6\times 0.825 = 4.95 \textsf{ flights}$. \pause
\vspl
\item $Var(X) = n \times p \times (1-p) = 6\times 0.825 \times 0.175 = 0.86625$.  Thus, $SD(X) = \sqrt{0.86625} = 0.931 \textsf{ flights}$.  \pause
\end{itemize}

\vsp

Since $Y\sim \textsf{Po}(10)$, then \pause

\vspl
\begin{itemize}
\item $E[Y] = \lambda = 10 \textsf{ bookings}.$ \pause 
\vspl
\item $Var(Y) = \lambda = 10$.  Thus $SD(Y) = \sqrt{10} = 3.162 \textsf{ bookings}.$ 
\end{itemize}
}

 \normal

\frame{
\frametitle{Example 4.6}
\begin{itemize}
\item [\textbf{3.}] Find the probability that, of \textit{RyanJet}'s next six flights, exactly 4 arrive on time.  
\end{itemize}
}

\sol
\frame{
\frametitle{Example 4.6: Solution (1/1)}
We have $X\sim\textsf{Bin}(6,0.825)$.  So \pause
\begin{eqnarray*}
P(X=4) &=&\comb{6}{4}\times 0.825^{4} \times 0.175^{2} \\ \pause
       & & \\
       &=& 15 \times 0.4632504 \times 0.030625 \pause \\
       && \\
         &=& 0.2128.
\end{eqnarray*}
}

\normal

\frame{
\frametitle{Example 4.6}
\begin{itemize}


\item [\textbf{4.}] Find the probability that \textit{RyanJet} will lose 
\vspl
\begin{itemize}
\item [\textbf{(a)}] exactly 8 bookings;

\vspl

\item [\textbf{(b)}] more than 2 bookings,
\end{itemize}

\vspl
during their website down--time.
\end{itemize}
}

\sol

\frame{
\frametitle{Example 4.6: Solution (1/2)}
We know that $Y \sim \textsf{Po}(10)$.  So\pause
\begin{eqnarray*}
P(Y=8)  &=& \frac{e^{-10} \times 10^{8}}{8!} \pause \\
           & & \\
          &=&0.1126
\end{eqnarray*}
}

\frame{
\frametitle{Example 4.6: Solution (2/2)}
Similarly, \pause
\begin{eqnarray*}
P(Y>2)  &=& P(Y=3) + P(Y=4) + \cdots \pause \\
        &=&1-\left\{P(Y=0)+P(Y=1)+P(Y=2)\right\} \\ \pause
        && \\
        &=&1-\left\{\frac{e^{-10}10^{0}}{0!} + \frac{e^{-10}10^{1}}{1!} + \frac{e^{-10}10^{2}}{2!} \right\}\pause \\
         & & \\
        &=& 1-\left\{0.000045 + 0.00045 + 0.0023\right\} \pause \\
          && \\
          &=& 0.9972.
\end{eqnarray*}
}

\normal

\frame{
\frametitle{Example 4.6}
\begin{itemize}
\item [\textbf{5.}] It is decided to move the website down--time to 03:00--03:30. 

\vsp

Why might the model you proposed in question 1 no longer be appropriate?
\end{itemize}
}

\sol

\frame{
\frametitle{Example 4.6: Solution (1/1)}
The rate will probably change -- surely, the number of bookings made in the middle of the night will not be the same as at other times of the day.  
}

\normal

\frame{
\frametitle{Example 4.7}
When a customer places an order with \textit{Staples Online Office Supplies}, a computerised accounting information system automatically checks to see if the customer has exceeded his or her credit limit.  

\vsp

Let $X$ be the number of customers who have exceeded their credit limit.  

\vsp

In a random sample of $n$ orders, we can expect 1 customer to have exceeded their credit limit, with a variance of 0.95.  
}

\frame{
\frametitle{Example 4.7}
\begin{itemize}
\item [\textbf{1.}] Would the binomial or the Poisson distributions be most appropriate to model $X$?
\end{itemize}
}

\sol

\frame{
\frametitle{Example 4.7: Solution (1/1)}
The \textcolor{purple}{\bf Binomial distribution} -- as we have a finite number of orders ($n$), and each trial has two outcomes: \pause

\vspl

\begin{itemize}
\item success (exceeded credit limit) \pause
\vspl
\item failure (does not exceed credit limit)
\end{itemize} \pause

\vspl

We can also assume independence between trials, as we have a random sample of orders.
}

\normal

\frame{
\frametitle{Example 4.7}
\begin{itemize}
\item [\textbf{2.}] Find the parameters of the model you proposed in question 1, and hence find the probability that at least 1 customer, of the next $n$ orders placed, exceeds their credit limit. 
\end{itemize}
}

\sol

\frame{
\frametitle{Example 4.7: Solution (1/3)}
We are told that $E[X]=1$; therefore, \pause
\begin{eqnarray*}
n \times p &=& 1, \qquad \textsf{and so} \\ \pause
         n &=&\frac{1}{p}.
\end{eqnarray*} \pause
We are also told that $Var(X) = 0.95$; therefore, \pause  
 \begin{eqnarray*}
n \times p \times (1-p) &=&0.95 \pause \qquad \textsf{and so} \\ \pause
\frac{1}{p} \times p \times (1-p) &=&0.95 \pause \\
                  1-p    &=&0.95 \pause \\
                       p &=&0.05. \pause
\end{eqnarray*}
}
\frame{
\frametitle{Example 4.7: Solution (2/3)}
Substituting $p=0.05$ into the expression for the expectation gives \pause
\[
n = \frac{1}{p} = \frac{1}{0.05} = 20.
\] \pause

So we have $X\sim\textsf{Bin}(20,0.05)$. 
}

\frame{
\frametitle{Example 4.7: Solution (3/3)}
Now we can find \pause
\begin{eqnarray*}
P(X\geq 1) &=& 1- P(X=0) \\ \pause
           &=& 1-\comb{20}{0} \times 0.05^{0} \times 0.95^{20} \pause \\
           &=& 1-0.3585 \pause \\
           &=&0.6415.
\end{eqnarray*}
}


\announce
\frame{
\frametitle{Announcements}
\begin{itemize}
\item CBA3 -- the first CBA of semester 2 -- goes live in practice mode this coming \textcolor{purple}{\bf Monday, 20th February} \pause

\vspl

\item Next week is a \textcolor{purple}{\bf computer practical week} -- see course webpage/your own personal timetable for details \pause

\vspl

\item Marked case study 2 reports available to collect from the ACC1012/1053 box upstairs \pause

\vspl

\item Course webpage now up-to-date, including one page summary of learning outcomes for Chapter 4 \pause

\vspl

\item ReCap recordings -- there have been problems locating these, but the ReCap team are sorting this out! \pause

\vspl

\item Today we will start Chapter 5, but first...
\end{itemize}
}


\normal
\frame{
\frametitle{Recap: Probability models}
\begin{itemize}
\item Is your variable \textcolor{purple}{\bf discrete} or \textcolor{purple}{\bf continuous}? \pause

\vspl

\item If \textcolor{purple}{\bf discrete} (e.g. \# customers arriving in a ten minute interval; \# of successful sales made on the next 6 visits)  : \pause

\vspl

\begin{itemize}
\item [--] Do you have a fixed number of independent trials, each with two outcomes (``\textcolor{orange}{\bf success}'' and ``\textcolor{orange}{\bf failure}")? \pause

\vspl

\item [--] Do you know the probability of success?  \pause

\vspl

\item [--] Do you have a fixed rate of occurrence per unit time/per page/per mile cycled etc...?  
\end{itemize} \pause

\vspl

\item If \textcolor{purple}{\bf continuous}...
\end{itemize}
}



\frame{

\vspace{1cm}

\huge
\textbf{Chapter 5}

\vspace{1cm}

\Large
\textbf{Continuous probability models}

}


\frame{
\frametitle{What we'll cover...}
\begin{itemize}
\item \textcolor{purple}{\bf Probability density functions} \pause
\vspl
\item The \textcolor{purple}{\bf Normal distribution} \pause
\vspl
\item The \textcolor{purple}{\bf Uniform distribution} \pause
\vspl
\item The \textcolor{purple}{\bf exponential distribution} \pause
\vspl
\item \textcolor{purple}{\bf Poisson processes}
\end{itemize}
}

\normal

\frame{
\frametitle{5. Continuous probability models}
\noindent We have seen how \textcolor{purple}{\textbf{discrete}} random variables can be modelled by discrete
probability distributions such as the \textcolor{purple}{\textbf{binomial}} and \textcolor{purple}{\textbf{Poisson}} distributions. \pause

\vspace{0.3cm}

\noindent We now consider how to model \textcolor{purple}{\textbf{continuous}} random
variables. 
}


\frame{
\frametitle{5.1 Introduction}

\noindent A variable is \textcolor{purple}{\textbf{discrete}} if it takes a \textcolor{purple}{\textbf{countable}} number of values.

\vspace{0.3cm}

\noindent \textbf{For example},
\begin{itemize}
\item [--] the number of \textcolor{blue}{\textbf{blue}} cars that I count in a 5 minute period
\item [--] the number of \textbf{heads} observed when I flip a coin ten times
\item [--] Shoe sizes: $1, \ldots, 12, 13, 1, 2, \ldots$
\item [--] $r=0,0.1,0.2,\ldots,0.9,1.0$
\end{itemize}

\pause

\vspace{0.3cm}

\noindent In contrast, the values which a \textcolor{purple}{\textbf{continuous variable}}
can take form a \textcolor{purple}{\textbf{continuous scale}}, with no ``jumps''.   

\vspace{0.3cm}
\noindent \textbf{For example},
\begin{itemize}
\item [--] Height
\item [--] Weight
\item [--] Temperature
\end{itemize}
}

\frame{
\frametitle{5.1 Introduction}
\noindent Think about \textcolor{purple}{\textbf{height}}. \pause
\vsp 
\begin{itemize}
\item  In practice, we might only record height to the \textcolor{purple}{\textbf{nearest cm}}
\vspl
\item  If we could measure height \textit{exactly} we'd find that everyone had a \textcolor{purple}{\textbf{different height}} \pause
\vspl
\item  This is the essential difference between discrete and continuous variables \pause
\vspl
\item  If there are $n$ people on the planet, the probability that someone's height is $x$ would be $\frac{1}{n}$ \pause
\vspl
\item  As $n$ gets bigger and bigger, this probability tends to zero!!
\end{itemize}
}

\frame{
\frametitle{5.1 Introduction}
\noindent Consider taking a sample of values from: \pause
\[
X: \textsf{Weight of 10oz burger}.
\]

\begin{center}
\includegraphics[width=6cm]{burger.ps}
\end{center}



}


\frame{
\frametitle{5.1 Introduction}
This is what we might observe as our sample got bigger:
\begin{center}
%\resizebox{\textwidth}{!}{\includegraphics{hist1.pdf}}
%\resizebox{\textwidth}{!}{\includegraphics{hist2.pdf}}
%\resizebox{\textwidth}{!}{\includegraphics{hist3.pdf}}
%\resizebox{\textwidth}{!}{\includegraphics{histinf.pdf}}
\psfrag{f}[][]{\tiny \sf Frequency}
\psfrag{W}[][]{\tiny \sf oz }
\psfrag{A}[][]{\tiny $n=100$}
\psfrag{B}[][]{\tiny $n=1000$}
\psfrag{C}[][]{\tiny $n=10,000$}
\psfrag{D}[][]{\tiny $n=100,000$}
\psfrag{E}[][]{\tiny $n=1000,000$}
\psfrag{F}[][]{\tiny $n=10,000,000$}
\psfrag{9.0}[][]{\tiny \sf 9.0}
\psfrag{9.5}[][]{\tiny \sf 9.5}
\psfrag{10.0}[][]{\tiny \sf 10.0}
\psfrag{10.5}[][]{\tiny \sf 10.5}
\psfrag{11.0}[][]{\tiny \sf 11.0}
\psfrag{0}[][]{\tiny \sf 0}
\psfrag{5}[][]{\tiny \sf 5}
\psfrag{10}[][]{\tiny \sf 10}
\psfrag{15}[][]{\tiny \sf 15}
\psfrag{20}[][]{\tiny \sf 20}
\psfrag{50}[][]{\tiny \sf }
\psfrag{100}[][]{\tiny \sf 100}
\psfrag{150}[][]{\tiny \sf }
\psfrag{200}[][]{\tiny \sf 200}
\psfrag{250}[][]{\tiny \sf }
\psfrag{500}[][]{\tiny \sf }
\psfrag{1000}[][]{\tiny \sf 1000}
\psfrag{1500}[][]{\tiny \sf }
\psfrag{2000}[][]{\tiny \sf 2000}
\psfrag{2500}[][]{\tiny \sf }
\psfrag{4000}[][]{\tiny \sf}
\psfrag{6000}[][]{\tiny \sf }
\psfrag{8000}[][]{\tiny \sf 8000}
\psfrag{10000}[][]{\tiny \sf }
\psfrag{12000}[][]{\tiny \sf }
\psfrag{20000}[][]{\tiny \sf }
\psfrag{40000}[][]{\tiny \sf }
\psfrag{60000}[][]{\tiny \sf 60000}
\psfrag{80000}[][]{\tiny \sf }
\psfrag{100000}[][]{\tiny \sf }
\psfrag{120000}[][]{\tiny \sf 120000}
\psfrag{200000}[][]{\tiny \sf 200000}
\psfrag{400000}[][]{\tiny \sf 400000}
\psfrag{600000}[][]{\tiny \sf 600000}
\psfrag{800000}[][]{\tiny \sf 800000}
\psfrag{1000000}[][]{\tiny \sf 1000000}
\psfrag{1200000}[][]{\tiny \sf 1200000}
\psfrag{0e+00}[][]{\tiny \sf 0e+00}
\psfrag{1e+05}[][]{\tiny \sf }
\psfrag{2e+05}[][]{\tiny \sf }
\psfrag{3e+05}[][]{\tiny \sf }
\psfrag{4e+05}[][]{\tiny \sf 4e+05}
\psfrag{5e+05}[][]{\tiny \sf }
\psfrag{6e+05}[][]{\tiny \sf }
\includegraphics[width=10cm, height=7cm]{cdfbigger.ps}
\end{center}
}

\frame{
\frametitle{5.1 Introduction}
\begin{itemize}
\item As the sample size gets bigger, the \textcolor{purple}{\textbf{interval widths get smaller}}
\item  the jagged profile of the histogram \textcolor{purple}{\textbf{smooths out}} to become a curve
\item When the sample size is infinitely large, this curve is known as the \textcolor{purple}{\textbf{probability density function}} (pdf)
\end{itemize}
}

\frame{
\frametitle{5.1 Introduction}
\frametitle{Features of the probability density function}

\noindent \textbf{The key features of pdfs are:}

\vspl 

\begin{enumerate}
\item pdfs never take negative values

\vspl

\item the area under a pdf is one: $P(-\infty<X<\infty)=1$

\vspl

\item areas under the curve correspond to probabilities

\vspl

\item $P(X\leq x)=P(X<x)$ since $P(X=x)=0$.
\end{enumerate}
}

\frame{
\frametitle{5.1 Introduction}
\noindent Over the next two weeks we will consider some particular probability distributions that are often used to describe continuous random variables.  

\vspace{0.3cm}

\pause
\noindent We start with the most \textcolor{purple}{\textbf{important}}, most \textcolor{purple}{\textbf{widely--used}} statistical distribution of all time...

\vspace{1cm}

\pause

\begin{center}
\LARGE
\textcolor{blue}{\textbf{...wait for it...}}
\normalsize
\end{center}
}

\frame{
\frametitle{5.2 The Normal distribution}
\begin{center}
\Huge
\ovalbox{\textbf{The Normal Distribution}}
\normalsize
\end{center}
}

\frame{

\frametitle{5.2.1 Introduction}
\noindent The \textcolor{purple}{\textbf{Normal distribution}} is without doubt the most widely--used statistical distribution in many practical applications:
\pause

\vsp

\begin{itemize}
	\item Normality arises \textcolor{purple}{\textbf{naturally}} in many physical, biological and social measurement situations

\vspl

\pause
	\item Normality is important in \textcolor{purple}{\textbf{Statistical inference}} 
\pause

\vspl

\item The normal distribution has many guises:
\begin{itemize}
	\item[--] Gaussian distribution
	\item[--] Laplacean distribution
	\item[--] ``bell--shaped curve''
\end{itemize}
\end{itemize}

\begin{center}
\includegraphics[width=2.65cm,height=2.7cm]{Gauss2.ps}
\hspace{2cm}
\includegraphics[width=2.65cm,height=2.7cm]{Gaussold.ps}
\end{center}
}

\frame{
\frametitle{5.2.1 Introduction}
\frametitle{Some real--life examples}
\begin{center}
\includegraphics[width=5cm]{HMV.ps}
\hspace{0.4cm}
\includegraphics[width=5cm]{USArain.ps}

\vspace{0.3cm}

\includegraphics[width=5cm]{heights.ps}
\hspace{0.4cm}
\includegraphics[width=5cm]{heathrow.ps}


\end{center}
}
\frame{
\frametitle{5.2.1 Introduction}
\noindent \textbf{Recall the ``parameters'' of the binomial and Poisson distributions:} \pause

\vspl

\begin{itemize}
\item  the \textcolor{purple}{\textbf{binomial distribution}} has two parameters, $n$ and $p$
\vspl
\item  the \textcolor{purple}{\textbf{Poisson distribution}} has one parameter $\lambda$
\vspl
\item  The \textcolor{purple}{\textbf{Normal distribution}} has two parameters: the mean, $\mu$, and the
standard deviation, $\sigma$
\end{itemize}
}

\frame{
\frametitle{5.2.1 Introduction}

\noindent It's probability density function (pdf) has a
``\textcolor{purple}{\textbf{bell--shaped}}'' profile (page 125): \pause
\begin{center}
\psfrag{Probability density}[][]{\sf \small Probability density}
\psfrag{X}[][]{\sf \small $X$}
\includegraphics[width=8cm,height=4cm]{Normalnew.ps}
\end{center}


}

\frame{
\frametitle{5.2.1 Introduction}
\noindent The (rather nasty!) formula for this pdf is
\[
f(x)=\dfrac{1}{\sqrt{2\pi\sigma^2}}
\exp\left\{-\dfrac{(x-\mu)^2}{2\sigma^2}\right\}.
\]
\noindent Unlike the binomial and Poisson distributions, there is \textcolor{purple}{\textbf{no simple formula}} for calculating probabilities. 

\vspace{0.3cm}

\noindent Don't worry though, probabilities from the Normal distribution can be determined using \textcolor{purple}{\textbf{statistical tables}} (see the end of this chapter) or statistical packages such as \texttt{Minitab}. 
}



\frame{
\frametitle{5.2.1 Introduction}
\noindent There are four important characteristics of the Normal distribution:

\vspl

\begin{enumerate}
\item It is \textcolor{purple}{\textbf{symmetrical}} about its mean, $\mu$.

\vspl

\item The mean, median and mode all \textcolor{purple}{\textbf{coincide}}.

\vspl

\item The area under the curve is equal to $1$.

\vspl

\item The curve extends in both directions to infinity ($\infty$).
\end{enumerate}

\vspace{0.3cm}

\noindent \textbf{On the next slide are plots of the pdf for Normal distributions with different
values of $\boldsymbol{\mu}$ and $\boldsymbol{\sigma}$}.
}

\frame{
\frametitle{5.2.1 Introduction}
\psfrag{Normal pdf with mean 30 and sd 10}[][]{\tiny \sf Normal pdf with mean 30 and sd 10}
\psfrag{Normal pdfs with mean 10,30,50 and sd 10}[][]{\tiny \sf Normal pdfs with mean 10, 30, 50 and sd 10}
\psfrag{Normal pdf with mean 30 and sd 10s 5,10,15}[][]{\tiny \sf Normal pdfs with mean 30 and sds 5,10,15}
\psfrag{0}[][]{\tiny \sf 0}
\psfrag{10}[][]{\tiny \sf 10}
\psfrag{20}[][]{\tiny \sf 20}
\psfrag{30}[][]{\tiny \sf 30}
\psfrag{40}[][]{\tiny \sf 40}
\psfrag{50}[][]{\tiny \sf 50}
\psfrag{60}[][]{\tiny \sf 60}
\psfrag{70}[][]{\tiny \sf 70}
\psfrag{80}[][]{\tiny \sf 80}
\psfrag{-20}[][]{\tiny \sf --20}
\psfrag{0.00}[][]{\tiny \sf 0.00}
\psfrag{0.01}[][]{\tiny \sf 0.01}
\psfrag{0.02}[][]{\tiny \sf 0.02}
\psfrag{0.03}[][]{\tiny \sf 0.03}
\psfrag{0.04}[][]{\tiny \sf 0.04}
\psfrag{0.05}[][]{\tiny \sf 0.05}
\psfrag{0.06}[][]{\tiny \sf 0.06}
\psfrag{0.07}[][]{\tiny \sf 0.07}
\psfrag{0.08}[][]{\tiny \sf 0.08}
\psfrag{Density}[][]{\tiny \sf Density}
\psfrag{x}[][]{\tiny $x$}
\begin{center}
\includegraphics[width=4cm,height=2.3cm]{norm1aplot.ps}\\

\includegraphics[width=4cm,height=2.cm]{norm2aplot.ps}\\

\includegraphics[width=4cm,height=2.3cm]{norm3aplot.ps}\\
\end{center}
%\includegraphics[width=4cm]{norm4aplot.ps}
}

\frame{
\frametitle{5.2.2 Notation}

\noindent If a random variable $X$ has a Normal distribution with
mean $\mu$ and variance $\sigma^2$, then we write
\[
X\sim N\left(\mu,\sigma^2\right).
\]
\pause
\noindent For example, a random variable $X$ which follows a Normal distribution with mean \textcolor{blue}{\textbf{10}} and variance \textcolor{blue}{\textbf{25}} is written as 

\begin{eqnarray*}
X	&\sim& N\left(\textcolor{blue}{10},\textcolor{blue}{25}\right)	\qquad \textsf{or}	\\
X	&\sim& N\left(\textcolor{blue}{10},\textcolor{blue}{5^{2}}\right).
\end{eqnarray*}
\pause
\noindent It is important to note that the
second parameter in this notation is the \textcolor{purple}{\textbf{variance}} and not the \textcolor{purple}{\textbf{standard deviation}}.
}



\frame{

\frametitle{5.2.3 The \textcolor{yellow}{\textit{standard}} Normal distribution}
\noindent The \textcolor{purple}{\textbf{Standard}} Normal distribution has a mean of \textcolor{blue}{\textbf{0}} and a variance of \textcolor{blue}{\textbf{1}}.  

\vspace{0.3cm}

\noindent A random variable with this \textit{standard} Normal distribution is usually given the letter $Z$, and so we say
\[
Z\sim N\left(\textcolor{blue}{\textbf{0}},\textcolor{blue}{\textbf{1}}\right).
\]
\pause
\noindent If our random variable follows a \textcolor{purple}{\textbf{standard}} Normal distribution, then we can obtain \textit{cumulative probabilities} from statistical tables (see the table at the end of this chapter, which give ``\textcolor{purple}{\textbf{less than or equal to}}'' probabilities).
}

\frame{
\frametitle{5.2.3 Probability density function for $Z$}

\begin{center}
\includegraphics[width=10cm,height=7cm]{z.ps}
\end{center}
}

\frame{
\frametitle{5.2.3 The \textcolor{yellow}{\textit{standard}} Normal distribution}
\noindent \textbf{For example, if $\boldsymbol{Z \sim N(0,1)}$}:
\pause
\begin{enumerate}
\item [\textbf{1.}] The probability that $Z$ is less
than $-1.46$ is $P(Z<-1.46)$. Therefore we look for the probability in
tables corresponding to $z=-1.46$: row labelled $-1.4$, column headed
$-0.06$.  
\\
\noindent This gives $P(Z<-1.46) = \boldsymbol{0.0721}$.

\vspace{0.3cm}

\pause
\item [\textbf{2.}]  The probability that $Z$ is less
than $-0.01$ is $P(Z<-0.01)$. Therefore we look for the probability in
tables corresponding to $z=-0.01$: row labelled $0.0$, column headed
$-0.01$.  \\
\noindent This gives $P(Z<-0.01) = \boldsymbol{0.4960}$.

\vspace{0.3cm}

\pause
\item[\textbf{3.}] Similarly, $P(Z<0.01)=\boldsymbol{0.5040}$.
\end{enumerate}
}

\frame{
\frametitle{5.2.3 The \textcolor{yellow}{\textit{standard}} Normal distribution}
%\begin{center}
{\tiny
\begin{tabular}{|c|cccccccccc|}
\hline
$z$ & -0.09  & -0.08  & -0.07  & -0.06  & -0.05  & -0.04  & -0.03  & -0.02  & -0.01  &  0.00 \\
\hline
 -2.9  &  0.0014  &  0.0014  &  0.0015  &  0.0015  &  0.0016  &  0.0016  &  0.0017  &  0.0018  &  0.0018  &  0.0019  \\
 -2.8  &  0.0019  &  0.0020  &  0.0021  &  0.0021  &  0.0022  &  0.0023  &  0.0023  &  0.0024  &  0.0025  &  0.0026  \\
 -2.7  &  0.0026  &  0.0027  &  0.0028  &  0.0029  &  0.0030  &  0.0031  &  0.0032  &  0.0033  &  0.0034  &  0.0035  \\
 -2.6  &  0.0036  &  0.0037  &  0.0038  &  0.0039  &  0.0040  &  0.0041  &  0.0043  &  0.0044  &  0.0045  &  0.0047  \\
 -2.5  &  0.0048  &  0.0049  &  0.0051  &  0.0052  &  0.0054  &  0.0055  &  0.0057  &  0.0059  &  0.0060  &  0.0062  \\
 -2.4  &  0.0064  &  0.0066  &  0.0068  &  0.0069  &  0.0071  &  0.0073  &  0.0075  &  0.0078  &  0.0080  &  0.0082  \\
 -2.3  &  0.0084  &  0.0087  &  0.0089  &  0.0091  &  0.0094  &  0.0096  &  0.0099  &  0.0102  &  0.0104  &  0.0107  \\
 -2.2  &  0.0110  &  0.0113  &  0.0116  &  0.0119  &  0.0122  &  0.0125  &  0.0129  &  0.0132  &  0.0136  &  0.0139  \\
 -2.1  &  0.0143  &  0.0146  &  0.0150  &  0.0154  &  0.0158  &  0.0162  &  0.0166  &  0.0170  &  0.0174  &  0.0179  \\
 -2.0  &  0.0183  &  0.0188  &  0.0192  &  0.0197  &  0.0202  &  0.0207  &  0.0212  &  0.0217  &  0.0222  &  0.0228  \\
 -1.9  &  0.0233  &  0.0239  &  0.0244  &  0.0250  &  0.0256  &  0.0262  &  0.0268  &  0.0274  &  0.0281  &  0.0287  \\
 -1.8  &  0.0294  &  0.0301  &  0.0307  &  0.0314  &  0.0322  &  0.0329  &  0.0336  &  0.0344  &  0.0351  &  0.0359  \\
 -1.7  &  0.0367  &  0.0375  &  0.0384  &  0.0392  &  0.0401  &  0.0409  &  0.0418  &  0.0427  &  0.0436  &  0.0446  \\
 -1.6  &  0.0455  &  0.0465  &  0.0475  &  0.0485  &  0.0495  &  0.0505  &  0.0516  &  0.0526  &  0.0537  &  0.0548  \\
 -1.5  &  0.0559  &  0.0571  &  0.0582  &  0.0594  &  0.0606  &  0.0618  &  0.0630  &  0.0643  &  0.0655  &  0.0668  \\
 -1.4  &  0.0681  &  0.0694  &  0.0708  &  0.0721  &  0.0735  &  0.0749  &  0.0764  &  0.0778  &  0.0793  &  0.0808  \\
 -1.3  &  0.0823  &  0.0838  &  0.0853  &  0.0869  &  0.0885  &  0.0901  &  0.0918  &  0.0934  &  0.0951  &  0.0968  \\
 -1.2  &  0.0985  &  0.1003  &  0.1020  &  0.1038  &  0.1056  &  0.1075  &  0.1093  &  0.1112  &  0.1131  &  0.1151  \\
 -1.1  &  0.1170  &  0.1190  &  0.1210  &  0.1230  &  0.1251  &  0.1271  &  0.1292  &  0.1314  &  0.1335  &  0.1357  \\
 -1.0  &  0.1379  &  0.1401  &  0.1423  &  0.1446  &  0.1469  &  0.1492  &  0.1515  &  0.1539  &  0.1562  &  0.1587  \\
 -0.9  &  0.1611  &  0.1635  &  0.1660  &  0.1685  &  0.1711  &  0.1736  &  0.1762  &  0.1788  &  0.1814  &  0.1841  \\
 -0.8  &  0.1867  &  0.1894  &  0.1922  &  0.1949  &  0.1977  &  0.2005  &  0.2033  &  0.2061  &  0.2090  &  0.2119  \\
 -0.7  &  0.2148  &  0.2177  &  0.2206  &  0.2236  &  0.2266  &  0.2296  &  0.2327  &  0.2358  &  0.2389  &  0.2420  \\
 -0.6  &  0.2451  &  0.2483  &  0.2514  &  0.2546  &  0.2578  &  0.2611  &  0.2643  &  0.2676  &  0.2709  &  0.2743  \\
 -0.5  &  0.2776  &  0.2810  &  0.2843  &  0.2877  &  0.2912  &  0.2946  &  0.2981  &  0.3015  &  0.3050  &  0.3085  \\
 -0.4  &  0.3121  &  0.3156  &  0.3192  &  0.3228  &  0.3264  &  0.3300  &  0.3336  &  0.3372  &  0.3409  &  0.3446  \\
 -0.3  &  0.3483  &  0.3520  &  0.3557  &  0.3594  &  0.3632  &  0.3669  &  0.3707  &  0.3745  &  0.3783  &  0.3821  \\
 -0.2  &  0.3859  &  0.3897  &  0.3936  &  0.3974  &  0.4013  &  0.4052  &  0.4090  &  0.4129  &  0.4168  &  0.4207  \\
 -0.1  &  0.4247  &  0.4286  &  0.4325  &  0.4364  &  0.4404  &  0.4443  &  0.4483  &  0.4522  &  0.4562  &  0.4602  \\
 -0.0 &  0.4641  &  0.4681  &  0.4721  &  0.4761  &  0.4801  &  0.4840  &  0.4880  &  0.4920  &  0.4960  &  0.5000  \\
\hline
\end{tabular}
}
%\end{center}
}


\frame{
\frametitle{5.2.3 The \textcolor{yellow}{\textit{standard}} Normal distribution}
%\begin{center}
{\tiny
\begin{tabular}{|c|cccccccccc|}
\hline
$z$ &  0.00  &  0.01  &  0.02  &  0.03  &  0.04  &  0.05  &  0.06  &  0.07  &  0.08  &  0.09 \\
\hline
0.0 & 0.5000 & 0.5040 & 0.5080 & 0.5120 & 0.5160 & 0.5199 & 0.5239 & 0.5279 & 0.5319 & 0.5359 \\
0.1 & 0.5398 & 0.5438 & 0.5478 & 0.5517 & 0.5557 & 0.5596 & 0.5636 & 0.5675 & 0.5714 & 0.5753 \\
0.2 & 0.5793 & 0.5832 & 0.5871 & 0.5910 & 0.5948 & 0.5987 & 0.6026 & 0.6064 & 0.6103 & 0.6141 \\
0.3 & 0.6179 & 0.6217 & 0.6255 & 0.6293 & 0.6331 & 0.6368 & 0.6406 & 0.6443 & 0.6480 & 0.6517 \\
0.4 & 0.6554 & 0.6591 & 0.6628 & 0.6664 & 0.6700 & 0.6736 & 0.6772 & 0.6808 & 0.6844 & 0.6879 \\
0.5 & 0.6915 & 0.6950 & 0.6985 & 0.7019 & 0.7054 & 0.7088 & 0.7123 & 0.7157 & 0.7190 & 0.7224 \\
0.6 & 0.7257 & 0.7291 & 0.7324 & 0.7357 & 0.7389 & 0.7422 & 0.7454 & 0.7486 & 0.7517 & 0.7549 \\
0.7 & 0.7580 & 0.7611 & 0.7642 & 0.7673 & 0.7704 & 0.7734 & 0.7764 & 0.7794 & 0.7823 & 0.7852 \\
0.8 & 0.7881 & 0.7910 & 0.7939 & 0.7967 & 0.7995 & 0.8023 & 0.8051 & 0.8078 & 0.8106 & 0.8133 \\
0.9 & 0.8159 & 0.8186 & 0.8212 & 0.8238 & 0.8264 & 0.8289 & 0.8315 & 0.8340 & 0.8365 & 0.8389 \\
1.0 & 0.8413 & 0.8438 & 0.8461 & 0.8485 & 0.8508 & 0.8531 & 0.8554 & 0.8577 & 0.8599 & 0.8621 \\
1.1 & 0.8643 & 0.8665 & 0.8686 & 0.8708 & 0.8729 & 0.8749 & 0.8770 & 0.8790 & 0.8810 & 0.8830 \\
1.2 & 0.8849 & 0.8869 & 0.8888 & 0.8907 & 0.8925 & 0.8944 & 0.8962 & 0.8980 & 0.8997 & 0.9015 \\
1.3 & 0.9032 & 0.9049 & 0.9066 & 0.9082 & 0.9099 & 0.9115 & 0.9131 & 0.9147 & 0.9162 & 0.9177 \\
1.4 & 0.9192 & 0.9207 & 0.9222 & 0.9236 & 0.9251 & 0.9265 & 0.9279 & 0.9292 & 0.9306 & 0.9319 \\
1.5 & 0.9332 & 0.9345 & 0.9357 & 0.9370 & 0.9382 & 0.9394 & 0.9406 & 0.9418 & 0.9429 & 0.9441 \\
1.6 & 0.9452 & 0.9463 & 0.9474 & 0.9484 & 0.9495 & 0.9505 & 0.9515 & 0.9525 & 0.9535 & 0.9545 \\
1.7 & 0.9554 & 0.9564 & 0.9573 & 0.9582 & 0.9591 & 0.9599 & 0.9608 & 0.9616 & 0.9625 & 0.9633 \\
1.8 & 0.9641 & 0.9649 & 0.9656 & 0.9664 & 0.9671 & 0.9678 & 0.9686 & 0.9693 & 0.9699 & 0.9706 \\
1.9 & 0.9713 & 0.9719 & 0.9726 & 0.9732 & 0.9738 & 0.9744 & 0.9750 & 0.9756 & 0.9761 & 0.9767 \\
2.0 & 0.9772 & 0.9778 & 0.9783 & 0.9788 & 0.9793 & 0.9798 & 0.9803 & 0.9808 & 0.9812 & 0.9817 \\
2.1 & 0.9821 & 0.9826 & 0.9830 & 0.9834 & 0.9838 & 0.9842 & 0.9846 & 0.9850 & 0.9854 & 0.9857 \\
2.2 & 0.9861 & 0.9864 & 0.9868 & 0.9871 & 0.9875 & 0.9878 & 0.9881 & 0.9884 & 0.9887 & 0.9890 \\
2.3 & 0.9893 & 0.9896 & 0.9898 & 0.9901 & 0.9904 & 0.9906 & 0.9909 & 0.9911 & 0.9913 & 0.9916 \\
2.4 & 0.9918 & 0.9920 & 0.9922 & 0.9925 & 0.9927 & 0.9929 & 0.9931 & 0.9932 & 0.9934 & 0.9936 \\
2.5 & 0.9938 & 0.9940 & 0.9941 & 0.9943 & 0.9945 & 0.9946 & 0.9948 & 0.9949 & 0.9951 & 0.9952 \\
2.6 & 0.9953 & 0.9955 & 0.9956 & 0.9957 & 0.9959 & 0.9960 & 0.9961 & 0.9962 & 0.9963 & 0.9964 \\
2.7 & 0.9965 & 0.9966 & 0.9967 & 0.9968 & 0.9969 & 0.9970 & 0.9971 & 0.9972 & 0.9973 & 0.9974 \\
2.8 & 0.9974 & 0.9975 & 0.9976 & 0.9977 & 0.9977 & 0.9978 & 0.9979 & 0.9979 & 0.9980 & 0.9981 \\
2.9 & 0.9981 & 0.9982 & 0.9982 & 0.9983 & 0.9984 & 0.9984 & 0.9985 & 0.9985 & 0.9986 & 0.9986 \\
\hline
\end{tabular}
}
%\end{center}
}

\frame{
\frametitle{5.2.3 The \textcolor{yellow}{\textit{standard}} Normal distribution}
\noindent So far so good?  \pause Hopefully! \pause  But what if we want a ``\textcolor{purple}{\textbf{greater than}}'' probability?  \pause

\vsp

These tables only give ``\textcolor{purple}{\textbf{less than}}'' probabilities! \pause
\vsp

\textbf{Easy!}  Remember, \pause
\vsp
\begin{itemize}
\item The area under the entire curve is equal to 1 \pause
\vspl
\item So we could find the ``\textcolor{purple}{\textbf{less than}}'' probability and then subtract from 1 to get what's left over!
\end{itemize}
}

\sol
\frame{
\frametitle{5.2.3 The \textcolor{yellow}{\textit{standard}} Normal distribution}
\begin{enumerate}
\item [\textbf{4.}] The probability that $Z$ is greater
than $1.5$ is $P(Z>1.5)$.  Now our tables give ``less than'' probabilities, and here we want a ``greater than'' probability. 
\pause

\begin{center}
\includegraphics[width=7.5cm,height=5cm]{blank1.ps}
\end{center}

\pause
\noindent So we find  $P(Z<1.5) = 0.9332$ and subtract this from 1 to give \textbf{0.0668}. 

\end{enumerate}
}

\frame{
\frametitle{5.2.3 The \textcolor{yellow}{\textit{standard}} Normal distribution}
\begin{enumerate}
\item [\textbf{5.}] What about the probability that $Z$ lies between $-1.2$ and $1.5$?  It often helps to think about this graphically.  
\pause

\begin{center}
\includegraphics[width=7.5cm,height=5cm]{blank2i.ps}
\end{center}

\noindent \textcolor{white}{Doing so, gives:}  
\begin{align*}
\textcolor{white}{P(-1.2<Z<1.5)} &\textcolor{white}{= P(Z<1.5) - P(Z< -1.2)}\\
&\textcolor{white}{= 0.9332 - 0.1151}\\
&\textcolor{white}{= 0.8181.}
\end{align*}
\end{enumerate}
}

\frame{
\frametitle{5.2.3 The \textcolor{yellow}{\textit{standard}} Normal distribution}
\begin{enumerate}
\item [\textbf{5.}] What about the probability that $Z$ lies between $-1.2$ and $1.5$?  It often helps to think about this graphically.  

\begin{center}
\includegraphics[width=7.5cm,height=5cm]{blank2ii.ps}
\end{center}

\noindent \textcolor{white}{Doing so, gives:}  
\begin{align*}
\textcolor{white}{P(-1.2<Z<1.5)} &\textcolor{white}{= P(Z<1.5) - P(Z< -1.2)}\\
&\textcolor{white}{= 0.9332 - 0.1151}\\
&\textcolor{white}{= 0.8181.}
\end{align*}
\end{enumerate}
}

\frame{
\frametitle{5.2.3 The \textcolor{yellow}{\textit{standard}} Normal distribution}
\begin{enumerate}
\item [\textbf{5.}] What about the probability that $Z$ lies between $-1.2$ and $1.5$?  It often helps to think about this graphically.  

\begin{center}
\includegraphics[width=7.5cm,height=5cm]{blank2iii.ps}
\end{center}
\pause
\noindent Doing so, gives 
\begin{align*}
P(-1.2<Z<1.5) &= P(Z<1.5) - P(Z< -1.2)\\ 
&= 0.9332 - 0.1151\\ 
&= 0.8181.
\end{align*}
\end{enumerate}
}

\normal

\frame{
\frametitle{5.2.3 The \textcolor{yellow}{\textit{standard}} Normal distribution}
\noindent  So how do we calculate probabilities for \textcolor{purple}{\textbf{any}} Normal distribution, not just the \textcolor{purple}{\textbf{standard}} Normal distribution -- for which we have tables?  \pause

\vspace{0.3cm}

\noindent \textbf{Idea:} ``make'' the Normal distribution that we have ``look like'' the standard Normal distribution, and then we can just use the tables as before!

\vspace{0.3cm}

\noindent \textbf{But how?}  Use the \textcolor{purple}{\textbf{slide--squash}} technique!!
}

\normal

\frame{
\frametitle{Example: IQ of graduates}
\noindent The formula which changes \textcolor{purple}{\textbf{any}} Normal random variable $X$ into the \textcolor{purple}{\textbf{standard}} Normal random variable $Z$ is given by
\begin{eqnarray*}
Z	&=& \frac{X- \mu}{\sigma},
\end{eqnarray*}
where
\begin{itemize}
\item $\mu$ is the mean
\item $\sigma$ is the standard deviation
\end{itemize}
\noindent This can be translated into probability statements:
\begin{eqnarray*}
P(X \leq x) &=& P\left(Z \leq \frac{x-\mu}{\sigma}\right)
\end{eqnarray*}
}

\frame{
\frametitle{Example: IQ of graduates}
\begin{center}
\psfrag{Distribution of IQs}[][]{\sf Distribution of IQs}
\psfrag{-50}[][]{\sf -50}
\psfrag{0}[][]{\sf 0}
\psfrag{50}[][]{\sf 50}
\psfrag{100}[][]{\sf 100}
\psfrag{150}[][]{\sf 150}
\includegraphics[width=11cm,height=7.5cm]{ss0.ps}\end{center}
}

\frame{
\frametitle{Example: IQ of graduates}
\begin{center}
\psfrag{Slide-squash}[][]{\sf Slide--squash}
\psfrag{-50}[][]{\sf -50}
\psfrag{0}[][]{\sf 0}
\psfrag{50}[][]{\sf 50}
\psfrag{100}[][]{\sf 100}
\psfrag{150}[][]{\sf 150}
\includegraphics[width=11cm,height=7.5cm]{ss1.ps}\end{center}
}

\frame{
\frametitle{Example: IQ of graduates}
\begin{center}
\psfrag{Slide-squash}[][]{\sf Slide--squash}
\psfrag{-50}[][]{\sf -50}
\psfrag{0}[][]{\sf 0}
\psfrag{50}[][]{\sf 50}
\psfrag{100}[][]{\sf 100}
\psfrag{150}[][]{\sf 150}
\includegraphics[width=11cm,height=7.5cm]{ss2.ps}\end{center}
}

\frame{
\frametitle{Example: IQ of graduates}
\begin{center}
\psfrag{Slide-squash}[][]{\sf Slide--squash}
\psfrag{-50}[][]{\sf -50}
\psfrag{0}[][]{\sf 0}
\psfrag{50}[][]{\sf 50}
\psfrag{100}[][]{\sf 100}
\psfrag{150}[][]{\sf 150}
\includegraphics[width=11cm,height=7.5cm]{ss3.ps}\end{center}
}

\frame{
\frametitle{Example: IQ of graduates}
\begin{center}
\psfrag{Slide-squash}[][]{\sf Slide--squash}
\psfrag{-50}[][]{\sf -50}
\psfrag{0}[][]{\sf 0}
\psfrag{50}[][]{\sf 50}
\psfrag{100}[][]{\sf 100}
\psfrag{150}[][]{\sf 150}
\includegraphics[width=11cm,height=7.5cm]{ss4.ps}\end{center}
}

\frame{
\frametitle{Example: IQ of graduates}
\begin{center}
\psfrag{Slide-squash}[][]{\sf Slide--squash}
\psfrag{-50}[][]{\sf -50}
\psfrag{0}[][]{\sf 0}
\psfrag{50}[][]{\sf 50}
\psfrag{100}[][]{\sf 100}
\psfrag{150}[][]{\sf 150}
\includegraphics[width=11cm,height=7.5cm]{ss5.ps}\end{center}
}

\frame{
\frametitle{Example: IQ of graduates}
\begin{center}
\psfrag{Slide-squash}[][]{\sf Slide--squash}
\psfrag{-50}[][]{\sf -50}
\psfrag{0}[][]{\sf 0}
\psfrag{50}[][]{\sf 50}
\psfrag{100}[][]{\sf 100}
\psfrag{150}[][]{\sf 150}
\includegraphics[width=11cm,height=7.5cm]{ss6.ps}\end{center}
}

\frame{
\frametitle{Example: IQ of graduates}
\begin{center}
\psfrag{Slide-squash}[][]{\sf Slide--squash}
\psfrag{-50}[][]{\sf -50}
\psfrag{0}[][]{\sf 0}
\psfrag{50}[][]{\sf 50}
\psfrag{100}[][]{\sf 100}
\psfrag{150}[][]{\sf 150}
\includegraphics[width=11cm,height=7.5cm]{ss7.ps}\end{center}
}

\frame{
\frametitle{Example: IQ of graduates}
\begin{center}
\psfrag{Slide-squash}[][]{\sf Slide--squash}
\psfrag{-50}[][]{\sf -50}
\psfrag{0}[][]{\sf 0}
\psfrag{50}[][]{\sf 50}
\psfrag{100}[][]{\sf 100}
\psfrag{150}[][]{\sf 150}
\includegraphics[width=11cm,height=7.5cm]{ss8.ps}\end{center}
}

\frame{
\frametitle{Example: IQ of graduates}
\begin{center}
\psfrag{Slide-squash}[][]{\sf Slide--squash}
\psfrag{-50}[][]{\sf -50}
\psfrag{0}[][]{\sf 0}
\psfrag{50}[][]{\sf 50}
\psfrag{100}[][]{\sf 100}
\psfrag{150}[][]{\sf 150}
\includegraphics[width=11cm,height=7.5cm]{ss9.ps}\end{center}
}

\frame{
\frametitle{Example: IQ of graduates}
\begin{center}
\psfrag{Slide-squash}[][]{\sf Slide--squash}
\psfrag{-50}[][]{\sf -50}
\psfrag{0}[][]{\sf 0}
\psfrag{50}[][]{\sf 50}
\psfrag{100}[][]{\sf 100}
\psfrag{150}[][]{\sf 150}
\includegraphics[width=11cm,height=7.5cm]{ss10.ps}\end{center}
}

\frame{
\frametitle{Example: IQ of graduates}
\begin{center}
\psfrag{Slide-squash}[][]{\sf Slide--squash}
\psfrag{-50}[][]{\sf -50}
\psfrag{0}[][]{\sf 0}
\psfrag{50}[][]{\sf 50}
\psfrag{100}[][]{\sf 100}
\psfrag{150}[][]{\sf 150}
\includegraphics[width=11cm,height=7.5cm]{ss11.ps}\end{center}
}

\frame{
\frametitle{Example: IQ of graduates}
\noindent What is the probability that a graduate applicant has an IQ less than 85?
\pause
\begin{eqnarray*}
P(X<85)	&=& P\left(Z<\frac{X-\mu}{\sigma}\right)	\\
\pause
	& &						\\
	&=& P\left(Z< \frac{85-100}{15}\right)	\\
\pause
	& &					\\
	&=& P(Z<-1)		\\
\pause
	& &			\\
	&=& 0.1587.  
\end{eqnarray*}
}

\sol

\frame{
\frametitle{Example: Solution to (i)}
\begin{eqnarray*}
P(X<110)	&=&	P\left(Z<\frac{X-\mu}{\sigma}\right)	\\
\pause
		& &						\\
		&=&	P\left(Z<\frac{110-100}{15}\right)	\\
\pause
		& &						\\
		&=&	P(Z<0.67)				\\
\pause
		& &						\\
		&=& 	0.7486.
\end{eqnarray*}
}

\frame{
\frametitle{Example: Solution to (ii)}
\begin{eqnarray*}
P(X>110)	&=& 1-P(X<110)	\\
\pause
		& &		\\
		&=& 1-0.7486	\\
\pause
		& &		\\
		&=& 0.2514. 
\end{eqnarray*}
}

\frame{
\frametitle{Example: Solution to (iii)}
\begin{eqnarray*}
P(X>125)		&=& 1-P(X<125)	\\
\pause
			& &		\\
			&=& 1-P\left(Z<\frac{125-100}{15}\right)	\\
\pause
			& &			\\
			&=& 1-P(Z<1.67)			\\
\pause
			& &					\\
			&=& 1-0.9525				\\
\pause
			& &				\\
			&=& 0.0475.
\end{eqnarray*}
}



\frame{
\frametitle{Example: Solution to (iv)}
\begin{eqnarray*}
P(95<X<115)	&=& P(X<115) - P(X<95)	\\
\pause
		& &			\\
		&=& P\left(Z<\frac{115-100}{15}\right) \pause - P\left(Z<\frac{95-100}{15}\right)	\\
\pause
		& &				\\
		&=& P(Z<1)	\pause -	P(Z<-0.33)		\\
\pause
		& &			\\
		&=& 0.8413 \pause - 0.3707	\\
\pause
		& &			\\
		&=& 0.4706.
\end{eqnarray*}
}


\normal

\frame{
\frametitle{Example 5.1}
You work as part of the design team for a social networking website.  You are interested in the amount of time, $X$ seconds, it takes users of your website to download a video. 

\vsp

 A random sample of downloads gives a mean download time of 7 seconds, with a standard deviation of 2 seconds. 

\vsp

What is the probability that it will take a user of your website in the future
\begin{itemize}
\item [\textbf{(a)}] more than 8.5 seconds;
\item [\textbf{(b)}] less than 2.5 seconds;
\item [\textbf{(c)}] between 2.5 and 8.5 seconds
\end{itemize}
to download this video?
}

\sol

\frame{
\frametitle{Example 5.1(a): Solution}
\begin{eqnarray*}
P(X>8.5)   &=& P\left(Z>\frac{8.5-7}{2}\right) \\
           & & \\ \pause
           &=&P(Z>0.75) \\\pause
           & & \\
           &=&1-P(Z<0.75) \\ \pause
           & & \\
           &=&1-0.7734 \pause = 0.2266.
\end{eqnarray*}
}

\frame{
\frametitle{Example 5.1(b): Solution}
\begin{eqnarray*}
P(X<2.5)   &=&P\left(Z<\frac{2.5-7}{2}\right) \\\pause
           & & \\
           &=&P(Z<-2.25) \\ \pause
           & & \\
           &=&0.0122.
\end{eqnarray*}
}

\frame{
\frametitle{Example 5.1(c): Solution}
\begin{eqnarray*}
P(2.5<X<8.5)  &=&P(X<8.5) - P(X<2.5) \pause \\
              & & \\
              &=&0.2266-0.0122 \pause = 0.2144.
\end{eqnarray*}
}


\normal

\frame{
\frametitle{5.3 More Continuous Probability Models}
Over the past few weeks we have discussed some ``standard'' probability distributions which can be used to model data.  

\vsp

We have looked at two such distributions for \textcolor{purple}{\bf discrete} data -- the binomial distribution and the Poisson distribution -- and last week the Normal distribution was introduced as a probability model for \textcolor{purple}{\bf continuous} data.  
}


\frame{
\frametitle{5.3 More Continuous Probability Models}
\noindent Recall the \textcolor{purple}{\bf probability density function} of the Normal distribution, which is often referred to as a ``bell--shaped curve'':

\vspace{2.8cm}

\begin{center}
\psfrag{The Normal Distribution}[][]{}
\includegraphics[width=5cm,height=5cm,angle=-90]{normal.ps}  
\end{center}
}


\frame{
\frametitle{5.3 More Continuous Probability Models}
\noindent We saw in the lecture last week that many naturally occurring continuous measurements (such as height, weight, time, rainfall etc.) often resemble this bell--shaped curve when plotted using a histogram, for example.  \pause

\vsp

But what if we cannot assume ``Normality'' for our data? \pause

\vsp

\noindent We now consider two other probability models which can be used to model continuous data when the Normal distribution isn't appropriate.  
}


\frame{
\frametitle{5.3 Example of ``non--Normality''}
\begin{itemize}
\item You manage a group of Environmental Health Officers and need to decide at
what time they should inspect a local hotel  \pause
\vspl
\item You decide that any time
during the working day (9.00 to 18.00) is okay \pause
\vspl
\item You want to decide
the time ``randomly''
\end{itemize} \pause

\vsp

\noindent Here, ``\textcolor{purple}{\textbf{randomly}}'' is a short--hand for 
\begin{center}
``\textit{a random time, where all times in the working day \\
are equally likely to be chosen}''
\end{center}
}

\frame{
\frametitle{5.3.1 The Uniform distribution}
\noindent Let $X$ be the time to their arrival at the hotel, measured
in terms of minutes from the start of the day. 

\vspace{0.3cm}

\noindent Then $X$ is a \textcolor{purple}{\textbf{Uniform}}
random variable between $0$ and $540$ (page 134):

\begin{center}
\includegraphics[width=10cm]{uniform.ps}
\end{center}
}

\frame{
\frametitle{5.3.1 The Uniform distribution}
\noindent As with the Normal distribution, the total area ($\text{\sf base}\times\text{\sf height}$) under the pdf must
equal one. 

\vspace{0.3cm}

\noindent Therefore, as the base is $540$, the height must be
$1/540$. 

\vspace{0.3cm}

Hence the \textcolor{purple}{\textbf{probability density function}} (pdf) for the
continuous random variable $X$ is
\[
f(x)= 
\begin{cases}
\dfrac{1}{540}&\text{for }0\leq x \leq 540\\
0 &\text{otherwise}.
\end{cases}
\]
}

\frame{
\frametitle{5.3.1 The Uniform distribution}
\noindent In general, we say that a random variable $X$ which is equally likely to
take any value between $a$ and $b$ has a \textcolor{purple}{\bf uniform distribution} on the
interval $\boldsymbol{a}$ to $\boldsymbol{b}$, i.e.
\begin{eqnarray*}
X	&\sim&	U(a, b).
\end{eqnarray*}
}

\frame{
\frametitle{5.3.1 The Uniform distribution}
\noindent The random variable has \textcolor{purple}{\textbf{probability density
function}} (pdf) 
\[
f(x)= 
\begin{cases}
\dfrac{1}{b-a}&\text{for }a\leq x \leq b\\
0 &\text{otherwise}
\end{cases}
\]
\pause
and probabilities can be calculated using the formula
\[
P(X\leq x)= 
\begin{cases}
0&\text{for }x<a\\
\dfrac{x-a}{b-a}&\text{for }a\leq x \leq b\\
1 &\text{for }x>b.
\end{cases}
\]
}
\frame{
\frametitle{5.3.1 The Uniform distribution}
\noindent Therefore, for example, the \textcolor{purple}{\textbf{probability that the inspectors visit
the hotel in the morning}} (within 180 minutes after 9am) is
\[
P(X\leq 180)=\pause\dfrac{180-0}{540-0}=\pause\frac{1}{3}.
\]
}

\frame{
\frametitle{5.3.1 The Uniform distribution}
\noindent The \textcolor{purple}{\textbf{probability of a visit during the lunch hour}} (12.30 to 13.30) is
\begin{eqnarray*}
P(210\leq X\leq 270)&=&P(X\leq 270)-P(X<210)\\
\pause
&=&\frac{270-0}{540-0}~-\frac{210-0}{540-0}\\
\pause
& &			\\
&=&\frac{270-210}{540}\\
& & \\
\pause
&=&\frac{60}{540}\\
& & \\
&=&\frac{1}{9}.
\end{eqnarray*}
}

\frame{
\frametitle{5.3.1 Uniform distribution: Mean and Variance}
\noindent \textbf{Recall that:}

\vsp

\begin{itemize}
\item If $X \sim \textsf{bin}(n, p)$, then
\vspl
\begin{itemize} 
\item [--] $E(X) = n \times p$	and
\vspl
\item [--] $\textsf{Var}(X) = n \times p \times (1-p)$
\end{itemize}

\vspace{0.3cm}

\pause
\item If $X \sim \textsf{Po}(\lambda)$, then
\vspl
\begin{itemize}
\item [--] $E(X) = \lambda$ and
\vspl
\item [--] $\textsf{Var}(X) = \lambda$
\end{itemize}
\end{itemize}
}

\frame{
\frametitle{5.3.1  Uniform distribution: Mean and Variance}
\noindent We have equivalent formulae for $X \sim U(a,b)$:
\begin{eqnarray*}
E(X) 		&=& \frac{a+b}{2} 	\\
& & \\
\textsf{Var}(X)	&=& \frac{(b-a)^2}{12}.
\end{eqnarray*}
}

\frame{

\frametitle{5.3.1  Uniform distribution: Mean and Variance}
\noindent In the above example, we have
\begin{align*}
E(X)&=\frac{a+b}{2}=\frac{0+540}{2}=270,
\end{align*}
\noindent so that the mean arrival of the inspectors is 
9am + 270 minutes = 13.30. 

\pause

\vspace{0.3cm}

Also
\begin{align*}
\textsf{Var}(X)&=\frac{{(540-0)}^2}{12}=24300,
\end{align*}
and therefore \pause $SD(X)=\sqrt{Var(X)}=\sqrt{24300}=155.9$ minutes.
}

\frame{
\frametitle{5.3.2 The Exponential distribution}

\noindent The \textcolor{purple}{\textbf{exponential distribution}} is another common distribution
that is used to describe continuous random variables.  

\vspace{0.3cm}

\pause
\noindent It is
often used to model lifetimes of products and times between
``random'' events, for example:
\vsp
\begin{itemize}
\item Lifetime of light bulbs
\vspl
\item Arrival of customers in a queueing
system 
\vspl
\item Arrival of orders
\end{itemize} \pause

\vspl

\noindent The distribution has one parameter, $\lambda$.  If our random variable $X$ follows an \textcolor{purple}{\textbf{exponential distribution}}, then we say
\begin{eqnarray*}
X	&\sim&	\textsf{exp}(\lambda).
\end{eqnarray*}
}


\frame{
\frametitle{5.3.2 The Exponential distribution}
\noindent  Its \textcolor{purple}{\textbf{probability
density function}} is
\[
f(x)=
\begin{cases}
\lambda e^{- \lambda x}& \text{for }x\geq 0,\\
0&\text{otherwise}
\end{cases}
\]
\pause
and probabilities can be calculated using
\[
P(X\leq x)=
\begin{cases}
0&\text{for }x<0\\
1-e^{- \lambda x}& \text{for }x>0.
\end{cases}
\]
}

\frame{
\frametitle{5.3.2 The Exponential distribution}
\noindent The main \textcolor{purple}{\textbf{features}} of this distribution are:
\vsp
\begin{enumerate}
\item an exponentially distributed random variable can only take \textbf{positive} values
\vspl
\item larger values are \textbf{increasingly unlikely} -- ``\textcolor{purple}{\textbf{exponential decay}}''
\vspl
\item the value of $\lambda$ fixes the \textbf{rate of decay} -- \textit{larger values
correspond to more rapid decay}.
\end{enumerate}
}

\sol

\frame{
\frametitle{5.3.2 The Exponential distribution}
\begin{center}
\psfrag{Density}[][]{\tiny \sf Density}
\psfrag{lambda=1}[][]{\tiny \sf $\lambda=1$}
\psfrag{lambda=5}[][]{\tiny \sf $\lambda=5$}
\psfrag{lambda=10}[][]{\tiny \sf $\lambda=10$}
\psfrag{lambda=20}[][]{\tiny \sf $\lambda=20$}
\includegraphics[width=11cm,height=6.5cm]{exp.ps}  
\end{center}

}

\normal

\frame{
\frametitle{5.3.2 The Exponential distribution}
\noindent Consider an example in which the time (in minutes) between successive
users of a self--service supermarket checkout can be modelled by an exponential distribution
with $\lambda = 0.3$. 

\vspace{0.3cm}

\pause

\noindent The probability of the gap between phone users
being less than 5 minutes is
\begin{eqnarray*}
P(X<5)&=&1-e^{-0.3\times 5}\\ \pause
     &=&1-0.223 \pause =0.777.
\end{eqnarray*}
}

\frame{
\frametitle{5.3.2 The Exponential distribution}
\noindent Also the probability that the gap is more than 10 minutes is
\begin{eqnarray*}
P(X>10)&=&1-P(X< 10)\\ \pause
       &=&1-\left(1-e^{-0.3\times 10}\right)\\ \pause
       &=&e^{-0.3\times 10} \pause =0.050
\end{eqnarray*}
\pause
and the probability that the gap is between 5 and 10 minutes is
\begin{eqnarray*}
P(5<X<10)&=&P(X<10)-P(X< 5) \pause \\
         &=&0.950 - 0.777 \pause = 0.173.
\end{eqnarray*}
}

\frame{

\frametitle{5.3.2 The Exponential distribution}
\noindent One of the main uses of the exponential distribution is as a model for
the \textbf{times between events occurring randomly in time}. 

\vspace{0.3cm}

\noindent We have previously considered events which occur at random points in time in connection with the \textcolor{purple}{\textbf{Poisson distribution}}. 

\vspace{0.3cm}

\noindent The Poisson distribution describes probabilities for the number of events taking place in a
given time period. 

\vspace{0.3cm}

\noindent The exponential distribution describes probabilities for the times between events. Both of these concern events occurring randomly
in time (at a constant average rate, say $\lambda$). This is known as a
\textcolor{purple}{\textbf{Poisson process}}.
}

\frame{

\frametitle{5.3.2 The Exponential distribution}
\noindent Consider a series of randomly occurring events such as calls at a
credit card call centre. The times of calls might look like
\begin{center}
\psfrag{0}{$0$}
\psfrag{1}{$1$}
\psfrag{2}{$2$}
\psfrag{3}{$3$}
\psfrag{4}{$4$}
\psfrag{5}{$5$}
\includegraphics[height=1cm]{line.ps}
\end{center}
\pause
\noindent We can view these data in \textcolor{purple}{\textbf{two ways}}:
\pause
\vsp
\begin{itemize}
\item The number of
calls in each minute (here 2, 0, 2, 1 and 1) 
\pause
\vspl
\item the
times \textit{between} successive calls
\end{itemize}
}

\frame{
\frametitle{5.3.2 The Exponential distribution}
\noindent  For the \textcolor{purple}{\textbf{Poisson process}}, 
\vsp

\begin{itemize}
\item the number of calls has a \textbf{Poisson} distribution with
parameter~$\lambda$, and
\vspl
\item the time between successive calls has an \textbf{exponential}
distribution with parameter~$\lambda$.
\end{itemize}
}

\frame{
\frametitle{5.3.2 Exponential distribution: Mean and Variance}

\noindent The mean and variance of the exponential distribution can be
shown to be
\[
E(X)=\frac{1}{\lambda},\qquad
\textsf{Var}(X)=\frac{1}{\lambda^2}.
\]
}

\frame{
\frametitle{Example 5.2}
 According to \textsf{Apple}'s technical support site, \texttt{www.apple.com/support/itunes}, downloading an iPod game using a broadband connection should take 3 to 6 minutes.   

\vsp

Assuming that download times are uniformly distributed between 3 and 6 minutes, if you download a game what is the probability that the download time will be
\begin{itemize}
\item [\textbf{(a)}] less than 3 minutes 15 seconds?
\item [\textbf{(b)}] More than 5 minutes?
\item [\textbf{(c)}] More than 7 minutes?
\item [\textbf{(d)}] What are the mean and standard deviation download times?
\end{itemize}
}

\sol

\frame{
\frametitle{Example 5.2(a): Solution}
Let $X$: Time taken to download a game (minutes).  \pause Then $X \sim U(3,6)$. \pause

\vsp

So \pause
\begin{eqnarray*}
P(X<3.25)  &=& \frac{3.25-3}{6-3} \pause = \frac{1}{12} = 0.0833.
\end{eqnarray*}
}
\frame{
\frametitle{Example 5.2(b),(c): Solution}
Similarly, \pause
\begin{eqnarray*}
P(X>5)  &=&1 - P(X<5) \pause \\
 & & \\
        &=&1-\frac{5-3}{6-3} = \pause \frac{1}{3} = 0.3333. \pause
\end{eqnarray*}
Also, $P(X>7) = \pause 0$... why?
}

\frame{
\frametitle{Example 5.2(d): Solution}
If $X \sim U(a,b)$,
\[
E[X] = \frac{a+b}{2} \qquad \textsf{and} \qquad \textsf{Var}(X) = \frac{(b-a)^{2}}{12}.
\] \pause

So we have 
\[
E[X] = \frac{3+6}{2} = 4.5 \textsf{ minutes}
\]
and
\[
\textsf{SD}(X) = \sqrt{\frac{(6-3)^{2}}{12}} = 0.866 \textsf{ minutes}
\]
}

\normal

\frame{
\frametitle{Example 5.3}
Customers arrive at the drive--through window of a fast food restaurant at a rate of 2 per minute during the lunch hour.  
\begin{itemize}
\item [\textbf{(a)}] What is the probability that the next customer will arrive within 1 minute?
\item [\textbf{(b)}] What is the probability that the next customer will arrive within 20 seconds?
\item [\textbf{(c)}] What is the mean time between arrivals at the drive--through window? What about the standard deviation?
\end{itemize}
}

\sol

\frame{
\frametitle{Example 5.3(a),(b): Solution}
Let $X$: Time between arrivals at the drive--through window (minutes); $X \sim \textsf{exp}(2)$. \pause Then
\begin{eqnarray*}
P(X<1)  &=& 1-e^{-2\times 1} \pause \\
        &=& 0.865.
\end{eqnarray*}
Similarly,
\begin{eqnarray*}
P\left(X<\frac{1}{3}\right)  &=& 1-e^{-2 \times \frac{1}{3}} \pause \\
        &=&0.487
\end{eqnarray*}
}

\frame{
\frametitle{Example 5.3(c): Solution}
If $X \sim \textsf{exp}(\lambda)$, then 
\[
E[X] = \frac{1}{\lambda} \qquad \textsf{and} \qquad \textsf{Var}(X) = \frac{1}{\lambda^{2}}.
\] \pause

Thus, in our example,
\[
E[X] = \frac{1}{2} = 0.5 \textsf{ minutes} = 30 \textsf{ seconds},
\] \pause
and 
\[
\textsf{SD}(X) = \sqrt{\frac{1}{2^{2}}} = \sqrt{\frac{1}{4}} = 30 \textsf{ seconds}.
\]
}



\normal


\frame{

\vspace{1cm}

\huge
\textbf{Chapter 6}

\vspace{1cm}

\Large
\textbf{Statistical inference} 

\textbf{for the population mean}

}

\frame{
\frametitle{What we'll cover...}
\begin{itemize}
\item \textcolor{purple}{\bf Confidence intervals} \pause
\vspl
\item One sample \textcolor{purple}{\bf hypothesis tests} for the mean \pause
\vspl
\item Two sample \textcolor{purple}{\bf hypothesis tests} for the mean \pause
\end{itemize}
}


\frame
{
\frametitle{6.1 Introduction}
\noindent \textbf{What does our sample tell us about the population?}
\pause

\vsp

\begin{itemize}
\item We can rarely observe the entire population, so the \textbf{\textcolor{purple}{population mean}} and \textbf{\textcolor{purple}{population variance}} are hardly ever known \textit{exactly};
\pause
\item These unknown quantities are called \textbf{\textcolor{purple}{parameters}};
\pause
\item We use Greek letters to denote them -- $\mu$ for the mean, and $\sigma^{2}$ for the variance (and so $\sigma$ for the standard deviation);
\pause
\item We hope that the \textbf{\textcolor{purple}{sample mean}} ($\bar{x}$) will be quite close to the true mean ($\mu$);
\pause
\item \textbf{But how do we know if it is?}
\end{itemize}
}


\frame{
\frametitle{Example: \textit{The Vintage Clothing Co.}}

\noindent The \textit{Vintage Clothing Co.} are a large retailer of bespoke and retro clothing.  \pause

\vsp

They have 1,000 branches across the U.K., and all of their branches are open on Sundays. \pause

\vsp

 However, they are considering whether or not it is worthwhile staying open on Sundays.  \pause

\vsp


The table overleaf shows the number of transactions at each of their shops on Sunday 24th February 2013.    
}

\frame{
\frametitle{Example: \textit{The Vintage Clothing Co.}}
%\begin{table}[!h]
\begin{center}

\tiny \hspace*{-5mm}
\begin{tabular}{|rrrrrrrrrr|rrrrrrrrrr|}
\hline
282&258&399&271&343&285&247&513&171&123&168&327&430&240&410&341& 90&512&245&336\\
290&263&446&185&330&111&243&376&139&351&311&389&546&321&393&487&287&514&149&315\\
264&320&217&257&349&640& 97&298&393&454&363&354&360&326&199&502&154&273&213&413\\
293&407&362&270&344&263&290&263& 50&253&345&581&229&264&304&394&246&235&417&452\\
499&276&412&323&310&177&248&178&409&275&278&307&495&515&232&432&577&269&370&248\\
339&404&371&262&336&218&274&483&211&245&316&381&432&233&223&447&412&250&262&337\\
202&133&356&408&224&379&197&278&235&509&171&232&429&315&326&602& 63&290&230&121\\
242&389&219&206&393&437&306&152&294&271&230&398&346&344&379&347&468&300&325&237\\
305&174&291&261&214&532&335& 63&100&357&190&347&208&420&322&463&203&216&356&504\\
389&236&445&378&255&301&308&150&289&453&464&273&211&450&222&250&214&259&296&356\\
\hline
320&420&357&160&372& 99&316&218&248&322&145&399&433&393&403&361&241&234&388&255\\
261&279&369&342&168&322&304&254& 99&503&303&212&105&166&257&422&460&331&288&410\\
346&370&235&355& 65&340&420&338&568&644&164&288&319&159&324&208&452&297&305&259\\
268&340&305&361&319&519&293&380&286&431&402&329&363&330&612&248&302&592&589&349\\
446&588&304&454&164&240&293&478&540&339&245&257&222&471&469&273&244&126&174&183\\
277&216&555&401&380&338&212&476& 77&363&140&451&329& 66&217&461&435&380&314&324\\
522&111&119&316&116&471&142&336&277&101&518&264&226&256&539&324&320&292&476&324\\
333&332&404&362&202&204&341& 80&333&267&439&136&343&389&244&370&268&362&317&400\\
372&595&314&182&470&192&555&374&368&192&225&321&435&403&316&312&307&368&236&452\\
192& 63&407&125&253& 89& 70&186&491&342&122&367&106&334&161&177&180&355&356&317\\
\hline
454&122&286& 39&361&262&316&272&285&201&191&162&229&334&278&231&154&290&277&392\\
644&297&398&118&246&148&478&167&337&344&395&334&255&401&504&304&408&204&673&126\\
192&507& 41&457&405&306&282&446&195&512&252&510&557&191&321&404&542&438&291&449\\
377&240&441&308&346&265&375&332&580&130&353&426& 95&588&332&109&467&333&388&309\\
263&529&172&529&315&257&481&260&297&382&438& 64&226&185&369&275&320&126&321&375\\
190&340&337&224&363&212&371&229&175&388&332&315&389&452&266&393&323&253&280&420\\
219&400&378&241&616&551&359&489&314&450&645&224&320&405&182&251&370&341&318&232\\

240&471&293&240&184&296&617&565&206&147&169&401&140&462&389&310&262&334&263&269\\
323&351&187&544&387&425&353&175&378&484&205&295&413&189&559&251&480&283&262&304\\
213&574&579&325&246&206&419&306&471&264&270&300&278&131&561&328&440&514&280&391\\
\hline
281&403&256&348&183&161&444&482&338&268&313&252&179&414&444&266&400&435&433&506\\
203&269&450&322&459&183&212&242&144&406&401&174&605&270&487&494&235&316&368&319\\
260&254&157&377&145&284&401&220&452& 59&335&467&251&192&371&298&317&382&363&397\\
282&303&328&378&363&636&374&143&495&239&423&496&411&462&282&411&203&395&590&388\\
278&272&417&666&233&316&287&268&186&247&339&397&276&291&324& 81&271&399&129&325\\
247&152&315&224&130&323&352&276&398&338&231&258&310&421&215& 85&237&356&439&348\\
507&277&240&188&321&419&370&374&211&224&340&264&441&226&563&279&297&114&546&277\\
281&196&498&375&348&234&469&103&324&643&315&293&444&109&408&100&477&293&138&206\\
485&279&494&513& 97&293&669&312&425& 70&181&210&241&187&448& 55&253&564&404&382\\
 31&496&234&200&411&386&218&382&483&405&435&414&379&360&194&291&393&247&314&285\\
\hline
204&188&444&416&106&485&276&250&248&200&352&463&251&197&197&456&293&333&373&240\\
295&297&271&141&319&256&197&110&338&237&249&291&393&437&432&274&202&182&176&212\\
482& 96&272&296&323&289&285&160&203&336&217&321&202&266&253&436&390&259&596&383\\
236&291&226&250&270&439&360&310&326&415&447&336&354&273&243&390&213&318&346&599\\
637&255& 61&393&324&492&484&259&271&150&550&185&224&352&387&441&232&261&313&410\\
246&529& 97&448&369&199&140&498&287&293&258&431&267&396&217&340&278&297&387&281\\
162&237&305&239&246&412&632&385&342&340&673&414&298&383&152&438&408&452&492&603\\
439&223&404&466&380&214&155&410&291&234&248&325&391&338&416&262&361&358&484&129\\
152&363& 90&383&365&500&362&190&343&138&233&179&200&476&128&308&221&649&278&152\\
525&275&355&585&394&183&488&323&312&595&257&434&160&375&478&353&239&331&426&477\\
\hline
\end{tabular}
\end{center}
}


\frame{
\frametitle{Example: \textit{The Vintage Clothing Co.}}
 Suppose the marketing department of \textit{The Vintage Clothing Co.} are interested in the \textcolor{purple}{\bf average number of transactions} across all their stores on Sunday 24th February 2013.  \pause


\vsp

Can we work this out \textit{exactly}?  \pause

\vsp

\noindent The answer is ``yes'' \pause --- we have data from every single branch! \pause

\vsp

  Actually, the table of results shows we have taken a \textcolor{purple}{\bf census} -- every single branch has been asked to provide us with data.  \pause

\vsp

So in this case, it is possible to work out the \textcolor{purple}{\bf population mean} $\mu$: \pause
\[
\mu =\frac{282+258+399+271+ \ldots + 426 + 477}{1000} = 320\textrm{ \sf transactions.}
\]
}


\frame{
\frametitle{Example: \textit{The Vintage Clothing Co.}}
\noindent Now, let's suppose the company don't have the \textcolor{purple}{\bf time}/\textcolor{purple}{\bf resources} to take a census.  \pause

\vsp

In fact, a week before the 24th February, just \textcolor{purple}{\bf five stores} are selected at random --- \pause we work out the mean number of transactions using the data from these five stores only.  \pause


\vsp

Let's suppose the top left--hand block of the table is for stores 1--100, the next block is for stores 101--200, etc. \pause

\vsp

 We put the numbers 1--1000 into a bag and draw, without replacement, \textcolor{purple}{\bf 5 numbers at random}.
}


\frame{
\frametitle{Example: \textit{The Vintage Clothing Co.}}

\begin{center}
\begin{tabular}{c| c}
Store         &No. of transactions, $X$ \\ \hline
637           &$x_{1}=374$          \\
327           &$x_{2}=452$          \\
849           &$x_{3}=271$          \\
666           &$x_{4}=419$          \\
680           &$x_{5}=643$          \\
\end{tabular}
\end{center}
\pause

\noindent Let's suppose this is the only information we have.  \pause


\vsp

It is no longer possible to work out the true population mean, as we don't have information from every single shop; \pause we can now only work out the \textcolor{purple}{\bf sample mean} $\bar{x}$: \pause
\[
\bar{x} = \frac{374+452+271+419+643}{5} = 431.8 \approx 432 \textrm{ \sf transactions.}
\]
}

\frame{
\frametitle{Example: \textit{The Vintage Clothing Co.}}
\noindent Obviously, the marketing team are not just interested in what goes on in these five shops. \pause

\vsp

However, this is the only information they have, and so they use this information to draw conclusions about all 1,000 shops as a whole.  \pause


\vsp

This is known as the process of \textcolor{purple}{\bf statistical inference} -- we are trying to \textit{infer} things about the population, based on the limited information in our sample. \pause


\vsp

 Hopefully, provided we don't have a \textcolor{purple}{\bf biased sample}, $\bar{x}$ will do a good job at estimating $\mu$.  Has it done a good job here?
}

\sol

\frame{
\frametitle{Example: \textit{The Vintage Clothing Co.}}
The true \textcolor{purple}{\bf population mean} is $\mu=320$.  \pause
 
\vsp

Our \textcolor{purple}{\bf sample mean} is $\bar{x}\approx 432$.  \pause

\vsp

We have \textcolor{purple}{\bf over--estimated} the population mean by quite a bit \pause -- our estimate is 112 too high!  \pause

\vsp

Perhaps we have a \textcolor{purple}{\bf biased sample} -- we seem to have selected a number of stores with a higher--than--average number of transactions -- especially store 680!}

\normal

\frame{
\frametitle{Example: \textit{The Vintage Clothing Co.}}
 This begs the question: \pause

\begin{center}``\textit{How accurate can our sample mean be in estimating the population mean?}''
\end{center}

\pause

 Let's take another random sample by drawing another five numbers from the bag: \pause

\begin{center}
\begin{tabular}{c| c}
Store         &No. of transactions, $X$ \\ \hline
558           &$x_{1}=253$          \\
428           &$x_{2}=446$          \\
903           &$x_{3}=251$          \\
364           &$x_{4}=256$          \\
14            &$x_{5}=185$          \\
\end{tabular}
\end{center}

\pause

\noindent This gives
\[
\bar{x} = \frac{253+446+251+256+185}{5} = 278.2 \approx 278 \textrm{ \sf transactions.}
\]
}


\frame{
\frametitle{Example: \textit{The Vintage Clothing Co.}}
This sample mean is much closer to the population mean, but still not \textit{very} close. \pause

\vsp

Also, it is quite different from the mean of the previous sample. \pause

\vsp

You could repeat this procedure yourself (filling in the table on page 146) to select three more random samples of size 5, and calculate the sample
means. \pause

\vsp

In fact, consider this \textcolor{purple}{\bf homework} to do before the next practical session!
}

\frame{
\frametitle{Example: \textit{The Vintage Clothing Co.}}

\begin{center}
\begin{tabular}{ccc}
\multicolumn{1}{l}{\textbf{Your random sample 1}}\hspace*{1cm}\\
\noalign{\medskip}
$u=$\hspace*{1.75cm}&$store=$\hspace*{1.75cm}&$x_1=$\hspace*{1.75cm}\\
\noalign{\medskip}
$u=$\hspace*{1.75cm}&$store=$\hspace*{1.75cm}&$x_2=$\hspace*{1.75cm}\\
\noalign{\medskip}
$u=$\hspace*{1.75cm}&$store=$\hspace*{1.75cm}&$x_3=$\hspace*{1.75cm}\\
\noalign{\medskip}
$u=$\hspace*{1.75cm}&$store=$\hspace*{1.75cm}&$x_4=$\hspace*{1.75cm}\\
\noalign{\medskip}
$u=$\hspace*{1.75cm}&$store=$\hspace*{1.75cm}&$x_5=$\hspace*{1.75cm}\\
\noalign{\medskip}
\cline{3-3}
\noalign{\medskip}
&&$\bar x=$\hspace*{1.75cm}
\end{tabular}
\end{center}
\pause

How close are these sample means to the correct population
value $\mu=320 \textrm{ \sf transactions}$? 
}



\frame{
\frametitle{Example: \textit{The Vintage Clothing Co.}}
\noindent In fact, we could take many samples, and it's very likely that we'll get a \textcolor{purple}{\bf different value} for $\bar{x}$ each time. \pause

\vsp

It's also very \textit{unlikely} that any of our $\bar{x}$'s will be exactly the same as the \textcolor{purple}{\bf true population mean} $\mu$. \pause

\vsp

The graph on the next slide shows histograms of $\bar{x}$'s taken from 100 samples from our population of 1,000 stores. 
}

\frame{
\frametitle{Example: \textit{The Vintage Clothing Co.}}
\begin{center}
\psfrag{0}[][]{\sf \tiny 0}
\psfrag{5}[][]{\sf \tiny 5}
\psfrag{10}[][]{\sf \tiny 10}
\psfrag{15}[][]{\sf \tiny 15}
\psfrag{20}[][]{\sf \tiny 20}
\psfrag{150}[][]{\sf \tiny 150}
\psfrag{200}[][]{\sf \tiny 200}
\psfrag{250}[][]{\sf \tiny 250}
\psfrag{300}[][]{\sf \tiny 300}
\psfrag{350}[][]{\sf \tiny 350}
\psfrag{400}[][]{\sf \tiny 400}
\psfrag{450}[][]{\sf \tiny 450}
\psfrag{500}[][]{\sf \tiny 500}
\psfrag{25}[][]{\sf \tiny 25}
\psfrag{30}[][]{\sf \tiny 30}
\psfrag{40}[][]{\sf \tiny 40}
\psfrag{xbar}[][]{\sf \scriptsize $\bar{x}$}

\psfrag{n=5}[][]{\sf \small $n=5$}
\psfrag{n=10}[][]{\sf \small $n=10$}
\psfrag{n=50}[][]{\sf \small $n=50$}
\psfrag{n=100}[][]{\sf \small $n=100$}
\psfrag{n=250}[][]{\sf \small $n=250$}
\psfrag{n=500}[][]{\sf \small $n=500$}
\psfrag{Frequency}[][]{\sf \tiny Frequency}

\includegraphics[width=10cm,height=7.5cm]{CLT.ps}
\end{center}
}


\frame{
\frametitle{Example: \textit{The Vintage Clothing Co.}}
\noindent \textbf{You should notice two things:} \pause

\vspl

\begin{itemize}
\item [\textbf{1.}] The distribution of $\bar{x}$'s looks like a \textcolor{purple}{\bf Normal distribution}; \pause

\vspl

\item [\textbf{2.}] As we increase the sample size ($n$), the distribution for $\bar{x}$ gets more and more \textcolor{purple}{\bf concentrated} -- around the \textcolor{purple}{\bf true population value} $\mu=320$!
\end{itemize}
\pause

\vsp

\noindent In fact, what we can see in action in this graph is known as the \textcolor{purple}{\bf Central Limit Theorem}.  \pause

\vsp

This is a very powerful result in Statistics which tells us about the distribution of the sample mean $\bar{x}$.  We now state this formally.  
}

\frame{
\frametitle{The Central Limit Theorem}
\noindent Suppose $x_{1}, x_{2}, \ldots, x_{n}$ are a random sample from \textit{any} population, with mean $\mu$ and variance $\sigma^{2}$.  \pause

\vsp

If $n$ is large, then
\begin{eqnarray*}
\bar{x} \sim N\left(\mu, \frac{\sigma^{2}}{n}\right)	\qquad \textrm{\sf approximately};\pause
\end{eqnarray*}

if $x_{1}, x_{2}, \ldots, x_{n}$ come from a Normal distribution themselves, then this result holds for \textit{any} $n$.
}
\frame{
\frametitle{The Central Limit Theorem}
In other words, if we were to take many samples of size $n$ and: \pause

\vspl

\begin{itemize}
\item For each sample calculate the mean $\bar{x}$; \pause

\vspl

\item Put all of our $\bar{x}$'s together and make a histogram of them;
\end{itemize}
\pause

\vspl

then our histogram of $\bar{x}$'s will \textcolor{purple}{\bf always} be Normally distributed around the true population mean $\mu$. \pause

\vsp

What's more, we also know about the \textcolor{purple}{\bf variability} of $\bar{x}$: \pause

\[
\textsf{var}(\bar{x}) = \frac{\sigma^{2}}{n}.
\]
\pause

Thus, the standard deviation of $\bar{x}$ is $\sigma/\sqrt{n}$, and we call this the \textcolor{purple}{\bf standard error}.  
}


\frame{
\frametitle{6.2 Confidence intervals}
\noindent The values we calculate for sample means and variances are \textcolor{purple}{\bf point estimates}. \pause

\vsp

They are single values based on a limited sample of the whole population.  \pause


\vsp

Suppose that we wish to estimate the mean $\mu$ of a population.  The natural estimate for $\mu$ is the sample mean $\bar{x}$.  \pause


\vsp

However, as we have seen, $\bar{x}$ is never exactly equal to $\mu$; all we really hope is that $\bar{x}$ will be close to $\mu$.  
}


\frame{
\frametitle{6.2 Confidence intervals}
One way of improving our inference is to construct \textcolor{purple}{\bf interval estimates}, more commonly known as \textcolor{purple}{\bf confidence intervals}.   \pause

\vsp

We simply place an interval over the point estimate for $\mu$ which allows us to say (with a certain level of confidence) within what range the population mean lies.  \pause


\vsp

The calculation of these intervals depends on the size of our sample ($n$), the level of confidence we choose, and whether or not the population variance ($\sigma^{2}$) is known.   
}

\frame{
\frametitle{6.2.1 Case 1: Known variance $\sigma^{2}$}
\noindent We know from the CLT that, if our random sample is drawn from a Normal distribution, or if $n$ is large (i.e. $n \geq 30$), then \pause 
\begin{eqnarray*}
\bar{x} \sim N\left(\mu, \frac{\sigma^{2}}{n}\right).
\end{eqnarray*}
\pause

If we initially assume we know the population variance $\sigma^{2}$, we can \textcolor{purple}{\bf standardise} $\bar{x}$ as we did in Chapter 5; i.e. \pause
\begin{eqnarray*}
Z &=& \frac{\bar{x}-\mu}{\sqrt{\sigma^{2}/n}}.  
\end{eqnarray*} \pause

Recall that the standard Normal distribution is $Z\sim N(0,1)$, i.e. $Z$ has zero mean and variance (and so standard deviation) 1. \pause

\vsp

Also recall that approximately 95\% of the standard normal distribution lies between $-1.96$ and $1.96$, i.e:
}

\frame
{
\frametitle{6.2.1 Case 1: Known variance $\sigma^{2}$}
\begin{itemize}
\item We know that (from tables) 
\pause
\begin{eqnarray*}
\textsf{Pr}(\textsf{\sf --1.96} <Z<\textsf{\sf 1.96}) &=& \textsf{\sf 0.95};
\end{eqnarray*}
We can think about this graphically:

\begin{center}
\includegraphics[width=9cm,height=3.5cm]{lec1p.ps}
\end{center}

%\pause
\item[] \textcolor{white}{Thus,}
%\pause
\begin{eqnarray*}
\textsf{\textcolor{white}{Pr}}
\end{eqnarray*}
\end{itemize}
}

\frame
{
\frametitle{6.2.1 Case 1: Known variance $\sigma^{2}$}
\begin{itemize}
\item We know that (from tables) 
%\pause
\begin{eqnarray*}
\textsf{Pr}(\textsf{\sf --1.96} <Z<\textsf{\sf 1.96}) &=& \textsf{\sf 0.95};
\end{eqnarray*}
We can think about this graphically:

\begin{center}
\includegraphics[width=9cm,height=3.5cm]{lec1q.ps}
\end{center}

%\pause
\item[] \textcolor{white}{Thus,}
%\pause
\begin{eqnarray*}
\textsf{\textcolor{white}{Pr}}
\end{eqnarray*}
\end{itemize}
}

\frame
{
\frametitle{6.2.1 Case 1: Known variance $\sigma^{2}$}
\begin{itemize}
\item We know that (from tables) 
%\pause
\begin{eqnarray*}
\textsf{Pr}(\textsf{\sf --1.96} <Z<\textsf{\sf 1.96}) &=& \textsf{\sf 0.95};
\end{eqnarray*}
We can think about this graphically:

\begin{center}
\includegraphics[width=9cm,height=3.5cm]{lec1r.ps}
\end{center}

%\pause
\item[] \textcolor{white}{Thus,}
%\pause
\begin{eqnarray*}
\textsf{\textcolor{white}{Pr}}
\end{eqnarray*}
\end{itemize}
}

\frame
{
\frametitle{6.2.1 Case 1: Known variance $\sigma^{2}$}
\begin{itemize}
\item We know that (from tables) 
%\pause
\begin{eqnarray*}
\textsf{Pr}(\textsf{\sf --1.96} <Z<\textsf{\sf 1.96}) &=& \textsf{\sf 0.95};
\end{eqnarray*}
We can think about this graphically:

\begin{center}
\includegraphics[width=9cm,height=3.5cm]{lec1s.ps}
\end{center}

\pause
\item Thus,
\pause
\begin{eqnarray*}
\textsf{Pr}\left(\textsf{\sf--1.96}<\frac{\bar{x}-\mu}{\sqrt{\sigma^{2}/n}}<\textsf{\sf 1.96}\right)&=&\textsf{\sf 0.95};
\end{eqnarray*}
\end{itemize}
}


\frame{
\frametitle{6.2.1 Case 1: Known variance $\sigma^{2}$}
Rearranging for $\mu$ gives us an expression for the \textcolor{purple}{\bf 95\% confidence interval for $\mu$}: \pause
\[
\left(\bar{x}-1.96\sqrt{\sigma^{2}/n} \quad \boldsymbol{,} \quad \bar{x}+1.96\sqrt{\sigma^{2}/n}\right);
\]
\pause

\noindent thus, we can say that the two values \pause
\begin{itemize}
\item  $\bar{x} - 1.96{\sqrt{\sigma^2 / n}}$ and
\item  $\bar{x} + 1.96 {\sqrt{\sigma^2 / n}}$ \pause
\end{itemize}
are the \textcolor{purple}{\bf lower} and \textcolor{purple}{\bf upper bounds} (respectively) of the (95\%) confidence interval. \pause

\vsp

We often write this more simply as \pause
\[
\bar{x} \pm 1.96\sqrt{\sigma^{2}/n}.
\]
}


\frame{
\frametitle{6.2.1 Case 1: Known variance $\sigma^{2}$}
\noindent Going back to \textit{The Vintage Clothing Co.} example, this means that if we were to take 100 samples and for each one calculate a 95\% confidence interval, then about 95 of these confidence intervals would ``capture'' the true population value $\mu=320$. \pause

\vsp

If we wanted to be ``more confident'' of capturing $\mu$, then the interval needs to be wider. \pause

\vsp

We replace the value \textcolor{purple}{\bf 1.96} with \pause

\vspl

\begin{itemize}
\item \textcolor{purple}{\bf 2.58} for a 99\% interval \pause

\vspl

\item  \textcolor{purple}{\bf 1.65} for a 90\% interval
\end{itemize}

\pause

If we increase our sample size, we become more certain of our estimate $\bar{x}$ and so the width of the interval \textcolor{purple}{\bf decreases}.  
}


\frame{
\frametitle{Example 6.1}
\noindent \textit{Geordie Sparkz} are an electrical company based in Newcastle producing circuitboards for large plasma televisions. 

\vsp

One of their machines punches tiny holes in these curcuitboards that should be 0.5mm in diameter.  A sample of 30 circuitboards off the production line is inspected; the average diameter of the holes produced by this machine, for this sample, is 0.54mm.    

\vsp

\noindent Assuming the machine is set to ensure a standard deviation of $\sigma=0.12$mm, calculate the 95\% confidence interval for the population mean diameter of holes produced by this machine. 

\vsp

 Do you think there is a real problem with this machine?  
}

\sol

\frame{
\frametitle{Example 6.1: Solution}
We need to use the formula \pause
\[
\bar{x} \pm 1.96 \times \sqrt{\frac{\sigma^{2}}{n}}.
\]
\pause
We have \pause
\[
n=30, \quad \bar{x}=0.54 \quad \textrm{\sf and} \quad \sigma=0.12.
\]
\pause
This gives \pause
\begin{eqnarray*}
0.54 &\pm&  1.96 \times \sqrt{\frac{0.12^{2}}{30}}  \\ \pause
      & & \\
0.54 &\pm& 0.0429
\end{eqnarray*} \pause

This gives the 95\% confidence interval as (0.497mm, 0.583mm).   \pause

\vsp

No real cause for concern: specified value (0.5mm) falls within the interval. 
}

\normal

\frame{
\frametitle{6.2.2 Case 2: Unknown variance $\sigma^{2}$}
If the population variance is unknown (which is usually the case), the quantity
\begin{eqnarray*}
T &=&\frac{\bar{x}-\mu}{\sqrt{s^{2}/n}}
\end{eqnarray*}
does \textbf{\textit{not}} have a $N(\textsf{\sf 0,1})$ distribution, but a \textbf{\textcolor{purple}{Student's $\boldsymbol{t}$--distribution}}.
\pause

\vspl

\begin{itemize}
\item This is similar to the normal distribution (i.e. symmetric and bell--shaped), but is more `heavily tailed';
\pause

\vsp

\item The $t$--distribution has one parameter, called the ``degrees of freedom'' ($\nu=n-\textsf{\sf 1}$).
\end{itemize}
}


\frame{
\frametitle{6.2.2 Case 2: Unknown variance $\sigma^{2}$}
\begin{center}
\psfrag{density}[][]{\sf \tiny density}
\psfrag{0.0}[][]{\sf \tiny 0.0}
\psfrag{0.1}[][]{\sf \tiny 0.1}
\psfrag{0.2}[][]{\sf \tiny 0.2}
\psfrag{0.3}[][]{\sf \tiny 0.3}
\psfrag{0.4}[][]{\sf \tiny 0.4}
\psfrag{-3}[][]{\sf \tiny -3}
\psfrag{-2}[][]{\sf \tiny -2}
\psfrag{-1}[][]{\sf \tiny -1}
\psfrag{0}[][]{\sf \tiny 0}
\psfrag{1}[][]{\sf \tiny 1}
\psfrag{2}[][]{\sf \tiny 2}
\psfrag{3}[][]{\sf \tiny 3}
\psfrag{Z}[][]{\sf \small \textcolor{red}{\bf Standard Normal distribution}}
\includegraphics[width=11cm,height=7.5cm]{t1.ps}
\end{center}
}


\frame{
\frametitle{6.2.2 Case 2: Unknown variance $\sigma^{2}$}
\begin{center}
\psfrag{density}[][]{\sf \tiny density}
\psfrag{0.0}[][]{\sf \tiny 0.0}
\psfrag{0.1}[][]{\sf \tiny 0.1}
\psfrag{0.2}[][]{\sf \tiny 0.2}
\psfrag{0.3}[][]{\sf \tiny 0.3}
\psfrag{0.4}[][]{\sf \tiny 0.4}
\psfrag{-3}[][]{\sf \tiny -3}
\psfrag{-2}[][]{\sf \tiny -2}
\psfrag{-1}[][]{\sf \tiny -1}
\psfrag{0}[][]{\sf \tiny 0}
\psfrag{1}[][]{\sf \tiny 1}
\psfrag{2}[][]{\sf \tiny 2}
\psfrag{3}[][]{\sf \tiny 3}
\psfrag{Z+t1}[][]{\sf \small \textcolor{red}{\bf Standard Normal distribution} + \textcolor{blue}{\bf $\boldsymbol{t(1)}$ distribution}}
\includegraphics[width=11cm,height=7.5cm]{t2.ps}
\end{center}
}


\frame{
\frametitle{6.2.2 Case 2: Unknown variance $\sigma^{2}$}
\begin{center}
\psfrag{density}[][]{\sf \tiny density}
\psfrag{0.0}[][]{\sf \tiny 0.0}
\psfrag{0.1}[][]{\sf \tiny 0.1}
\psfrag{0.2}[][]{\sf \tiny 0.2}
\psfrag{0.3}[][]{\sf \tiny 0.3}
\psfrag{0.4}[][]{\sf \tiny 0.4}
\psfrag{-3}[][]{\sf \tiny -3}
\psfrag{-2}[][]{\sf \tiny -2}
\psfrag{-1}[][]{\sf \tiny -1}
\psfrag{0}[][]{\sf \tiny 0}
\psfrag{1}[][]{\sf \tiny 1}
\psfrag{2}[][]{\sf \tiny 2}
\psfrag{3}[][]{\sf \tiny 3}
\psfrag{Z+t5}[][]{\sf \small \textcolor{red}{\bf Standard Normal distribution} + \textcolor{blue}{\bf $\boldsymbol{t(5)}$ distribution}}
\includegraphics[width=11cm,height=7.5cm]{t3.ps}
\end{center}
}


\frame{
\frametitle{6.2.2 Case 2: Unknown variance $\sigma^{2}$}
\begin{center}
\psfrag{density}[][]{\sf \tiny density}
\psfrag{0.0}[][]{\sf \tiny 0.0}
\psfrag{0.1}[][]{\sf \tiny 0.1}
\psfrag{0.2}[][]{\sf \tiny 0.2}
\psfrag{0.3}[][]{\sf \tiny 0.3}
\psfrag{0.4}[][]{\sf \tiny 0.4}
\psfrag{-3}[][]{\sf \tiny -3}
\psfrag{-2}[][]{\sf \tiny -2}
\psfrag{-1}[][]{\sf \tiny -1}
\psfrag{0}[][]{\sf \tiny 0}
\psfrag{1}[][]{\sf \tiny 1}
\psfrag{2}[][]{\sf \tiny 2}
\psfrag{3}[][]{\sf \tiny 3}
\psfrag{Z+t10}[][]{\sf \small \textcolor{red}{\bf Standard Normal distribution} + \textcolor{blue}{\bf $\boldsymbol{t(10)}$ distribution}}
\includegraphics[width=11cm,height=7.5cm]{t4.ps}
\end{center}
}


\frame{
\frametitle{6.2.2 Case 2: Unknown variance $\sigma^{2}$}
\begin{center}
\psfrag{density}[][]{\sf \tiny density}
\psfrag{0.0}[][]{\sf \tiny 0.0}
\psfrag{0.1}[][]{\sf \tiny 0.1}
\psfrag{0.2}[][]{\sf \tiny 0.2}
\psfrag{0.3}[][]{\sf \tiny 0.3}
\psfrag{0.4}[][]{\sf \tiny 0.4}
\psfrag{-3}[][]{\sf \tiny -3}
\psfrag{-2}[][]{\sf \tiny -2}
\psfrag{-1}[][]{\sf \tiny -1}
\psfrag{0}[][]{\sf \tiny 0}
\psfrag{1}[][]{\sf \tiny 1}
\psfrag{2}[][]{\sf \tiny 2}
\psfrag{3}[][]{\sf \tiny 3}
\psfrag{Z+t20}[][]{\sf \small \textcolor{red}{\bf Standard Normal distribution} + \textcolor{blue}{\bf $\boldsymbol{t(20)}$ distribution}}
\includegraphics[width=11cm,height=7.5cm]{t5.ps}
\end{center}
}


\frame{
\frametitle{6.2.2 Case 2: Unknown variance $\sigma^{2}$}
\begin{center}
\psfrag{density}[][]{\sf \tiny density}
\psfrag{0.0}[][]{\sf \tiny 0.0}
\psfrag{0.1}[][]{\sf \tiny 0.1}
\psfrag{0.2}[][]{\sf \tiny 0.2}
\psfrag{0.3}[][]{\sf \tiny 0.3}
\psfrag{0.4}[][]{\sf \tiny 0.4}
\psfrag{-3}[][]{\sf \tiny -3}
\psfrag{-2}[][]{\sf \tiny -2}
\psfrag{-1}[][]{\sf \tiny -1}
\psfrag{0}[][]{\sf \tiny 0}
\psfrag{1}[][]{\sf \tiny 1}
\psfrag{2}[][]{\sf \tiny 2}
\psfrag{3}[][]{\sf \tiny 3}
\psfrag{Z+t50}[][]{\sf \small \textcolor{red}{\bf Standard Normal distribution} + \textcolor{blue}{\bf $\boldsymbol{t(50)}$ distribution}}
\includegraphics[width=11cm,height=7.5cm]{t6.ps}
\end{center}
}


\frame{
\frametitle{6.2.2 Case 2: Unknown variance $\sigma^{2}$}
\begin{center}
\psfrag{density}[][]{\sf \tiny density}
\psfrag{0.0}[][]{\sf \tiny 0.0}
\psfrag{0.1}[][]{\sf \tiny 0.1}
\psfrag{0.2}[][]{\sf \tiny 0.2}
\psfrag{0.3}[][]{\sf \tiny 0.3}
\psfrag{0.4}[][]{\sf \tiny 0.4}
\psfrag{-3}[][]{\sf \tiny -3}
\psfrag{-2}[][]{\sf \tiny -2}
\psfrag{-1}[][]{\sf \tiny -1}
\psfrag{0}[][]{\sf \tiny 0}
\psfrag{1}[][]{\sf \tiny 1}
\psfrag{2}[][]{\sf \tiny 2}
\psfrag{3}[][]{\sf \tiny 3}
\psfrag{Z+t100}[][]{\sf \small \textcolor{red}{\bf Standard Normal distribution} + \textcolor{blue}{\bf $\boldsymbol{t(100)}$ distribution}}
\includegraphics[width=11cm,height=7.5cm]{t7.ps}
\end{center}
}


\frame{
\frametitle{6.2.2 Case 2: Unknown variance $\sigma^{2}$}
So if we don't know $\sigma^{2}$, the formula for the confidence interval becomes: \pause
\begin{eqnarray*}
\bar{x} \pm t_{p}\times\sqrt{s^{2}/n}.
\end{eqnarray*} \pause
We find $t_{p}$ from statistical tables (page 148).  We read along the $p$ column and down the $\nu$ row. 
\pause 
\begin{itemize}
\item For a 90\% confidence interval, $p=\textsf{\sf 10}\%$;
\item For a 95\% confidence interval, $p=\textsf{\sf 5}\%$;
\item For a 99\% confidence interval, $p=\textsf{\sf 1}\%$.
\item The degrees of freedom, $\nu=n-\textsf{\sf 1}$.
\end{itemize}
}

\frame{
\frametitle{Example 6.2} 
\noindent A credit card company wants to determine the mean income of its card holders.  It also wants to find out if there are any differences in mean income between males and females.  

\vspace{0.3cm}

A random sample of 225 male card holders and 190 female card holders was drawn, and the following results obtained:

\begin{center}
\begin{tabular}{l c c} \hline
		&Mean		&Standard deviation	\\ \hline
Males		&\pounds 16 450 &\pounds 3675	\\
Females		&\pounds 13 220	&\pounds 3050	\\ \hline
\end{tabular}
\end{center}

\noindent Calculate 95\% confidence intervals for the mean income for males and females.  \pause

\vsp

Is there any evidence to suggest that, on average, males' and females' incomes differ?  If so, describe this difference.  
}

\sol

\frame{
\frametitle{Example 6.2: Solution}
\noindent The true population variance, $\sigma^{2}$, is unknown (we have the \textcolor{purple}{\bf sample} variance), and so we have \textbf{case 2} and need to use the $t$ distribution. Thus,
\pause
\begin{eqnarray*}
\bar{x} \pm t_{p} \times \sqrt{s^{2}/n}.
\end{eqnarray*} \pause
From the question, 
\[
\bar{x}=16450, \qquad s^{2}=3675^{2}=13505625, \qquad \textrm{\sf and} \qquad n=225.
\] \pause
But what about $t_{p}$?
}

\frame{
\frametitle{Example 6.2: Solution}
\noindent The value $t_{p}$ must be found from the table on page 148.    
\pause
\begin{itemize}
\item Recall that the degrees of freedom, $\nu=n-1$, and so here we have $\nu=225-1=224$
\pause
\item But the table only gives value of $\nu$ up to 29 -- for higher values, we use the $\infty$ row 
\pause
\item Since we require a 95\% confidence interval, we read down the $p=5\%$ column, giving a $t$ value of 1.96
\end{itemize}
}

\frame{
\frametitle{Example 6.2: Solution}
\noindent Thus, the 95\% confidence interval for $\mu$ is found as
\pause
\begin{eqnarray*}
16450 &\pm& 1.96 \times \sqrt{13505625/225},	\qquad \textsf{i.e.}\\ \pause
16450 &\pm& 480.2.
\end{eqnarray*}
\pause 
\noindent So, the 95\% confidence interval for \textcolor{purple}{\bf male income} is  \pause
\begin{center}
(\pounds 15969.80, \pounds 16930.20). 
\end{center}
}

\normal

\normal

\frame{
\frametitle{Example 6.2: Solution}
\noindent Again, the true population variance, $\sigma^{2}$, is unknown, and so we have case 2.  Thus,
\pause
\begin{eqnarray*}
\bar{x} \pm t_{p} \times \sqrt{s^{2}/n}.
\end{eqnarray*}
\pause
Now, 
\begin{eqnarray*}
\bar{x} &=& 13220, \\
s^{2}	     &=& 3050^{2}\\	
	     &=& 9302500,  \qquad \textsf{and}\\
n	     &=& 190.
\end{eqnarray*}
}

\frame{
\frametitle{Example 6.2: Solution}
\noindent As before, since the sample size is large we use the $\infty$ row of $t$ tables to obtain the value of $t_{p}$, giving:
\pause
\begin{eqnarray*}
13220 &\pm& 1.96 \times \sqrt{9302500/190},	\qquad \textsf{i.e.}\\ \pause
13220 &\pm& 1.96 \times 221.27, \qquad \textsf{i.e.}\\	\pause
13220 &\pm& 433.69.
\end{eqnarray*}
\pause
\noindent So, the 95\% confidence interval for \textcolor{purple}{\bf female income} is \pause
\begin{center}
(\pounds 12786.31, \pounds 13653.69).  
\end{center}
}


\frame{
\frametitle{Example 6.2: Solution}
\noindent Since the 95\% confidence intervals for males and females \textit{do not overlap}, there \textit{is} evidence to suggest that males' and females' incomes, on average, are different.  

\vspace{0.3cm}

Further, it appears that male card holders earn more than women.  
}

%%%LEE
\frame{
\frametitle{6.3 Hypothesis tests for one mean}

\noindent We have seen that confidence intervals can be used to make inferences about population parameters.  \pause

\vsp

Sometimes, you may be asked to assess whether or not a parameter takes a specific value.  \pause For example: whether the population mean $\mu=5$.


\vsp

One way of re-expressing this question is to ask whether the parameter value is plausible in light of the data.  \pause

\vsp

A simple check to see whether the value is contained in a 95\% confidence interval will provide an answer.  \pause

\vsp

An alternative method, called a \textcolor{purple}{\bf hypothesis test}, is available.  It is used extensively in reporting experimental results.  
}

\frame{
\frametitle{6.3 Hypothesis tests for one mean}
\noindent A hypothesis test is a rule for establishing whether or not a set of data is consistent with a hypothesis about a parameter of interest.  \pause

\vsp

The \textcolor{purple}{\bf null hypothesis} is a statement that a parameter has a certain value, and is usually written as $H_{0}$.  For example: \pause

\vspl

\begin{itemize}
\item $H_{0}: \mu=2.7$ \pause
\item $H_{0}: \sigma^{2}=12.4$.
\end{itemize}

\vspl

If the null hypothesis is not true, what alternatives are there?  \pause

\vsp

Usually, the \textcolor{purple}{\bf alternative hypothesis} is written as $H_{1}$.  Examples include: \pause

\vspl

\begin{itemize}

\item $H_{1}: \mu \neq 2.7$ \pause
\item $H_{1}:\sigma^{2} \neq 12.4$.  
\end{itemize}
}

\frame{
\frametitle{6.3 Hypothesis tests for one mean}
\noindent Based on the information we have in our sample, we'd like to go with either the null hypothesis or the alternative hypothesis.  \pause

\vsp

We might use our sample as evidence to suggest that, for example, the population mean could well be equal to 2.7; \pause alternatively, the sample might give evidence to the contrary and suggest that the population mean is not equal to 2.7. \pause 
}

\frame{
\frametitle{6.3 Hypothesis tests for one mean}
\noindent  Suppose you are going on holiday to Sicily in March. \pause

\vsp

A friend tells you that in March, Sicily has an average of \textcolor{purple}{\bf 10 hours} sunshine a day.\pause

\vsp

On the first three days of your holiday there are \textcolor{purple}{\bf 7}, \textcolor{purple}{\bf 8} and \textcolor{purple}{\bf 9} hours of sunshine respectively. \pause

\vsp

 You consider that this is evidence that your friend is wrong.
}

\frame{
\frametitle{6.3 Hypothesis tests for one mean}
Thus, \pause
\vspl

\begin{itemize}
\item the null hypothesis would state that the average sunshine hours per day is 10 \pause
\item your alternative hypothesis might state that the average sunshine hours per day \textit{is less than} 10
\end{itemize} \pause

\vspl

In symbols,\pause
\vspl
\begin{itemize}
\item $H_{0}: \mu=10$ versus
\item $H_{1}: \mu < 10$
\end{itemize}
}

\frame{
\frametitle{6.3 Hypothesis tests for one mean}
  You might be tempted to go with the alternative hypothesis.  \pause

\vsp

However, this sample of three days could be a fluke result -- you might have chosen the most miserable period in March for years for your holiday.  \pause
\begin{center}
\textit{Your test results are not conclusive; they only give you evidence \textit{for} or \textit{against} a particular belief}.  
\end{center}
}


\frame{
\frametitle{6.3.1 Methodology for hypothesis testing}
All hypothesis tests follow the same basic methodology, although the
actual calculations may vary depending on the data available.

\vspl

\begin{itemize}
\item [\textbf{1.}]\textbf{State the null hypothesis ($\boldsymbol{H_{0}}$)} \pause
\\
\noindent We use a hypothesis test to throw light on whether or not this statement is true.  \pause For example, you might ask ``\textcolor{purple}{\bf is the population mean equal to 10?}'', or \pause ``\textcolor{purple}{\bf are the two population means equal?}''; \pause such hypotheses are expressed in the following way: \pause
\begin{eqnarray*}
H_{0} &:& \mu = 10, \qquad \textrm{\sf and}	\\
H_{0} &:& \mu_{1} = \mu_{2}; \qquad \textrm{\sf or maybe}\\
H_{0} &:& \mu = c,
\end{eqnarray*}
Where $c$ could be any constant.
\end{itemize}
}

\frame{
\frametitle{6.3.1 Methodology for hypothesis testing}
\begin{itemize}
\item [\textbf{2.}]\textbf{State the alternative hypothesis ($\boldsymbol{H_{1}}$)}
\\
\noindent This is the conclusion to be reached if the null hypothesis is rejected. For example, ``\textcolor{purple}{\bf the population mean does not equal 10}'', \pause or even
``\textcolor{purple}{\bf the population mean is less than 10}''; in symbols: \pause

\vspl

\begin{eqnarray*}
H_{1} &:& \mu \neq 10		\qquad \textrm{\sf or maybe}\\
H_{1} &:& \mu < 10. 
\end{eqnarray*} \pause
To test for two different populations, we might say ``\textcolor{purple}{\bf the two population means are different}''. In symbols: \pause
\begin{eqnarray*}
H_{1} &:& \mu_{1} \neq \mu_{2}.
\end{eqnarray*}
 
\end{itemize} 
}




\frame{
\frametitle{6.3.1 Methodology for hypothesis testing}
\begin{itemize}

\item [\textbf{3.}]\textbf{Calculate the test statistic}
\\
\noindent The value calculated from the sample which is used to perform the test is called the \textcolor{purple}{\bf test statistic}. \pause

\vsp

 It usually has a similar nature to the population value mentioned in the null hypothesis. 
\end{itemize}
}

\frame{
\frametitle{6.3.1 Methodology for hypothesis testing}
\begin{itemize}
\item [\textbf{4.}]\textbf{Find the $\boldsymbol{p}$--value of the test}
\\
\noindent The probability that such an extreme test statistic occurs, \textit{assuming that $H_{0}$ is true}, is called the \textcolor{purple}{\bf $\boldsymbol{p}$--value}.  \pause

\vsp

This can be found by comparing the test statistic to values from statistical tables.
\end{itemize}
}

\frame{
\frametitle{6.3.1 Methodology for hypothesis testing}
\begin{itemize}
\item [\textbf{5.}]\textbf{Reach a conclusion} \pause

\vsp

\noindent  A small $p$--value suggests that our test statistic is unlikely to occur if $H_{0}$ is true, and so we reject $H_{0}$ in favour of the alternative $H_{1}$.  \pause

\vsp

{\tiny 
\begin{center}
\begin{tabular}{|c|c|} \hline
$p$--value					&Interpretation			\\ \hline
$p$ is bigger than  10\%			&no evidence against the null hypothesis: stick with $H_{0}$	\\
$p$ lies between 5\% and 10\%                   &\textit{slight} evidence against $H_{0}$, but not enough to reject it\\
$p$ lies between 1\% and 5\%	                &moderate evidence against $H_{0}$: reject it, and go with $H_{1}$\\
$p$ is smaller than 1\%		                &strong evidence against $H_{0}$: reject it, and go with $H_{1}$\\ \hline
\end{tabular}
\end{center}
}
\end{itemize}
}
  
\frame{
\frametitle{6.3.2 Case 1: Population variance known: Example}
 A chain of shops believes that the average size of transactions is \pounds 130, and the population variance is known to be \pounds 900. \pause

\vsp


The takings of one branch were analysed and it was found that the mean transaction size was \pounds 123 over the 100 transactions in one day. \pause

\vsp

Based on this sample, test the null hypothesis that the true mean is equal to \pounds 130.}

\frame{
\frametitle{6.3.2 Case 1: Population variance known: Example}
Since $\sigma^2$ is known (we are given that $\sigma^{2}=900$), this corresponds to case 1: population variance known (think back to confidence intervals). \pause

\vsp

We now proceed with the five steps outlined in the previous section.   \pause

\vsp

\noindent \textbf{Steps 1 and 2} \textit{(hypotheses)} \pause

\vsp 

\noindent Here, we state our null and alternative hypotheses.  The null hypothesis is given in the question -- i.e.
\begin{eqnarray*}
H_{0} &:& \mu = \textrm{\sf \pounds} 130.
\end{eqnarray*}
\noindent We could test against a general alternative, i.e.
\begin{eqnarray*}
H_{1} &:& \mu \neq \textrm{\sf \pounds} 130.
\end{eqnarray*}}


\frame{
\frametitle{6.3.2 Case 1: Population variance known: Example}
\noindent \textbf{Step 3} \textit{(calculating the test statistic)} \pause

\vsp

\noindent When $\sigma^{2}$ is known, we use following test statistic
\begin{eqnarray*}
z&=& \frac{|\bar{x}-\mu|}{\sqrt{\sigma^{2}/n}}, 	\qquad{\textrm{\sf i.e.}}\\ \pause
 & &\\
z&=& \frac{|123-130|}{\sqrt{900/100}}	\\ \pause
& & \\
 &=& \frac{7}{\sqrt{9}}	\\ \pause
& & \\
 &=& 2.33.
\end{eqnarray*}
}

\frame{
\frametitle{6.3.2 Case 1: Population variance known: Example}
\noindent \textbf{Step 4} \textit{(finding the $p$--value)} \pause

\vsp

\noindent Recall the \textcolor{purple}{\bf Central Limit Theorem} from Section 6.1; this tells us that the quantity \pause
\[
\frac{\bar{x}-\mu}{\sqrt{\sigma^{2}/n}}
\]
follows a standard Normal distribution.  \pause

\vsp

Thus, the value we obtain from our test statistic formula above will be from the positive half of the standard Normal distribution.  
}


\frame{
\frametitle{6.3.2 Case 1: Population variance known: Example}
We can therefore compare our test statistic to critical values from the standard Normal distribution to find our $p$--value, or at least a range for our $p$--value. \pause

\vsp

 Remember, this is the probability of observing our data, or anything more extreme than this, if the null hypothesis is true; \pause thus, the smaller the $p$--value, the more evidence there is \textcolor{purple}{\bf against} $H_{0}$.  \pause
}

\frame{
\frametitle{6.3.2 Case 1: Population variance known: Example}
\noindent Our alternative hypothesis is \textcolor{purple}{\bf two--tailed} (i.e. $\neq$ rather than $<$ or $>$), and so our values are: \pause
\begin{center}
\begin{tabular}{|c|c c c|} \hline
Significance level	&10\%		&5\%	&1\%	\\ \hline
Critical value		&1.645		&1.96	&2.576	\\ \hline
\end{tabular}
\end{center} \pause
\noindent Our test statistic $z=2.33$ lies between the critical values of 1.96 and 2.576, and so our $p$--value lies \textcolor{purple}{\bf between 1\% and 5\%}. \pause

\vsp

 We can see this more clearly on a diagram.
}


\frame{
\frametitle{6.3.2 Case 1: Population variance known: Example}

\noindent \textbf{Step 5} \textit{(conclusion)} \pause 

\vsp

\noindent Using table 6.2 to interpret our $p$--value, we see that: \pause
\vspl
\begin{itemize}
\item There is \textcolor{purple}{\bf moderate} evidence against $H_{0}$ \pause
\item Thus, we should \textcolor{purple}{\bf reject} $H_{0}$ in favour of $H_{1}$ \pause
\item It appears that the population mean transaction size \textcolor{purple}{\bf is not equal to} \pounds 130
\end{itemize}
}


\normal


     
\frame{
\frametitle{6.3.2 Case 1: Population variance known: Example}
\noindent Alternatively, since our sample mean $\bar{x}=\textrm{\sf \pounds} 123$ is smaller than the proposed value of $\textrm{\sf \pounds} 130$, we could have set up a \textcolor{purple}{\bf one--tailed} alternative hypothesis: \pause
\begin{eqnarray*}
H_{0} &:& \mu = \textrm{\sf \pounds} 130	\qquad \textrm{\sf against}	\\
H_{1} &:& \mu < \textrm{\sf \pounds} 130.
\end{eqnarray*} \pause
\noindent This is now a one--tailed test and the critical values from tables are: \pause
\begin{center}
\begin{tabular}{|c| c c c|} \hline
Significance level	&10\%		&5\%	&1\%	\\	\hline
Critical value		&1.282		&1.645	&2.326  \\ \hline
\end{tabular}
\end{center} 
}


\frame{
\frametitle{6.3.2 Case 1: Population variance known: Example}
\noindent The test statistic is (as before) $2.33$, which now lies ``to the right'' of the last critical value in the table (2.326).  \pause

\vsp

Thus, our $p$--value is now smaller than 1\%, and so, using table 6.2, we see that \pause

\vsp

\begin{itemize}
\item there is \textcolor{purple}{\bf strong} evidence against $H_{0}$ \pause
\item We would \textcolor{purple}{\bf reject} $H_{0}$ in favour of $H_{1}$ \pause
\item There is evidence to suggest that the population mean \textcolor{purple}{\bf is less than} \pounds 130
\end{itemize}
}

\frame{
\frametitle{6.3.3 Case 2: Population variance unknown: Example}

\noindent The batteries for a fire alarm system are required to last for 20000
hours before they need replacing. 

\vsp

16 batteries were tested; they were found to have an average life of 19500 hours and a standard
deviation of 1200 hours.  

\vsp

Perform a hypothesis test to see if the batteries do, on average, last for 20000 hours.
}

\frame{
\frametitle{6.3.3 Case 2: Population variance unknown: Example}
\noindent \textbf{Steps 1 and 2} \textit{(hypotheses)} \pause

\vsp

\noindent Using a \textcolor{purple}{\bf one--tailed test}, our null and alternative hypotheses are:
\begin{eqnarray*}
H_{0} &:& \mu = 20000	\qquad{\textrm{\sf versus}}	\\
H_{1} &:& \mu < 20000.
\end{eqnarray*} \pause
\noindent We use a one--tailed test because we are interested in whether the batteries are effective or not; there is no problem if they last longer than 20000 hours.  }


\frame{
\frametitle{6.3.3 Case 2: Population variance unknown: Example}
\noindent \textbf{Step 3} \textit{(calculating the test statistic)} \pause

\vsp

\noindent  Unlike the previous example, the population variance $\sigma^{2}$ is unknown.\pause

\vsp

  However, the \textcolor{purple}{\bf sample} standard deviation is given, based on a sample of size 16, and so we need to use a slightly different test statistic.  \pause

\vsp

In fact, we do what we did last week when we were constructing confidence intervals -- i.e. we replace $\sigma^{2}$ with $s^{2}$ and then use tables of values from Student's $t$ distribution instead of the standard Normal distribution. \pause
}

\frame{
\frametitle{6.3.3 Case 2: Population variance unknown: Example}
Thus, the test statistic is given by \pause
\begin{eqnarray*}
t &=& \frac{|\bar{x} - \mu |}{\sqrt{s^2 / n}}\\ \pause
   & & \\
  &=& \frac{|19500-20000|}{\sqrt{1200^{2}/16}}	\\ \pause
 & & \\
  &=& \frac{500}{\sqrt{1440000/16}}	\\ \pause
   & & \\
  &=& 1.667.  
\end{eqnarray*}
}

\frame{
\frametitle{6.3.3 Case 2: Population variance unknown: Example}
\noindent \textbf{Step 4} \textit{(finding the $p$--value)} \pause 

\vsp

\noindent Since $\sigma^{2}$ is unknown, we use $t$--distribution tables to obtain a range for our $p$--value. \pause

\vsp

 The degrees of freedom, $\nu=n-1=16-1=15$, and under a one--tailed test this gives the following critical values: \pause
\begin{center}
\begin{tabular}{|c| c c c|} \hline
Significance level	&10\%		&5\%	  &1\%	\\ \hline
Critical value   	&1.341		&1.753	  &2.602 \\ \hline
\end{tabular}
\end{center} \pause
\noindent Our test statistic of $t=1.667$ lies between the critical values of 1.341 and 1.753, and so the corresponding $p$--value lies between 5\% and 10\%. 
}

 
\frame{
\frametitle{6.3.3 Case 2: Population variance unknown: Example}
\noindent \textbf{Step 5} \textit{(conclusion)} \pause

\vsp

\noindent Using table 6.2 to interpret our $p$--value, we see that there is \pause

\vspl

\begin{itemize}
\item only \textcolor{purple}{\bf slight} evidence against the null hypothesis \pause
\item this is not enough grounds to reject it, so we \textcolor{purple}{\bf retain} $H_{0}$ \pause
\item There is insufficient evidence to suggest there is a problem with these batteries. 
\end{itemize}
}

\frame
{
\frametitle{6.4 Testing two means}

\noindent If we have \textbf{two} independent random samples from \textbf{two} populations, we can compare the two sample means (\textit{c.f.} comparing one sample mean to a \textit{proposed value} in the one--sample case).
\pause

\vspace{0.5cm}

\noindent We use the same framework for hypothesis testing as for the one--sample test; however, the calculations required for the test statistic are slightly different.  There are two situations to consider here:
\pause
\begin{itemize}
\item Are \textbf{both} population variances ($\sigma_{1}^{2}$ \textbf{and} $\sigma_{2}^{2}$) \textcolor{purple}{\textbf{known}}?
\pause
\item Are \textbf{both} population variances \textcolor{purple}{\textbf{unknown}}?
\end{itemize}
}


\frame
{
\frametitle{6.4.1 Both population variances ($\boldsymbol{\sigma_{1}^{2}}$ and $\boldsymbol{\sigma_{2}^{2}}$) known}
\pause
\begin{itemize}
\pause
\item[\textbf{1.}] \textcolor{purple}{\textbf{State the null hypothesis}}
\\
\noindent This time, the null hypothesis is
\begin{eqnarray*}
H_{0} &:& \mu_{1} = \mu_{2}, 
\end{eqnarray*}
i.e. the two population means are equal.
\pause

\vspl

\item [\textbf{2.}] \textcolor{purple}{\textbf{State the alternative hypothesis}} 
\\
\noindent We usually test against the (\textcolor{purple}{\bf two--tailed}) alternative:
\begin{eqnarray*}
H_{1} &:& \mu_{1} \neq \mu_{2},
\end{eqnarray*}
i.e. the population means \textit{are not} equal.  However, we might use the \textcolor{purple}{\bf one--tailed} alternatives:
\pause
\begin{eqnarray*}
H_{1} &:& \mu_{1} > \mu_{2}, \qquad \textsf{\sf or}	\\
\pause
H_{1} &:& \mu_{1} < \mu_{2}.
\end{eqnarray*}
\end{itemize}
}




\frame{
\frametitle{6.4.1 Both population variances ($\boldsymbol{\sigma_{1}^{2}}$ and $\boldsymbol{\sigma_{2}^{2}}$) known}
\begin{itemize}
\item [\textbf{3.}] \textcolor{purple}{\textbf{Calculate the test statistic}}
\\
\noindent The test statistic for a two--sample test (when both population variances are known) is
\begin{eqnarray*}
z	&=& \frac{|\bar{x}_{1}-\bar{x}_{2}|}{\sqrt{\frac{\sigma_{1}^{2}}{n_{1}} + \frac{\sigma_{2}^{2}}{n_{2}}}}
\end{eqnarray*}
\end{itemize}
}

\frame{
\frametitle{Both population variances ($\boldsymbol{\sigma_{1}^{2}}$ and $\boldsymbol{\sigma_{2}^{2}}$) known}
\begin{itemize}
\item [\textbf{4.}]\textcolor{purple}{\textbf{Find the $\boldsymbol{p}$--value}}
\\
\noindent This is found from statistical tables; since, in this case, both population variances $\sigma_{1}^{2}$ and $\sigma_{2}^{2}$ are \textit{known}, we refer to standard normal tables.  As before, we find a range for our $p$--value by comparing our test statistic to the 10\%, 5\% and 1\% critical values.   
\pause

\vspl

\item [\textbf{5.}] \textcolor{purple}{\textbf{Form a conclusion}}
\\
\noindent Exactly the same again!  Use table 6.2 to help you decide what to do!  Word your conclusions in the context of the original question.
\pause
\end{itemize}
}


\frame{
\frametitle{Example 6.3}
 Before a training session for call centre employees a sample of 50 calls to the call centre had an average duration of 5 minutes, whereas after the training session a sample of 45 calls had an average duration of 4.5 minutes.  \pause

\vsp

The population variance is \textbf{known} to have been 1.5 minutes before the course and 2 minutes afterwards.  \pause

\vsp

Has the course been effective?  
}

\sol

\frame{
\frametitle{Example 6.3: Solution}

\textbf{Steps 1 \& 2} \textit{(hypotheses)} \pause

\vsp

\begin{eqnarray*}
  H_{0}&:& \mu_{B}=\mu_{A}  \qquad \textrm{\sf versus} \\ \pause
  & & \\
  H_{1} &:& \mu_{B}\neq \mu_{A}
\end{eqnarray*}

}

\frame{
\frametitle{Example 6.3: Solution}
\textbf{Step 3} \textit{(Test statistic)} \pause

\vsp

We use \pause
\begin{eqnarray*}
  z  &=& \frac{|\bar{x}_{B}-\bar{x}_{A}|}{\sqrt{\frac{\sigma_{B}^{2}}{n_{B}}+\frac{\sigma_{A}^{2}}{n_{A}}}}  \pause \\
    && \\
       &=& \frac{|5 - 4.5|}{\sqrt{\frac{1.5}{50}+\frac{2}{45}}} \pause \\
    & &\\
     &=& \frac{0.5}{\sqrt{0.03+0.0444}} \\ \pause
    & & \\
    &=& 1.833
\end{eqnarray*}
}

\frame{
\frametitle{Example 6.3: Solution}
\textbf{Step 4} \textit{(p--value)} \pause

\vsp

Since this is case 1 (both population variances known), we use Normal tables (page 158).  \pause

\vsp

Recall that we have a \textcolor{purple}{\bf two--tailed} alternative, and so we get \pause

\begin{center}
\begin{tabular}{|c| c c c|} \hline
  Significance level &10\%  &5\%    &1\% \\ \hline
  Critical value     &1.645 &1.96   &2.576 \\ \hline
\end{tabular}
\end{center}

\pause

Our test statistic $z=1.833$ shows that our $p$--value is between 5\% and 10\%.}

\frame{
\frametitle{Example 6.3: Solution}
\textbf{Step 5} \textit{(Conclusion)} \pause

\vsp

From Table 6.2, \pause

\vsp

\begin{itemize}
\item We have \textcolor{purple}{\bf slight} evidence against $H_{0}$ \pause

\vspl

\item This is not enough to reject and so we \textcolor{purple}{\bf retain} $H_{0}$ \pause

\vspl

\item There is insufficient evidence to suggest the training course has been effective!
\end{itemize}
}

\normal

\frame          
{
\frametitle{6.4.2 $\boldsymbol{\sigma_{1}^{2}}$ and $\boldsymbol{\sigma_{2}^{2}}$ unknown}
\noindent In the more likely situation where the population variances are unknown, the test statistic becomes
\pause
\begin{eqnarray*}
t &=& \frac{|\bar{x}_{1}-\bar{x}_{2}|}{s \times \sqrt{\frac{1}{n_{1}}+\frac{1}{n_{2}}}},
\end{eqnarray*}
where $s$ is a ``pooled standard deviation'', and is found as
\begin{eqnarray*}
s &=& \sqrt{\frac{(n_{1}-1)s_{1}^{2}+(n_{2}-1)s_{2}^{2}}{n_{1}+n_{2}-2}}.
\end{eqnarray*}
\pause
\noindent Like before, we have to use $t$--tables to obtain our critical value; the degrees of freedom is now found as $\nu=n_{1}+n_{2}-\textsf{\sf 2}$. 
}


\normal

\frame{
\frametitle{Example 6.4}

\noindent A company is interested in knowing if two branches have the same level of average transactions.  

\vsp

The company sample a small number of transactions and calculates the following statistics:
\begin{center}
\begin{tabular}{c|ccc}
Shop 1 & $\bar{x}_{1} = 130$ & $s_{1}^{2} = 700$ & $n_{1}=12$\\
Shop 2 & $\bar{x}_{2} = 120$ & $s_{2}^{2} = 800$ & $n_{2}=15$
\end{tabular}
\end{center}
\noindent Test  whether or not the two branches have (on average) the same level of transactions. 
}


\frame{
\frametitle{Example 6.4: Solution}
 \textbf{Steps 1 and 2} \textit{(hypotheses)} \pause

\vspl

\noindent Our null and alternative hypotheses are: \pause
\begin{eqnarray*}
H_{0} &:& \mu_{1} = \mu_{2}	\qquad \textrm{\sf versus}	\\ \pause
H_{1} &:& \mu_{1} \neq \mu_{2}.
\end{eqnarray*}   

\vsp

\textbf{Step 3} \textit{(Test statistic)} \pause

\vspl

 Since both population variances are unknown (only the \textit{sample} values are given), the test statistic is \pause
\begin{eqnarray*}
t &=& \frac{|\bar{x}_{1}-\bar{x}_{2}|}{s \times \sqrt{\frac{1}{n_{1}}+\frac{1}{n_{2}}}}.
\end{eqnarray*}
}

\sol

\frame{
\frametitle{Example 6.4: Solution}
First the \textcolor{purple}{\bf pooled standard deviation}: \pause
\begin{eqnarray*}
s &=& \sqrt{\frac{(n_{1}-1)s_{1}^{2}+(n_{2}-1)s_{2}^{2}}{n_{1}+n_{2}-2}} \\ \pause
 & & \\
  &=& \sqrt{\frac{(12-1)\times 700 + (15-1)\times 800}{12+15-2}}	\\ \pause
& & \\
  &=& \sqrt{\frac{11\times 700 + 14 \times 800}{25}}	\\ \pause
& & \\
  &=& \sqrt{\frac{7700 + 11200}{25}}	\\ \pause
& & \\
  &=& \sqrt{\frac{18900}{25}}	\\ \pause
& & \\
  &=& \sqrt{756} = 27.495.
\end{eqnarray*}}


\frame{
\frametitle{Example 6.4: Solution}
Now we put this into our formula for $t$: \pause
\begin{eqnarray*}
t &=& \frac{|130-120|}{27.495 \times \sqrt{\frac{1}{12}+\frac{1}{15}}}	\\ \pause
& &\\
  &=& \frac{10}{27.495 \times \sqrt{0.15}}	\\ \pause
& &\\
  &=& \frac{10}{10.649}	\\ \pause
& &\\
  &=& 0.939.  
\end{eqnarray*}}

\normal

\frame{
\frametitle{Example 6.4: Solution}
\textbf{Step 4} \textit{(p--value)} 

\vsp

 Since both population variances are unknown, we use $t$--tables to obtain our critical value. \pause

\vsp

The degrees of freedom, $\nu=n_{1}+n_{2}-2$, i.e. $\nu=12+15-2=25$.  \pause

\vsp

Under a two--tailed test, and using $t$--tables (page 158), we get the following critical values: \pause
\begin{center}
\begin{tabular}{|c| c c c|} \hline
Significance level	&10\%		&5\%	&1\%	\\ \hline
Critical value		&1.708		&2.060	&2.787	\\ \hline
\end{tabular}
\end{center} \pause
\noindent Our test statistic $t=0.939$ lies to the left of the first critical value, and so our $p$--value is bigger than 10\%. }

\frame{
\frametitle{Example 6.4: Solution}
\textbf{Step 5} \textit{(Conclusion)} 

\vsp

Using Table 6.2, \pause

\vspl

\begin{itemize}
\item We have \textcolor{purple}{\bf no} evidence against $H_{0}$ \pause

\vspl

\item Therefore, we \textcolor{purple}{\bf retain} $H_{0}$ \pause

\vspl

\item  There is no significant difference between the average level of transactions at the two shops.  
\end{itemize}
}

\announce
\frame{
\frametitle{Welcome back!}
Two more assignments:

\vspl

\begin{itemize}
\item Clubs case study -- next week's computer session, deadline \textbf{4pm, Friday 12th May} \pause

\vspl

\item CBA -- practice mode next week, assessed mode w/b 8th May, deadline \textbf{11.45pm, Sunday 14th May}
\end{itemize} \pause

}


\frame{
\frametitle{Welcome back!}
Case study: \pause

\vspl

\begin{itemize}
\item Won't take too much work \pause

\vspl

\item Three/four pages max, including graphs and tables \pause

\vspl

\item Need to do simple stuff: graphs, means, standard deviations etc., PLUS `harder' stuff: confidence intervals and a hypothesis test \pause

\vspl

\item Must do analysis on Minitab - we will do all of the necessary computing in the computer sessions next week \pause

\vspl

\item Individual submissions!

\end{itemize} \pause

\vspl

Next week: \pause

\vspl

\begin{itemize}
\item Bank holiday \pause

\vspl

\item Monday practicals cancelled - replacement Wednesday, 1-3pm, Side cluster BS.TC
\end{itemize}
}

\normal


\normal

\frame{

\vspace{1cm}

\huge
\textbf{Chapter 7}

\vspace{1cm}

\Large
\textbf{Techniques of regression}

}


\frame{
\frametitle{What we'll cover...}
\begin{itemize}
\item Visualising \textcolor{purple}{\bf bivariate data} \pause
\vspl
\item Assessing the \textcolor{purple}{\bf association} between two continuous variables: \pause
\vspl
\begin{itemize}
\item [--] Informally \pause
\vspl
\item [--] More objectively -- the sample \textcolor{purple}{\bf correlation coefficient} \pause
\end{itemize}
\vspl
\item Assessing the \textcolor{purple}{\bf signficance} of the correlation coefficient \pause
\vspl
\item Modelling the relationship between two continuous variables: \textcolor{purple}{\bf Simple linear regression} \pause
\vspl
\item Extensions to the \textcolor{purple}{\bf multiple linear regression} model, and possibly beyond...
\end{itemize}
}

\frame{
\frametitle{7.1 Introduction}
\noindent In this chapter we will investigate relationships between \textcolor{purple}{\bf continuous variables}.  \pause

\vsp

Initially, we will assume our data consists of $n$ pairs of observations on two variables, say $X$ and $Y$:
\begin{eqnarray*}
(x_{1},y_{1}), (x_{2},y_{2}), \ldots, (x_{n},y_{n}).
\end{eqnarray*} \pause
\begin{itemize}
\item Could be a random sample of $n$ individuals from a population, on which two measurements/observations $(x_{i},y_{i})$, $i=1, \ldots, n$ were made \pause
\vspl
\item Could be from an experiment in which one variable ($X$) is held fixed or controlled at certain chosen levels and independent measurements of the \textcolor{purple}{\bf response} variable ($Y$), are taken at each of these levels
\end{itemize}
}


\frame{
\frametitle{7.1 Introduction}
  The first step is \textit{always} to plot the data on a \textcolor{purple}{\bf scatter diagram}.  \pause

\vsp

We considered scatter diagrams, often called \textcolor{purple}{\bf scatter plots}, in Chapter 4 (Section 4.5.3, page 92).  \pause

\vsp

From this diagram we can get an initial impression about the relationship between $X$ and $Y$ and form some subjective assessments.  
}


\frame{
\frametitle{7.1 Introduction}
The main aim of this Chapter is to supplement such descriptive analyses with more formal techniquesb --- in terms of \pause
\vspl
\begin{itemize}
\item \textcolor{purple}{\bf quantifying} the association between $X$ and $Y$, and \pause
\vspl
\item  \textcolor{purple}{\bf modelling} any relationship between $X$ and $Y$
\end{itemize}
}


\frame{
\frametitle{7.1 Introduction}
  Towards the end of the course, we will also consider extending these techniques to investigate the relationship between the response variable $Y$ and more than one \textcolor{purple}{\bf predictor} variable -- perhaps to include several predictor variables $X_{1}, X_{2}, \ldots$.
}

\frame{
\frametitle{7.2 Example: The \textit{Saint Clair Estate Winery}}

\noindent The \textit{Saint Clair Estate Winery} is a vineyard in the Marlborough region of the South Island of New Zealand.  \pause
\vspl
\begin{itemize}
\item \textcolor{purple}{\bf Multi--million} dollar industry \pause
\vspl
\item \textit{Saint Clair} one of the country's leading producers/exporters, of wine
\end{itemize}
}


\frame{
\frametitle{7.2 Example: The \textit{Saint Clair Estate Winery}}
 
\noindent The price of a bottle of wine is thought to depend on many factors, such as its age, the quality of the grapes used to produce it, the amount of rainfall during the growing season, where the wine was produced, etc.  

\pause

\vspace{0.3cm}

The table below shows the price of 10 randomly selected bottles of wine from \textcolor{blue}{\texttt{www.tanners-wines.co.uk}}, an online wine merchant.  Also shown is the age of each wine selected. 

\pause

{\scriptsize
\begin{center}
\begin{tabular}{|c|c c c c c c c c c c|} \hline
Bottle		&1		&2	&3	&4	&5	&6	&7	&8	&9	&10	\\ \hline
Age ($X$)&$3\frac{1}{2}$ &5	&3	&$2\frac{1}{2}$	&3	&2	&$2\frac{1}{2}$	&1	&10	&4	\\
Price ($Y$)	&4.50	&12.95	&6.50	&4.99	&7.50	&14.95	&8.25	&3.95	&18.99	&10.00	\\ \hline
\end{tabular}
\end{center}}
}

\frame{
\frametitle{7.2 Example: The \textit{Saint Clair Estate Winery}}	
%\centering
\includegraphics[width=10cm,height=7cm]{wine1.ps}
%\caption{Scatter plot of price of wine (\pounds) against age (years)}
%\end{figure}
}

\sol 
\frame{
\frametitle{7.2 Example: The \textit{Saint Clair Estate Winery}}
\noindent Looking at the scatter plot (and maybe just the raw data themselves!), what can you say about the relationship between age of wine and price?
\pause
\begin{itemize}
\item \textit{Generally}, as the age of wine increases, the price also increases
\pause
\item There is a \textcolor{purple}{\bf linear} relationship
\pause
\item There is a \textcolor{purple}{\bf strong} linear relationship?  \pause Or maybe \textcolor{purple}{\bf moderate}?
\pause
\item There is a \textcolor{purple}{\bf positive correlation}
\end{itemize}
}

\normal

\frame{
\frametitle{7.3 Quantifying the relationship: Correlation}
\noindent There is clearly a relationship between the age and price of wine; the relationship is \textcolor{purple}{\bf strong}, \textcolor{purple}{\bf positive} and \textcolor{purple}{\bf linear}.

\pause

\vspace{0.3cm}

 How would you describe, in words, the relationship between $X$ and $Y$ in the following scatter plots?
%\begin{figure}[!h]
\begin{center}
\includegraphics[width=7cm,height=4cm]{scatter1.ps}
%\caption{Scatter plots showing different relationships}
%\end{figure}
\end{center}
}

\frame{
\frametitle{7.3 Quantifying the relationship: Correlation}
\noindent Scatterplots such as the one in the bottom left--hand corner can be difficult to interpret using words alone, since different people might say different things. 

\pause

\vspace{0.3cm}

Some might think there is a moderate/fairly strong relationship between $X$ and $Y$ here, whilst others might conclude that there is a relatively weak relationship between these two variables.  

\pause

\vspace{0.3cm}

Interpreting such relationships with words alone can be subjective; \textcolor{purple}{\bf quantifying} such relationships \textcolor{purple}{\bf numerically} can circumvent this problem of subjectivity.  
}

\frame{
\frametitle{7.3 Quantifying the relationship: Correlation}
One way of doing this is to calculate the \textcolor{purple}{\bf product moment correlation coefficient}, often denoted by the letter $r$. 

\pause

\vspace{0.3cm}


The formula for $r$ is  \pause
\begin{eqnarray*}
r	&=& \frac{S_{xy}}{\sqrt{S_{xx}\times S_{yy}}},
\end{eqnarray*}
\pause
where 
\pause
\begin{eqnarray*}
S_{xy}	&=& \left(\sum xy\right)-n\bar{x}\bar{y},	\\ \pause
S_{xx}	&=& \left(\sum x^{2}\right) - n\bar{x}^{2}	\qquad \textrm{\sf and}	\\ \pause
S_{yy}	&=& \left(\sum y^{2}\right) - n\bar{y}^{2},
\end{eqnarray*}
\pause
$n$ is the number of pairs and $\bar{x}$ and $\bar{y}$ correspond to the mean of $X$ and the mean of $Y$ (respectively).  
}


\frame{
\frametitle{7.3 Quantifying the relationship: Correlation}
\noindent The correlation coefficient $r$ always lies between $-1$ and $+1$. 
\pause
\begin{itemize}
\item If $r$ is close to $+1$, there is a strong \textit{positive} linear relationship
\pause
\item If $r$ is close to $-1$ there is a strong \textit{negative} relationship
\pause
\item If $r$ is close to zero, there is \textit{no} linear relationship between the variables. 
\end{itemize}
\pause
 Note that $r \approx 0$ does not imply no relationship at all, simply no \textit{linear} relationship. 
\pause

\vspace{0.3cm}

\noindent  Can you estimate the value of $r$ for the wine age/price data?   And for the four datasets shown on page 169?  
}

\frame{
\frametitle{7.3 Quantifying the relationship: Correlation}

\noindent Using the wine price/age data, we can calculate the value of $r$.  \pause  The easiest way to do this is to draw up a table:
\pause

%{\small

\begin{center}
\begin{tabular}{|c| c| c| c| c| } \hline
$x$		&$y$		&$x^{2}$	&$y^{2}$	&$xy$	\\ \hline 
3.5		&4.50		&12.25		&20.25		&15.75	\\ \pause
5		&12.95		&25		&167.7025	&64.75	\\ \pause
3		&6.50		&9		&42.25		&19.5	\\ \pause
2.5		&4.99		&6.25		&24.9001	&12.475	\\
3		&7.50		&9		&56.25		&22.5	\\
2		&14.95		&4		&223.5025	&29.9	\\
2.5		&8.25		&6.25		&68.0625	&20.625	\\
1		&3.95		&1		&15.6025	&3.95	\\
10		&18.99		&100		&360.6201	&189.900\\
4		&10.00		&16		&100		&40	\\ \hline \pause
\textbf{36.5}	&\textbf{92.58}	&\textbf{188.75}&\textbf{1079.14}&\textbf{419.35}	\\ \hline
\end{tabular}
\end{center}
}

\sol 
\frame{
\frametitle{7.3 Quantifying the relationship: Correlation}
	
\noindent Then we have: \pause
\begin{eqnarray*}
\bar{x}	&=& \frac{36.5}{10}	\\ \pause
	& &	\\
	&=& 3.65 \qquad \textrm{\sf and}	\\ \pause
	& &				\\
\bar{y}	&=& \frac{92.58}{10}	\\ \pause
	& &	\\
	&=& 9.258.
\end{eqnarray*}
}

\frame{
\frametitle{7.3 Quantifying the relationship: Correlation}
\noindent We can now calculate $S_{xy}$, $S_{xx}$ and $S_{yy}$:  \pause
\begin{eqnarray*}
S_{xy}	&=& \left(\sum xy\right) - n \bar{x}\bar{y}	\\ \pause
	&=& 419.35 - 10\times 3.65 \times 9.258	\\ \pause
	&=&81.433, \pause		
\end{eqnarray*}
\begin{eqnarray*}
S_{xx}	&=&\left(\sum x^{2}\right) - n \bar{x}^{2}	\\ \pause
	&=& 188.75 - 10 \times 3.65 \times 3.65		\\ \pause
	&=& 55.525	\qquad \textrm{\sf and}		
\end{eqnarray*}
}

\frame{
\frametitle{7.3 Quantifying the relationship: Correlation}
\begin{eqnarray*}	 
S_{yy}	&=& \left(\sum y^{2}\right) - n \bar{y}^{2}	\\ \pause
	&=& 1079.14 - 10 \times 9.258 \times 9.258	\\ \pause
	&=& 222.0344.
\end{eqnarray*}
}

\frame{
\frametitle{7.3 Quantifying the relationship: Correlation}
Thus,
\begin{eqnarray*}
r	&=& \frac{S_{xy}}{\sqrt{S_{xx}\times S_{yy}}}	\\ \pause
	& &						\\ 
	&=& \frac{81.433}{\sqrt{55.525 \times 222.0344}}	\\ \pause
	& &							\\ 
	&=& \frac{81.433}{111.0336}				\\ \pause
	& &							\\
	&=& 0.7334.
\end{eqnarray*}
}

\normal

\frame{
\frametitle{7.3 Quantifying the relationship: Correlation}
Since this is fairly close to +1, we have a moderate/strong positive linear association between the age and price of wine. 


\pause

\vspace{0.3cm}

 Remember that this correlation coefficient can only be used to detect \textcolor{purple}{\bf linear} associations.  

\pause

\vspace{0.3cm}

For information, the value of $r$ for the plots on page 169, from top--left and moving clockwise, is:\pause $r=1$, \pause$-0.899$, \pause $0.699$ and \pause $0.064$. 

\vspace{0.3cm}

\pause



 Note there is clearly a relationship between $X$ and $Y$ in the bottom--right plot, but here $r=0.064$ which is very close to zero: this is because the relationship here is plainly non--linear.  
}

\frame{
\frametitle{7.4 Modelling the relationship: linear regression}
 A correlation analysis may establish a linear relationship but it does not allow us to \textit{use} it to, say, predict the value of one variable given the value of another. 

\pause

\vspace{0.3cm}

 \textcolor{purple}{\bf Regression analysis} allows us to do this and more.  


\pause

\vsp

 Look at the scatter plot of the price of wine against the corresponding age of each bottle.
}

\frame{
\frametitle{7.4 Modelling the relationship: linear regression}
%\begin{figure}[!h]
\begin{center}
\includegraphics[width=10cm,height=7cm]{wine1.ps}
%\caption{Scatter plots showing different relationships}
%\end{figure}
\end{center}
}

\frame{
\frametitle{7.4 Modelling the relationship: linear regression}
A ``line of best fit'' can be drawn through the data, and from this line we can make predictions of price based on age.  

\vsp
\pause

The problem is, everyone's line of best fit is bound to be slightly different,   and so everyone's predictions will be slightly different!  

\vsp
\pause

The aim of regression analysis is to find the very best line which goes through the data in a completely objective way.  


\vsp
\pause

We do this through the \textcolor{purple}{\bf regression equation}. 

}


\frame{
\frametitle{7.4 Modelling the relationship: linear regression}
 Recall from Chapter 1 that the equation of a straight line takes the general form \pause
\[
y=mx +c,
\]
where $m$ is the \textcolor{purple}{\bf gradient} and $c$ is the \textcolor{purple}{\bf intercept}. \pause \pause

\vsp

Statisticians tend to use different notation for their \textcolor{purple}{\bf regression equation}: \pause   
\begin{eqnarray*}
Y	&=&\beta_{0} + \beta_{1} X + \epsilon,
\end{eqnarray*} \pause

where $Y$ is the \textcolor{purple}{\bf response} variable and $X$ the \textcolor{purple}{\bf predictor} variable, and $\epsilon$ (``epsilon'') is a ``random error'' term.  }


\frame{
\frametitle{7.4 Modelling the relationship: linear regression}

The unknown parameters $\beta_{0}$ (``beta nought'') and $\beta_{1}$ (``beta one'') represent the intercept and slope of the population regression line $\beta_{0} + \beta_{1}X$.  \pause

\vsp

Obviously, we need to find $\beta_{0}$ and $\beta_{1}$; the best values will minimise the vertical `gaps' between the regression line and the data.  These `gaps' are known as the \textcolor{purple}{\bf residuals} -- see diagram.  

 

}

\frame{
\frametitle{7.4 Modelling the relationship: linear regression}
Each of the points $i$, $i=1, \ldots, n$, in our scatter plot has a $y$ co--ordinate $y_{i}$. \pause

\vsp

 Recall from above that the corresponding $y$ co--ordinates of points on the line, say $\hat{y}_{i}$, are given by
\[
\hat{y}_{i} = \beta_{0}+\beta_{1}x_{i}.
\] \pause

Thus, the vertical ``gaps'' between the points and the line are given by
\begin{eqnarray*}
y_{1} - \hat{y}_{1}   &=&y_{1}-\beta_{0}-\beta_{1}x_{1} \\
y_{2} - \hat{y}_{2}   &=&y_{2}-\beta_{0}-\beta_{1}x_{2} \\
               &\vdots&  \\
y_{n} - \hat{y}_{n}   &=&y_{n}-\beta_{0}-\beta_{1}x_{n}
\end{eqnarray*}
}


\frame{
\frametitle{7.4 Modelling the relationship: linear regression}
Some of these ``gaps'' will be negative, as defined above, as some points will lie below the line. \pause

\vsp

To get rid of any ``negative gaps'', we square all of these quantities:
\begin{eqnarray*}
&& (y_{1}-\beta_{0}-\beta_{1}x_{1})^{2} \\ \pause
&& (y_{2}-\beta_{0}-\beta_{1}x_{2})^{2} \\ \pause
                        && \hspace{1cm} \vdots \\ 
 && (y_{n}-\beta_{0}-\beta_{1}x_{n})^{2} \\
\end{eqnarray*}
}


\frame{
\frametitle{7.4 Modelling the relationship: linear regression}
The very best line of best fit -- that is, the line which minimises the sum of these ``squared gaps'', is what we call the \textcolor{purple}{\bf regression line}.  \pause

\vsp

So we want the regression line to minimise the quantity
\[
\Delta(\beta_{0},\beta_{1}) = \sum_{i=1}^{n}(y_{i}-\beta_{0}-\beta_{1}x_{i})^{2}.
\]
And how do we minimise a function? We use calculus!  So we solve
\begin{eqnarray*}
\frac{d}{d\beta_{0}}\Delta(\beta_{0},\beta_{1}) &=&0 \\
& &\\
\frac{d}{d\beta_{1}}\Delta(\beta_{0},\beta_{1}) &=&0
\end{eqnarray*}
for $\beta_{0}$ and $\beta_{1}$. 
}

\frame{
\frametitle{7.4 Modelling the relationship: linear regression}
 Doing so gives some very nice formulae:
\begin{eqnarray*}
\hat{\beta}_{1}   &=& \frac{S_{xy}}{S_{xx}} \qquad \textrm{and} \\
&& \\
\hat{\beta}_{0}   &=& \bar{y}-\hat{\beta}_{1}\bar{x},
\end{eqnarray*}
where the ``hat'' notation $\widehat{\textcolor{white}{L}}$ implies that we obtain \textcolor{purple}{\bf estimates} of the gradient and intercept from our sample data, and not the \textcolor{purple}{\bf true} values of these parameters. \pause

\vsp

Estimate the regression equation for the wine data, and superimpose this on the original scatter plot.}




\sol 
\frame{
\frametitle{7.4 Modelling the relationship: linear regression}
\noindent For the wine data, we have \pause
\begin{eqnarray*}
\hat{\beta}_{1}	&=& \frac{S_{xy}}{S_{xx}}		\\ \pause
		& &					\\
		&=& \frac{81.433}{55.525}		\\ \pause
		& &					\\
		&=&1.467	\qquad \textrm{\sf and}	\\ \pause
		& &					\\
\hat{\beta}_{0}	&=& \bar{y}-\hat{\beta}_{1}\bar{x}	\\ \pause
		&=& 9.258 - 1.467 \times 3.65		\\ \pause
		&=& 3.903.
\end{eqnarray*}
}

\frame{
\frametitle{7.4 Modelling the relationship: linear regression}
\noindent Thus, the regression equation is \pause
\begin{eqnarray*}
Y	&=& 3.903 + 1.467 X + \epsilon.
\end{eqnarray*}
\pause

To plot this line (page 172), we just need to co--ordinates of two points.  We know one of them: $(0,3.9)$.  For another, choose any $x$--value -- say $x=8$:
\[
Y = 3.903+1.467\times 8 = 15.639 \longrightarrow (8, 15.6).
\]
}


\frame{
\frametitle{Modelling the relationship: simple linear regression}
%\begin{figure}[!h]
\begin{center}
\includegraphics[width=10cm,height=7cm]{wine2.ps}
%\caption{Scatter plot of price of wine (\pounds) against age (years), with regression line superimposed}
%\end{figure}
\end{center}
}

\normal
\frame{
\frametitle{Modelling the relationship: simple linear regression}
We can use the estimated regression equation to make predictions of wine price given a certain age.

\vsp 

\pause

For example, suppose we produce a bottle of wine that has been ageing for $4\frac{1}{2}$ years.  How much should we sell it for?  

\vsp
 \pause

Based on our regression equation, we could estimate a selling price per bottle as: \pause
\begin{eqnarray*}
Y	&=& 3.903 + 1.467 \times 4.5	\\ \pause
	&=& 10.505,
\end{eqnarray*}
i.e. about \pounds 10.50. 

}


\frame{
\frametitle{A cautionary note (I)}
As far as possible, avoid \textcolor{purple}{\bf extrapolation}.  \pause
\vspl
\begin{itemize}
\item  Only use the regression equation to make predictions using $X$--values that lie within the range of the data observed \pause
\vspl
\item So we should not use our regression equation to estimate the selling price of a bottle of wine that has been ageing for 12 years \pause
\vspl
\item We cannot be sure that this linear association will continue beyond the range of our data!
\end{itemize}
}
 

\frame{
\frametitle{A cautionary note (II)}
Also care should be taken not to read too much into the regression equation. \pause

\vsp

For example, consider sales of ice cream and sales of sun tan lotion. \pause
\vspl
\begin{itemize}
\item In hot weather sales of ice cream increase and sales of sun tan lotion also increase \pause
\vspl
\item  So ice cream sales may be a useful predictor of sun tan lotion sales \pause
\vspl
\item  However, the act of buying an ice cream does not \textit{cause} someone to by some sun tan lotion... \pause
\vspl
\item ...What is happening is that both ice cream sales and sun tan lotion sales are directly influenced by a third factor: in this case, the weather. 
\end{itemize}
}


\frame{
\frametitle{7.5 Testing the strength of a correlation}
 In Section 7.3 we thought about how we can quantify the strength of (linear) association between a pair of variables $X$ and $Y$.  \pause

\vsp

We then moved on, in Section 7.4, to think about how we can \textcolor{purple}{\bf model} this relationship through the simple linear regression model.  \pause

\vsp

Surely, though, there is no point in estimating the regression equation if there is little, or no, linear association between $X$ and $Y$? 

\vsp

That is, if the correlation coefficient is close zero, we have shown that the strength of linear association is negligible and so why would we then be interested in modelling this negligible/non--existent relationship?  
}


\frame{
\frametitle{Example 7.1}
\noindent The following table shows the total market value of 14 companies (in \pounds million) and the number of stock exchange transactions in that company's shares occurring on a particular day.  Underneath, you are given some numerical summaries; the graph below shows a scatter plot for these data, as produced by \texttt{Minitab}.     
{\tiny
\begin{center}
\begin{tabular}{|c|c c c c c c c c c c c c c c|} \hline
Market value	&6.5	&5.2	&0.4	&1.7	&1.9	&2.4	&3.2	&4.7	&10.1	&12.5	&13.1	&5.5	&2.5	&1.5	\\ \hline
Transactions	&380	&200	&42	&50	&40	&78	&350	&18	&295	&190	&200	&55	&38	&20	\\ \hline
\end{tabular}
\end{center}}
\normalsize
\[
\sum_{i=1}^{14}x_{i} = 71.2 \qquad \sum_{i=1}^{14}y_{i} = 1956 
\]
\[
\sum_{i=1}^{n}x_{i}^{2} = 582.66 \qquad \sum_{i=1}^{14}y_{i}^{2} = 487166 \qquad \sum_{i=1}^{14}x_{i}y_{i} = 13481.6
\]
}



\frame{
\frametitle{Example 7.1}
\begin{center}
\includegraphics[width=11cm,height=6cm]{shares.ps}
%\caption{Scatter plot showing market value versus number of stock exchange transactions for 14 companies}
%\end{figure}
\end{center}
}


\frame{
\frametitle{Example 7.1}
\begin{itemize}
\item [(a)] Find the sample correlation coefficient $r$, and comment.

\vspl

\item [(b)] Formally test the strength of correlation as suggested by your answer to part (a).  
\end{itemize}
}

\sol

\frame{
\frametitle{Example 7.1(a): Solution}
We have
\begin{eqnarray*}
S_{xx}   &=& 582.66 - 14 \times \left(\frac{71.2}{14}\right)^{2} = \pause 220.55714 \\ \pause
S_{yy}   &=& 487166  -14 \times \left(\frac{1956}{14}\right)^{2} = \pause 213884.8571 \\ \pause
S_{xy} &=&13481.6 - 14 \times \left(\frac{71.2}{14}\right)\times \left(\frac{1956}{14}\right) = \pause 3533.942857
\end{eqnarray*} \pause

So
\[
r = \frac{3533.942857}{\sqrt{220.55714 \times 213884.8571}} = 0.515.
\]\pause

\textbf{Comment:} Moderate, positive linear correlation.
}

\frame{
\frametitle{Example 7.1(b): Solution}
We have
\begin{eqnarray*}
H_{0} &:& \rho = 0   \qquad \textsf{(i.e. no correlation in the population)} \pause \\
H_{1} &:& \rho \neq 0 \quad \textsf{ \hspace{0.3cm} (i.e. there {\it is} a correlation!)} \pause
\end{eqnarray*}
The test statistic is 
\[
t = r\sqrt{\frac{n-2}{1-r^{2}}} \pause = 0.515\sqrt{\frac{12}{1-0.515^{2}}}=\pause 2.08.
\] \pause

\vspl

To get the $p$--value, we use $t$ tables (see \textcolor{purple}{\bf Page 156}, Chapter 6) with $\nu=n-2 = 14-2 = 12$, giving: \pause

\vspl

\begin{center}
\begin{tabular}{|c|c c c|} \hline
$p$--value     &10\%  &5\%  &1\%  \\ \hline
Critical value &1.782  &2.179 &3.055 \\ \hline
\end{tabular}
\end{center}

\vspl

So here, $p$ lies between 5\% and 10\%. }



\frame{
\frametitle{Example 7.1(b): Solution}
Thus \pause

\vsp

\begin{itemize}
\item There is \textcolor{purple}{\bf slight} evidence against $H_{0}$ 

\vspl

\item We \textcolor{purple}{\bf retain } $H_{0}$ 

\vspl

\item The correlation observed in the sample is not strong enough to suggest a true correlation between $X$ and $Y$ in the population
\end{itemize}
}



\normal
\frame{
\frametitle{7.6 Multiple linear regression}
\noindent In this section we will show how the linear regression model can be \textcolor{purple}{\bf extended} to include any number of predictor variables. \pause 

\vsp

\noindent The model we have considered so far, namely
\begin{eqnarray*}
Y	&=& \beta_{0} + \beta_{1}X + \epsilon,
\end{eqnarray*}
has been, and is often, referred to as the  \textcolor{purple}{\bf simple} linear regression model, because it only involves a single predictor variable.  \pause

\vsp

However, frequently two or more predictor variables may be useful together to predict $Y$.  
}


\frame{
\frametitle{7.6 Multiple linear regression}
For instance, the sales of a product may depend on \pause

\vspl

\begin{itemize}
\item the product's unit price, \textbf{and} \pause

\vspl

\item the amount of advertising expenditure \textbf{and}\pause

\vspl

\item the price of a competing product
\end{itemize} \pause

\vspl

The simple linear regression model can be extended to include any number of predictor $X$ variables, in which case it is called the \textcolor{purple}{\bf multiple linear regression model}.
}


\frame{
\frametitle{7.6.1 Back to the simple linear regression model}
Recall the example relating age of wine ($X$ years) to price of wine ($Y$ pounds).    \pause

\vspl

By hand, we found the equation of our regression line (the very best line of best fit!) to be \pause
\[
Y = 3.903+1.467X+\epsilon.
\] \pause

Is \textcolor{purple}{\bf Age} an important predictor of \textcolor{purple}{\bf price}? 
}



\frame{
\frametitle{7.6.1 Back to the simple linear regression model}
We can attempt to answer this by testing \pause
\begin{eqnarray*}
H_{0}  &:& \beta_{1} = 0 \qquad \textsf{versus} \\
H_{1}  &:& \beta_{1} \neq 0.
\end{eqnarray*} \pause

We will use \texttt{Minitab} here!
}


\frame{
\frametitle{7.6.1 Back to the simple linear regression model}
Notice that $p=1.6\%$, and so \pause

\vspl

\begin{itemize}
\item We have \textcolor{purple}{\bf moderate} evidence against $H_{0}$ \pause

\vspl

\item We should \textcolor{purple}{\bf reject} $H_{0}$ in favour of $H_{1}$ \pause

\vspl

\item $\beta_{1}$ is significantly different from zero, and so Age \textbf{is} an important predictor of price!
\end{itemize}
}


\frame{
\frametitle{7.6.2 Extending the simple linear regression model}
\begin{center}
%\begin{table}[!h]
%\centering
{\tiny
\begin{tabular}{|c|c c c c c c c c c c|} \hline
Bottle			&1	&2	&3	&4	&5	&6	&7	&8	&9	&10	\\ \hline
Price (\pounds$Y$)	&4.50	&12.95	&6.50	&4.99	&7.50	&14.95	&8.25	&3.95	&18.99	&10.00	\\
Age ($X_{1}$ years)	&$3\frac{1}{2}$	&5&3	&$2\frac{1}{2}$&3&2	&$2\frac{1}{2}$&1&10	&4	\\
Rainfall ($X_{2}$ mm)	&126	&121	&125	&106	&107	&112	&124	&105	&116	&108	\\
Temp. ($X_{3}^{\textrm{o}}$C)&16&20&17	&18	&18	&22	&19	&15	&21	&20	\\ \hline
\end{tabular}}
%\caption{Price of bottles of wine, with corresponding Age, total rainfall and average temperature during growing season}
%\end{table}
\end{center}}

\frame{
\frametitle{7.6.2 Extending the simple linear regression model}
 A multiple linear regression model that may be suitable simply extends on the simple linear regression model:
\begin{eqnarray*}
Y	&=& \beta_{0} + \beta_{1}X_{1} \pause + \beta_{2}X_{2} + \beta_{3}X_{3} + \epsilon;
\end{eqnarray*} \pause
as before, $\epsilon$ is our ``random error'' term, and $\beta_{0}$, $\beta_{1}$, $\beta_{2}$ and $\beta_{3}$ are parameters in the model that we need to estimate.}


\frame{
\frametitle{7.6.2 Extending the simple linear regression model}
\noindent So how do we find $\hat{\beta}_{0}$, $\hat{\beta}_{1}$, $\hat{\beta}_{2}$ and $\hat{\beta}_{3}$ -- the estimated parameters of the model?  	\pause

\vsp

We \textit{can} compute these by hand, as we did in Section 7.4 for the simple linear regression model, but this requires knowledge of matrix algebra which many of you won't have (even if you did A Level maths!).  \pause

\vsp

Anyway, \texttt{Minitab} can perform the calculations for us! }


\frame{
\frametitle{7.6.2 Extending the simple linear regression model}
 Thus, the full (multiple) regression model is:
\begin{eqnarray*}
Y	&=&-22.5 +0.807X_{1}-0.0004X_{2}+1.55X_{3} + \epsilon,
\end{eqnarray*}
where $X_{1}$, $X_{2}$ and $X_{3}$ represent the age of a bottle of wine, the total rainfall during the growing season and the corresponding average afternoon temperature (respectively).  

}



\frame{
\frametitle{7.6.2 Extending the simple linear regression model}
The estimated coefficients of the model indicate the \textcolor{purple}{\bf direction} of the relationship between the price of a bottle of wine and each of the corresponding predictors.  \pause

\vsp

For example:
\begin{itemize}
\item Since $\hat{\beta}_{1}=0.807$ is positive -- positive relationship between age and price (i.e. generally, older wines are more expensive); \pause
\item Since $\hat{\beta}_{2}=-0.0004$ is negative -- negative relationship between rainfall and price (i.e. generally, wines from regions with higher rainfall are cheaper); \pause
\item Since $\hat{\beta}_{3}=1.55$ is positive -- positive relationship between temperature and price (i.e. generally, wines from regions with higher temperatures are more expensive).
\end{itemize}}


\frame{
\frametitle{7.6.3 Testing the importance of our predictor variables}
\noindent Recall Section 7.6.1, where we used \texttt{Minitab} to test the significance of the parameter $\beta_{1}$ in our model.  \pause

\vsp

The null hypothesis here was $H_{0}: \beta_{1}=0$; retention of this hypothesis would imply that the predictor variable attached to this parameter (in Section 7.6.1 this was ``Age'') is not an important predictor of the response variable (Price).  \pause

\vsp

The output from \texttt{Minitab} for our multiple linear regression, which also uses rainfall and temperature as predictors, is shown at the top of page 182 and can be used in a similar way.  }


\frame{
\frametitle{7.6.3 Testing the importance of Age}
\noindent For example, let us once again consider the importance of \textbf{Age} in our model: \pause 
\begin{eqnarray*}
H_{0}	&:& \beta_{1}=0 \qquad \textrm{\sf versus}	\\
H_{1}	&:& \beta_{1} \neq 0. \pause
\end{eqnarray*}
\noindent The $p$--value for this is 3\%. Thus, \textit{age appears to be important in our model}.  
}


\frame{
\frametitle{7.6.3 Testing the importance of Rainfall}
\noindent \textbf{Rainfall} is variable $X_{2}$, which has coefficient $\beta_{2}$.  Our hypotheses are:
\begin{eqnarray*}
H_{0}	&:& \beta_{2}=0	\qquad \textrm{\sf versus}	\\
H_{1}	&:& \beta_{2} \neq 0.
\end{eqnarray*} \pause
\noindent The $p$--value for this is 99.6\%.  Thus, \textit{rainfall is NOT important in our model}.   }

\frame{
\frametitle{7.6.3 Testing the importance of Temperature}
\noindent \textbf{Temperature} is variable $X_{3}$, which has coefficient $\beta_{3}$.  Our hypotheses are: \pause
\begin{eqnarray*}
H_{0}	&:& \beta_{3}=0 \qquad \textrm{\sf versus}	\\
H_{1}	&:& \beta_{3} \neq 0.
\end{eqnarray*}
\noindent The $p$--value for this is 0.2\%. Thus, \textit{temperature appears to be important in our model}.  }


\frame{
\frametitle{7.6.3 Testing the importance of our predictor variables} 
 Since rainfall is not an important linear predictor in our model, we should now remove it and re--fit the model using only age and temperature.  \pause

\vsp

In \texttt{Minitab}, we perform the regression again, but this time include only age and temperature as predictor variables.
}

\frame{
\frametitle{7.6.3 Testing the importance of our predictor variables} 
\noindent Notice that the regression equation has now changed, and now only includes age and temperature.  \pause

\vsp

We now have:
\begin{eqnarray*}
Y	&=& -22.6 + 0.806 X_{1} + 1.55 X_{3} + \epsilon,
\end{eqnarray*}
where $X_{1}$ represents the age of a bottle of wine and $X_{3}$ represents the average temperature during the growing season.  \pause

\vsp

Notice that the $p$--values for both age and temperature are still less than 0.05, so performing a hypothesis test for both would conclude that both are important in the model.
}


  
\frame{
\frametitle{7.6.3 Testing the importance of our predictor variables} 
\noindent The regression equation above represents our ``\textcolor{purple}{\bf final}'' model, in that we have  excluded all variables that are not important predictors of price, and the model now includes only those predictors that \textit{are} important.  \pause

\vsp

We could now use this model to make predictions.  
}


  
\frame{
\frametitle{7.6.3 Testing the importance of our predictor variables} 
For example, suppose you run a vineyard and have just produced a 7 year--old vintage wine.  \pause

\vsp

During the growing season, the average afternoon temperature was $18.5^{\textsf{o}}$C and the total amount of rainfall was 117mm.  How much, per bottle, might this wine sell for?
}

\sol

\frame{
\frametitle{7.6.3 Testing the importance of our predictor variables} 

We have $X_{1}=7$, $X_{2}=117$ and $X_{3}=18.5$. Thus \pause
\[ 
Y =  -22.6 + 0.806\times 7 + 1.55 \times 18.5 \pause = 11.717,
\]
i.e. about \pounds 11.72 per bottle.  
}


\normal

\frame{
\frametitle{7.6.4 The $R^{2}$ statistic}

In the \texttt{Minitab} output shown in these lecture notes so far, you may have noticed something called \texttt{R-Sq}.  \pause

\vsp

Each time you perform a regression analysis in \texttt{Minitab}, the output includes the value of the $R^{2}$ statistic, and this is sometimes used as an overall assessment of the quality of our model.  \pause

\vsp

Technically, the $R^{2}$ statistic tells us how much of the variation in our $Y$ data is explained by the predictors in the model.  
}

\frame{
\frametitle{7.6.4 The $R^{2}$ statistic}
For simplicity, suppose you have the simple linear regression model
\[
Y= \beta_{0}+\beta_{1}X +\epsilon.
\] \pause
If we observe a perfect relationship between $X$ and $Y$, -- i.e. all of our points lie perfectly on a straight line -- then if we know $X$, we know $Y$! \pause

\vsp

The $Y$ value could just be ``read off'' from the regression line. \pause

\vsp

In this case, we would say that $X$ explains 100\% of the variation in $Y$, and the corresponding value of the $R^2$ statistic would be 100\%. 
}


\frame{
\frametitle{7.6.4 The $R^{2}$ statistic} 

Thus, the closer the value of the $R^2$ statistic to 100\%, the better the model.  \pause

\vsp

We can compare the $R^2$ statistic for the various fits we have tried out for the wine data:
\begin{center}
\begin{tabular}{l| c}
  Model                             &$R^2$  \\ \hline
Simple -- including just ``Age'' (page 180) &53.8\% \\
Multiple -- including ``Age'', ``Rain'' and ``Temp'' (page 182) &91.2\% \\
Multiple -- including ``Age'' and ``Temp'' (page 185)   &91.2\% \\\hline
\end{tabular}
\end{center}
}


\normal


\frame{
\frametitle{Example 7.3}
\noindent On a small island the government would like to be able to predict the number of mortgage loans issued by the state mortgage company ($Y$) from: \pause

\vspl

\begin{itemize}
\item The amount of \textcolor{purple}{\bf personal income} in millions of local currency ($X_{1}$) \pause

\vspl

\item The \textcolor{purple}{\bf interest rate} ($X_{2}$)\pause

\vspl

\item The \textcolor{purple}{\bf year} ($X_{3}$)  
\end{itemize}
}

\sol

\frame{
\frametitle{Example 7.3: Solution}
\begin{itemize}
\item [\textbf{1.}] Write down the ``full'' multiple linear regression model that might be suitable for this scenario. \pause

\vsp
\[
Y = \beta_{0}+\beta_{1}X_{1}+\beta_{2}X_{2}+\beta_{3}X_{3} + \epsilon
\]

\end{itemize}
}


\frame{
\frametitle{Example 7.3: Solution}
\begin{itemize}
\item [\textbf{2.}] Use \texttt{Minitab} to fit the model in (\textbf{1}).  Summarise the regression output in the space below, making sure you write down the fitted model.  \pause

\vsp
We get:
\[
Y = 741022+6772X_{1}-1684X_{2}-372X_{3} + \epsilon 
\] \pause

Notice also that $R^{2} = 94.4\%$.
\end{itemize}

}


\frame{
\frametitle{Example 7.3: Solution}
\begin{itemize}
\item [\textbf{3.}] Which, if any, of the variables \textit{do not appear to be important predictors} in your model?   \pause

\vsp


All $p$--values for the predictors are above 0.05 -- suggesting that we would \textit{retain} all null hypotheses: \pause
\begin{eqnarray*}
H_{0}  &:& \beta_{1}=0 \\
H_{0}   &:&\beta_{2}=0 \\
H_{0}    &:&\beta_{3}=0 \pause
\end{eqnarray*}
and so all three predictors would drop out!  However, we only remove one variable at a time -- here, ``Year'', as it's $p$--value is the largest.  
\end{itemize}
}

\frame{
\frametitle{Example 7.3: Solution}
\begin{itemize}
\item [\textbf{4.}]  Remove the least important variable from your model, and re--fit using \texttt{Minitab}.  Again, summarise the regression output in the space below, making sure you write down the fitted model. \pause

\vsp

Removing $X_{3}$ and re-fitting, gives: \pause
\[
Y = 6582+3932X_{1}-1850X_{2}+\epsilon.
\]
Notice that now, $R^{2} = 94.2\%$.
\end{itemize}
}

\frame{
\frametitle{Example 7.3: Solution}
\begin{itemize}
\item [\textbf{5.}] Repeat step 4 until you have removed all variables that do not appear to be important predictors in your model.  Write down your ``final'' regression equation in the space below: \pause

\vsp

Our \textcolor{purple}{\bf final} model includes ``Interest'' only, giving: \pause
\[
Y = 30439-3234X_{2} + \epsilon.
\] \pause
Notice that now, $R^{2} = 90.9\%$.
\end{itemize}
}

\frame{
\frametitle{Example 7.3: Solution}
\begin{itemize}
\item [\textbf{6.}] Comment on the $R^{2}$ statistic in your regression analyses.   \pause

\vsp

The $R^{2}$ Statistic has changed from \pause
\[
94.4\% \longrightarrow 94.2\% \longrightarrow 90.9\%.
\]
Still quite high, even though we've removed two variables! 
\end{itemize}
}

\frame{
\frametitle{Example 7.3: Solution}
\begin{itemize}
\item [\textbf{7.}] This year (2014), the average income is forecast to rise to 4.9 million units of the local currency and the interest rate is set to rise to 5\%.  How many mortgages can the state mortgage company expect to issue this year? \pause

\vsp

So we have $X_{1}= 4.9$, $X_{2}=5$ and $X_{3}=2014$.  So\pause
\[
Y = 30439-3234X_{2} = \pause 30439-(3234\times 5) = 14,269\textsf{ mortgages}.
\] \pause

Notice we didn't need $X_{1}$ nor $X_{3}$!
\end{itemize}
}

\end{document}



\frame{
\frametitle{Example 7.3: Solution}
We remove ``Year'' first, as it is least significant (it's $p$--values is the greatest).  \pause

\vsp

Then we re--fit!
}


\frame{
\frametitle{Example 7.3: Solution}
}




\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

