Documente Academic
Documente Profesional
Documente Cultură
=! !
2
) ---1 ---1
01 1 0011 0011
It. ooeR really m;:ttter a gre;;\J. oe;:tJ to lIR vvllidl ,ve lIRe Rince we are only interesteo
in RolutionR.
Lds look at another exarnple
6x + 3y + 6z 9
x + 21} = 16
4x + 5y + 1z 18
The auglIlented fornl is
(:
:)
6
)
J
2 0
5 1
\Ve h8ve
9 ) C -9 6 -27) C
2 0
;
2
6 ----7 1 2 0 6 ----7 0 3 -2 1
451 1 0 -3 1 -6 0 3 -1 -6 0 0
SonIC :::;teps have been concatenated!
What can go wrong
In reality nothing 1l1uch can go wrong buL v,,re need to exarnine ct couple or cases
\vhere the reslIlt.R we ohtain reC]uire Rome t.hOlIght.
1. Suppose \ve elld up \vith a ro'l.1) of ;;eros. This is no problern, except \vhen
the rllllnber of llOll-zero rOWb is less that the nurnber of variables. Thib just
llleans there is noL an unique solution e.g
x+ 21} - Z 0
x+z 3
2x + 2y 3
104
0
;, )
-2/3
1
-.:)
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
\Ve 11i1VP,
(l
2 -1
+ .. (
1 2 -1 0
)
U
2
-6 )
0 1 0 1 -2 "' -----7 1 -1
-.:)
2 0 0 0 0 0 0 0
This corresponds to
x+y+z -69
y-Z= -3/2
Now there is a solution [or these equations bu t it is not the explicit unique
t.ype we have heen dealing \'lit.h n]1 to novv. If z iR kno,vn, RAy tllen it.
follo\\'R x = 3-z
o
and y = (2zo-3)/2. \Ve hAve a Rolntion fOf every vAIne.
Technically there are an i'njinitc nurnbe-r cf solutions. It is obvious if you
think about it that if you have fevver equations than variables (llnknovvns)
then .you \'lill not have a sirnple bolution.
If we have 2 ro\'lS all zero then \ve have to give d, vdl11e to hvo if
then ;3 variables and so on.
2. No Solllt.ion
Of COllrRe yonf eCjni1.tions mAy not. hRve a Rolntion in that they i1,re c:.ontra-
for exmnple:
x = 1 1) = 3 x = -2 z = 16
\Ve recogni:;r;e t.he eCjllRtionR are ( hAve no Rolntions at all ) in
t.he follo\'ling \'lAy. lfwr: ha?h' a row (;f whirh is all ,".::r:TO e.reept fOT the venj
last ele-rncnt then the equations }u//ue no sol-ution. For exarnple:
Suppose \Vc have the equationb
x - 21) - 3z
2x+ cy + 6z 6
-x+3y +(c-3)z= 0
,vhere c iR Rome conRtant.. \\7"e proc:.eed to ro\'l er;helon
( i
1
-2 3
U
-2 3
c 6 c+6 0
:)
c-3 1 c J
105
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
Before we go fnft11ef \vhat 11;:'\'P1)enS if c = -67 The miridle row of our matrix
correspondR to 0=4 vv11id1 is nonsenRe. Thus the origin;:d eqnation Ret rioes
not have a solution when c = -6
However we will just carryon
( !1
-2 3
D (
-2 3
D
(
-2 3
c 6 0 c+6 2c ---t 0 0 2c - c(c + 6)
3 c-3 0 1 c 0 1 c
C -2
3 1
)
U
-2 3
D
-----101 c 0 -----1 1 c
o 0 2c - c(c + 6) 6 0 -4c - c
2
Now if -4c - c
2
= 0, t11:='1t is c = 0: or c = -4 onf 1:='l,Rt eqnation is 0 = 1
which ib dearly nonsense! This rneans that the original equatiollb had no
solution.
You Illay feel LhetL this is a, bit of a sledge heuluner to crack a nul" but Lhere is
a real IJurpose to our exercise. If you Inove avvay [ronl the trivial cases then the
sdlellle we have outlined above is the best approach. It is etlso the Lechnique use
in t11e c;ompnter pfogr:='lJl1S avail:='l,hle for eqnation Rolving. In the shape of
the fedllceo fO\V echelon form tell ns a lot :='I,hont matrices. Often \ve have a Ry-Rten1
of eqwltions \vhere \ve have SOIne pararneters e,g, using our techniques d,bu'le we
GUl find the range of values: or perhapb the valueb thernsdveb \vhen solution:::; dTe
p0:::;:::; ible,
The row elirnination ideas v,re have outlined are knov,.'ll etS GU;(lss'iau. elhniu.a{:iou.
in llUlllerical circles. The algoriLhnls which beetr Lis neune, \\.'hile ver}' Inuch slicker
:='ITe h:='l,Red on these sinlple ideas.
106
1
)
4
0
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
Exercises
1. SolvA
(a)
2x +3y 7
5x-y 9
(b)
x+3y +3z 1
2x+Sy + 7z
-2x - 4y - Sz
(c)
v-w-x-y-z 1
2v - lV + 3x + 4z 2
2v - 2lV + 2x + y + z 1
v+x+2y+z 0
(0.)
w + 2x - 3y - 4z 6
w+3x+y - 2z 4
ltv + 5 x - 2y - 5z 1 0
2. Consider the equations
V-lV-X-y-z 1
2v-w+3x+4z 2
2v - 2w + 2x + y + z
v+x+2y+z c
For vVll:='tt valuAs of c no tllASA ACtU8tiol1R hmre a UniCj11A Rolution: Are t hArA
:=,my v;:dllAS of c for \vhic:h tllAre is no solution?
107
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
9.0.6 More on Matrices
If we have cUI n x rn lllatrix A "ve need SOHle \\.'c't,y of referring to a, pa,rLicular
elel11enL. It is (:0l11111on 1,0 refer to the (in tll elernent 111ectning the elel11enL in ro"v
i Rnd column j _ \VA think of tllA mAtrix as 118ving tllA form
Q11 Q12 Q 1,11.-1 Q111.
Q21 Qn Q2,11.-1 Q211.
A= a31 Q.E QJ,n-l a3n
cdots
Qm1 Q
m
2 Qm,n-1 um,n
If WA havA a typical ijt h elernAnt \ve RomAtimeR vvritA
TllA unit ma.trix iR an n x n matrix \vith onAS on t hA diagonal 8J1d 7.eros eIRe,vhAre,
usually written I for exmnple
~ n or U ! ! n
So A is 8, unit matrix if
1. It is square.
2. The elernenLs aij satisfy aii = 1 for all i and Qi.j = 0 [or all i -I- j
9.0.7 Addition and Subtraction
\:\7e (;(1.11 i:ldd or subtract rnatricl's that ha'ue the same dimensions by just adding or
subtrading the corresponding elernents .. For exa.lnple
(
all
a12 ) +
( b
ll
b
12
)
(
all + b 11 U12 + b 12
)
a21 a22 b
21
b
22 a21 + b21 U22 + bn
and
(
a"
al2 ) _ ( b
ll
bl2 ) = (
Q" - b"
a12 - b
12
)
a21 a22 b
21
b
22
a21 - b
21
U22 - b
n
(! ~ )
B = (
-4
-3 ) ( -3
-1
)
,vhAn A And -2
~ 1 thAn A + B = !
3
0
0
5
)
'.vhill' A - B = 5
5
108
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
IVlultiplication by a scalar ( nUlnber)
\Ve can nlUltiply a rnatrix A by ct nlllnber s to give sA vvhich is the nmLrix \vhose
elernents ;=t1'e tll0Re of A mnltiplieo hy S, RO if
all a12 a1,TL-1 a1n
021 all 2,TL-1 02n
A= 03rL
m1
Qm.2
m,n-l 01n,n
then
so"
S012 SOl,rL-1 Sa1rL
S021 SOn S02,11,-1 Sa2rL
sA= SOJl S032 S03,n-1 saJn
Sa
m
1 sa
1
n2 sam ,n-1 sa1n,n
\Ve use the Lenn !3c(tLm' [or quantities that are not vectors.
Transpose of a matrix
If \Vc hl,ke a rnatrix A and "vritc thc colunms as ro\vs thcn thc nc\v rnatrix is callcd
thc transpot:lc A writtcn AT or AI
Thus if A = (1\ 122 6) then AT = Notice that (A T)T = A.
Any lllaLrix that satisfies
is s;:'t.io to be symmeirir:. If
A=-A
T
tllen it is ;:'t,nti-symmetric:.
IVlultiplication of IVlatrices
This is a rather 1110re cOlnplicated Lopic. \Ve define Inultiplication in a ntLher
cOlnplex v,ray so that \Ve keep a connection \vith systerl1s of equcttions. Suppose A
is ;:'t,n n x p lYli1trix ano B is a p x nt rnatrix. Then the (ij )th element of AB iR
p
L aikbkj = all blj + ai2
b
2j + aU
b
3j + ai4
b
4j + ... + alp-l b p- 1j + aipbpj
1< 1
109
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
.:\ote tha.t AB is an n x rn Incttrix. One \vay of thinking; of ehis is to notice that
the (ij )th elell1ent of the product n1cttrix is Inade up b}' 111ulLipl}'ing elelnents in
the ith row of the first Inatrix b}' the corresponding elernenLs in the jeh COlUlllll or
tllA sAcono m;:ttrix. The proo.ndR arA then s111'nmeo..
examples
( 1
2 3) ( ! ) = 1 x 7 + 2 x 6 + 3 X 4 = 31
(
~ ) (1 2 3) = ~ ~ ~ ~ ~ )
4 4 8 12
(! 1
2
2) (i n
(
5 22)
28 124
Some conseqnAnc;eR are
-Yon C;:'\J1 only mnltiply matrices if they have the right dimensionR.
In general A B #- BA
AI =A
IA = A but I has different dirnellsionb to that above
AO =0
OA = 0 but 0, a. Inatrix of heros, has dilTerent dilnensions to thctt above
110
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
As we said the reason for this stntnge ideet is so Lhat iL Lies in vviLh linear
equations: thus if
x+2y u
4x+ 9y v
and
v+4y 3
2v-y 0
tllARe can he written in matrix form
ano
So we call write boLh e CeUl wriLe sysLerl1s of equetLions as one rna.Lrix equetLion
4
-1
BAx= (n
)(!
Tllis iR Axact ly thA RamA SAt of Aqnations ,VA ,,\TonIa h8ve h;;"o if ,VA h;:to Alirnin;:tted
U d,nd v \vithout ,m,Y rnatrices.
Inverses
So we have a, whole set of algebraic operations we can use Lo play \vith nletLrices,
excelJt v.'e have not dellned division since if we can rl1ulLiply Lhen \\rh}' not divide?
For ;:'I, ( nOn-7.Aro) nnmher Z ,"VA (;;:'I,n definA the invArRe z-l ,vhic;h s;:'Itisfies
ZZ-l = Z-l Z = 1 .
In the s,une ,"vav we sav that the rnatrix A has an inverse A -1. if there is d, rrld.trix
A -, \vhich .'
Beware not all IIlatl'ices have inverses! Those that do arc said to be non-singular
otherwise a rnatrix which does noL have an inverse said Lo be is singular. If you
111
Mathematics for Computer Scientists Chapter g. Algebra: Matrices, Vectors stc.
think about it you will see that only square matrices can have inverses. Suppose
A is an n x n matrix and B is another n x n matrix. If
AB =BA=I
where I is an n x n unit matrix then B is the inverse of A. Notice A must be
square but not all square matrices have inverses.
We can of course find the inverse by solving equations. For example
So
~ ~ ) ~ ~ )
(
ae+bg af+bh)
ce + dg cf + dh
we then solve the four equations .
ae + bg 1
af + bh 0
ce + dg 0
cf+ dh
Not a very promising approach. However we can use the row-echelon ideas to get
an inverse. All we do is take a matrix A and paste next to it a unit matrix I .
Write this augmented matrix as B = (AI).
We row reduce B to reduced row echelon form. The position of the original I
is the inverse. For example suppose A = (! ~ ) then
B = (AI) (1 2 1 0)
490 1
We get using row operations
(
1210) (12
4901 ----101
and the inverse is A -1 = (!4 ~ )
Of course we check
1
-4
112
9
-4
~ )
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
What can go wrong?
1. If you rnanage to convert the left hand rnatrix A to a unit Inatrix I then you
have succeeded.
2, Sornetirnes a.s }'OU rnanipulate the uugrnented rnatrix B you introduce a row
of zeros inLo Lhe position where )'OU placed A. In Lhis case you can sLop as
there is no 8ol'(llion.
Consider A = ~ ~ ~ ) . Tlle Rllgmented m;:ttrix iR B = ~ ~ ~ ~ ~ ~ o )
45045 1 0 0
Now using ro\v operations we have
(!
:)
6 1
o 0) ( 0
-9 6
-6 0)
0
0 3 1
-6 0)
J
2 0 0 1 0 ---i 1 2 0 0 1 0 ---i 2 0 0 1 0
5 1 0 o 0 0
:J
1 0 o 1
:J
1 0 -4 1 -J -J
U
2 0 0
1 0) C 0
0 -2/9 -3
4/3 )
---i 1 -1/3 0 -4/3 - 1 /3 ---i 0 1 0 1/9
0 1 1/3 2 1 0 0 1
1/3
grvmg 11S our inverse
(-2/9 -3 4/3 )
1/9 2 -1/3
1/3 2 0
(
6 3 6)
COllsider novv A = ! ~ ~ . The auglnenLed 11lctLrix is B =
Novv using ro\v operations ,ve have
(
6 3 6 1 0 0) (0 -9 6 1 -6 0)
1 2 0 0 1 0 ---i 1 2 0 0 1 0
480 0 0 0 0 000 0 0
Given the zero:::; vve kllO\V there is no inverse!
2 -1/3
2
(!
-1
361 0
2 0 0 1
8 0 0 1
Of cour:::;e vve can think of soh"illg equations using irrvcrsc rnatrices. It is d,hnost
cU ways beLLer 1.0 use ro\\' operations on the augrnenLed InaLrix but we CcUI proceed
as follows. If we have the equations
6x + 31} + 6z 9
x+2y 6
4x + 5y + z 18
113
~ )
Mathematics for Com puter Scientists
t hiR can he writtfm as
so
In general if
then
.---1.] A-1 .
prOVlue(1 eXIRtR.
(
-2/9
1/9
1/3
Ax=b
114
Olapter 9. Algebra: Matrices, Vectors stc.
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
SUlnmary
1. The transpose of A vvriLLell AT is 1,he nlct1,rix nw.de by vvriting the rov.'s of A
as col unlns in AT.
2. A is synnnetric if A = A T
;i. The zero matrix is the n X m array of zeros e.g ~ ~ ~ )
;1. The unit rnatrix I ( of order n) is the n x m rnatrix with 1 'b 011 the diagonal
;;mo 7.eros elsewhere e.g. ~ ~ ~ )
001
5. The nlct1,rix A has an inverse B ilI AB = BA = 1. B is vniLLen A -1.
6. A Inatrix \vhich has an inverse is said to be non-singular.
7. Do rernernber 1,hat excep1, in special cases AB #- BA
Exercises
L Givp-n A = ~ ~ ~ 1 ~ 1 ) Rnd B = 0 ~ ) rompntp- AB and BA
2. Sho\v tha.1o ( ~ , ~ 2 ~ ) is skew synnnetric.
-J -4 3
3. IfA= ( ~ 1 !: i) showthatA=A
2
4. Show tha.1o ABT = B TAT
5. Sho\v that the inverse of A B is B-
1
A -1
Find the inverRP- of ( 1
3
1 ) and (!
4
6. 2
6
5
2
5
115
3
~ 3 )
5
2
14
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
Geometry
We write thc point (x, 11) in thc plane as the vcctor X = ( ). If A is a 2 x 2
matrix Ax transforms x into a new point. Suppose A = 1{2) Then
1.
A(n=(n
2.
'J
IJ.
A( n = C{2)
4.
AC ) = e{2)
If we plot the /1 points and their transfonns \ve get
N -
[J
' ---,.
I I
I I
I I
I I
I I
,.... -
>. 0-
";"' -
-2 -1 0 2
x
9.1 Determinants
Considcr the matrix vVc ca:n show that this has an invcrse
when \7 = ad - be =1= bee g.O. 7. The quantity \7 is called the determinant of the
116
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
llw,Lrix A = and is wriLLen I lor del (A). Simibrly
has an inverse when
abc
d e f
9 h i
The general definition of a, deLenninanL of an n x n n1ctLrix A is as fo11ov.'s.
1. If n = 1 Lhen del, ( A) = all
2. if n > 1 Let Mij be Lhe delennin,anl of the (n-1) x (n-1) rnatrix obLa,ined
fr0111 A by deleting row i and colU111n j. Mij is called a, min,or.
ThAn
rt
det(A) = Ul1Mll-U12M12+UnMn-ullJMH+ ... (-1)rt+1UlrtMlrt = L(-1)i+1a1jM1j
i=l
DAtermin;:tntR arA pretty nasty but -VVA :='ITe fortun:='lte as -vve really only 11eed them
for n = 1) 2 01' ;3.
9.2 Properties of the Determinant
J. Any m:='ltrix A :='1110 its tranRpoRe AT have the same oeterminant: i.e. oet(A)=oet(A
T
).
:\ote: ThiR is useful Rince it implieR that -vvhene"ver -vve use ro,\'s, a sirnil:='lT
behavior \vill result if \ve use colurnns, In particular \ve \vill sec ho,v fO,V
elelIlentary operations are helpful in finding the deterrninant,
2. The detenninant (Of OUoa rnatrix is the product of the entries on the
oiago11al, that is e = uel
o
;), If \ve interchange tV{O rows, the deterrninant of the new rnatrix is the opposite
sign of the old that is
117
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
(
9 h i
Note Lh1.tL whenever you want to replace a, rovv by sOlnething (Lhrough ele-
nlentary do not rnultiply Lhe row iLself by 1.t conshtnL. Otherwise,
it is easy to rnake errors: see property 4
6. det(AB)=dct(A)dct(B)
7. A is invertible if 1.tnel only if deLlA) -I- O. Note in Lh1.tL case det (A -1 )=l/deL(A)
\Vhile detenninant s can be useful in geornetry and Lheory they are cOlnplex and
quite difficult to handle. Our last result is for cOlnpleteness and links nl1.tLrix
inverses wiLh detenninants.
Recall tl18t tlle n x n rnatrix A doeR not have 8,11 inverse \vhen net (A)=O. Hovv-
ever the connedion between netennin8,11tR 8,11d matrices iR more complex. Suppose
vve dcfine a nc\v Inatrix: thc adjoint of A say adj (A) as
(
M"
. i-l T -M21
(l,dJA = (( - 1 ) Mij) = , ..
(-1 pL+l MTLl
-M12
M22
(
-1)ll. 1M )T l,ll.
(
-11
TL
-
2
M,.
.
(-1 )2n M
Ttn
iT T !3) T
1 5 ... 1 -2 1 2 -3
\Vhy is 8.nyone interest en in the adjoint: The rnain reason is
A-1 = adjA
dct(A)
Of courbC you \vould havc to havc a vcry special rca.SOIl to cornputc an invcrsc this
wa)',
118
Mathematics for Com puter Scientists
9.2.1 Cramer's Rule
S11ppose we 118ve the Ret of eCju8tions
U1X + b(!-) + C1Z d
1
Q, b, c,
and let D = 02 b
2
C2
OJ b
J
CJ
Q2X + btl) + C2Z d2
Q3
X
+ b J1J + CJZ d3
Then Cramer' R rule stRtes that
d, b, c,
X=- d
2
b
2 C2
0
b
3 UJ C3
1
Q, d, C,
Y =- Q2 d2 C2
D
d
3 U3 C3
1
l
b, d
l
Z=-
02 b
2
d
2
0
b
J
d
J OJ
There is even a, nlOre general case. Suppose vve ba ve
Ax=d
Olapter 9. Algebra: Matrices, Vectors stc.
\vhere x T = (Xl! X2, ... ,x
n
) and d
T
= (d,) d
2
, ... ,d
n
), Let D =det(A).
Then
Xk = ~ ( ~
U'tk-ll
d
1 U'tk III
d
n Qn' QrL(k-lj QrL(k+l)
Ul
n
)
Q
nn
\Vhile this is a nice fonnula you \vould have to be Inad to UbC it to solve equatiollb
since the best v,ray or evaluating big deLenninanLs is b}' ro\\! reduction, etnd this
gi ves solutions directl}'.
Exercises
J. Evaluate
2 4
3 6
119
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
2 4 3
2_
Eval118te 3 6 5
2 5 2
x 2
3_
Evah18te
)
2x+ 1 x
3
x-
0 3x-2 2
4. If A = (:
o 0 9
) show that
14
del(A) = I II
120
Mathematics for Com puter Scientists Chapter 10. Probability
Chapter 10
Probability
Probabil-ity theory 'is nothi'l/.Y bnt COTflU/D'l/. sense 're(hlCed to ca[c:ala-
fion.
Pierre Simon L;:'I,plac;e
In what. followR we are going t.o c;over t.he h;:'l,RiUl of prohahilit.y. The ioeaR are
reasonably btraightforward, ho\vever a.s it involves counting it ib very easy to rnake
rnibtakeb - ab we shall sec.
Suppose we perfortn an experirnent vvhobe out corne is not perfectly predictable
e.g. roll a, die or Loss a coin. Irnagine we rnake a, list of all possible ouLcornes, (all
Lhis list S Lhe sample space. So
If we Loss a coin S cOllsists of {lIead: Tail}, \\'e write S = {lIealL Tctil}:
If a princebb kisses a frog then \ve have two pObbibilities
S= { \ve get a. prince, \ve get an ernbarrassed frog}
\Vhell we roll t \,vo dice then S is the seL of pairs
(1,1 )
(2,1 )
(3,1 )
(4, J)
(i), J )
(f)))
(L2)
(2:2)
(:l2)
( 4:2)
(5:2)
(lA)
(2A)
(:3A)
(
(L5)
(2:5)
(:l5)
(
(1,6)
(2,6)
(:3,6 )
(4,6)
(5,6)
(fjJj)
An event A is a (ollecLion of outcOlnes of interest, for exa.lnple rolling 10\\'0 dice and
getting a double. In this case Lhe event A is dellned as
121
Mathematics for Com puter Scientists Chapter 10. Probability
A = { (1: 1 ) : (2: 2) , ( :),;) ) , ( 4,4) : ( 5: 5) : ( 6: 6) } .
SnpPoRe that tllA Avent B is that tllA Rum iR less th;;tt 4 when we roll two rlice, then
B={ (1,1),(1,2),(2,1)} .
If two events A and B have no elernents in conUI1on then v,re say the}' aremu['ualLy
p:rrlllsi'l!(. For eX8,rnple let A be the event {At le8st one 6} that is
Since A and B have no elernents in COIInI10n they are rnuLuall}' exclusive. Define
Lhe event C as
C={ (2,;3),(25,7)}
Then A and C ,HC also Irmtually exclusive. If D={tmrn cxceeds IO} then A and
o axe not lI1utually exclusive! Check this YO'(l'tselj.
COlnbining events
It is handy to have a s,yrnbol for not A, \ve UbC r.,. A but \VC are not 'vcry picky
and not A is acccptable.
The event A and B, often \vrittcn A rl B ib the bCt of OUtCOIrlCS vvhich belong
both to A etHci 1,0 B.
The event A or B; often \\'riLLen A U B is the seL of ouLCOlnes \vhich belong;
either to A or 1,0 B or to boLh.
Yon \vill recognise the notation from the e8Tlier disc;ussion on setR.
Sup}Jose S={O,L2;:14)\Q,7,8,9} then if\ve define A={1,:3,5,7,9} etnd B={4:5:7}
. .
\ve h8ve
A n B = A an rl B = {5,7}
\Vllile AU B = A or B = {l ,;),4,5,7,9}
122
Mathematics for Com puter Scientists Chapter 10. Probability
10.0.2 Probability - the rules
Now to Aadl Avent WA :='ITe going to Rssig;n a mAAsure ( in RomA vvay ) callAo thA
probability. \Ve will vvritc the probabilit,)" of an evcnt A as P[AJ. \Vc will set out
SOIne rules for the nw.in ones are u.s follows:
1. 0:::; P:AJ :::; 1.
2. P[SJ = 1
3. For InuLually exclusive events A and B P:A or BJ = P[A: + P[BJ
\Ve will ada a few extrR rulAR
(i) For mutu:='IJly exclusivA AVAnts A 1 Ana A2 ano A3 ... An thAn
or written oifferAnt ly
P[A, or A2 or A
3
or An"': = P[A,: + P[A
2
J + P:AJJ + ... + P[AnJ +.,'
(ii) For all evenL A
P [ not AJ = 1 - P :AJ
(iii) For Avents A ana B
P[A or B: = P[AJ + P:BJ - P:A and BJ
All this is (}, bit fiddle,)" but is not really vcry hanL If you vverc not too confused
at this point you vvill have noticed that v.'e do noL have a V .. 'cl}' or geLLing the
prolJalJiliLies. This is a dilTicult point excepL in Lhe case v .. 'e are going to discuss.
10.0.3 Equally likely events
Suppose that every outcoIne of Cl.n experirncnt is equally likely. Thcn \ve UUl shovv
rrOln Lhe rules alJove 1'01' any event A
'AJ = the nunlber of out COlnes in A
p. the nUlnber of possible outcOlnes
123
Mathematics for Com puter Scientists Chapter 10. Probability
This IIleans we can do SOIIle calculatiOlls.
examples
1. Snppose that the ontcomes
tl18t a baby is 8, girl
tl18t a baby is 8, hoy
8re eCj118,lly likely. Then RS there 8re t\VO possihle ontcomes "ve have P[girl]=] /2=P[hoy].
2. Suppose now a f8Tnily has ;) dliloren: the possihilities are
BB BG GB GG
etHci so P[ one boy and one girl]= 2/4=1/2 while P[tv.,o girls]=1/4
;3. The fanlOus shtListician R A Fisher had seven daughters. If }'OU C'OLlI1t the
possihle SACplenC;eR BBBBBBB to GGGGGGG yon \vill fino that there are
27 = 128. Only one seqnenc;e iR 8,11 girl so the prohahility of t hiR event is
]/128.
4. A pair of dice iR thrown. \\lhat is the prohahility of getting totalR of 7 ana
11, Suppose no\\' \\'e throv{ the t\VO dice t\vice. vVhat is the probability of
getting a total of 11 and 7 in this case'!
5. \Ve draw 2 balls frolIl an urn containing () \vhite and 5 bhl,ck: vVHat is the
}Jrobability that we get one \\'hite etnd one bIack betll?
As you ean see vve really need SOine help in counting.
ExercisesS
1. A }Joker hanu c'onsists of 5 cards drawn fron1 et pack of 52. \Vhat is the
}Jfobability tha.1o a hand is a slru;igh r tha.1o is 5 cards in nUlnerical order, but
not 8,11 of tlle S8Tne snit.
2. \Vl18t is tlle proh8,hility that a poker hand iR 8, full house, that iR 8, triple and
8, p8,ir.
3. A 8,no B flip 8, coin in tnrn. Tlle firRt to get 8, head wins. Find the s8,mple
space. \Vhd,t is the probability that A wins?
124
Mathematics for Com puter Scientists Chapter 10. Probability
4. The garne of craps is pla}'ed as 1'o11ov.'s: A player rolls tvvo dice. If Lhe sunl is
a, ~ ;3 or 12 he loses. If the Sllln is ct seven or cUI 11 he \\'ins. OLhenvise the
playAr rollR t.he dice llnt.il l1A gAts l1is initial s c o n ~ : in which case he wins or
gets :='1, 7 in whir;h U1Re he 10ReR. \Vh;:d, is the probability of "vinning?
,). A rnan has n keyb, one of \vhieh "vill open hib door. He trieb keys at ran-
dOIIl, discarding thobe that don't \vork until he opens the door. \Vhat is the
probctbility that he is successful on the kth try.
6. The birthday problenl lIow Inany people should be in a rOOIn Lo Inake the
proh;:thility of t.wo or more hRving t.he SRme birthdRY 1'nore th;:tn O.S? ThiR iR
Cjllit.e diffkll1t. ana a si1'npler approar;h is to c:onRirier t.he prohahility that. no
two people hRve tl1e S:='Ul1e birthday.
It is often a, useful dodge in probability Lo look at P[ noL A: vvhen P[A] is
11:='1,1'0.
So P [ no coincidences] =
365 x 364 x 363 x ... x (365 - n + 1)
365 x 365 x ... x 365
= 1 x (1-364/365) x (1-364/365) x (1-363/365) x x (1-(365-n+ 1 )/365)
Nunlber Probabilit),
125 0.7/1709S()8
16 0.716:39599
17 0.684992:3:3
18 0.65308858
HJ 0.62088147
20 0.58f356162
21 0.55fBIH)6
22 0.52 j]0'i()9
2;3 0./19270277
24 0.46165574
25 0.4:31:300:30
125
Mathematics for Com puter Scientists
Prob of coincident birthdays
:
00
6 -
6 -
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
000
I
10
I
20
I
30
I
40
I
50
number
10.0.4 Conditional Probability
I
60
I
70
I
80
Chapter 10. Probability
SOllletillle it is natural to htlk of the probctbility of an event A given sonle other
eVAnt has oCClllTed. \Ve "vrite the proh;:thility of A given B as P lA 1 B j ann nefinA
it as
Reillernber this is a fancy "vay of writing
P[A 1 B] = P:A and BJ
PlB
\:Vhile conditional probabilities can have interesting philosophic-al ill1plic-ations they
also allow one to do calculations. Thus
P[A] = P[A 1 B]P:B] + P[A 1--- B]P[", B]
or l110re generally if B1! B
2
) ... are the onl}' possibilities so Bi = 1 then
l1.
P[A] = L P:A 1 Bi]P[B
i
]
i=1
126
Mathematics for Com puter Scientists Chapter 10. Probability
127
Mathematics for Com puter Scientists Chapter 10. Probability
Exanlples
1. Consider the t able below.
Ernployed U nernployed Total
IVIale 400 40 500
FernRle 140 260 400
Total GOO 300 900
Then
P[ rvlale] = 500/900
P[ rvIale and Unelnployed] =/10/900
P[ - rvlale] =/10/500 = P[ Unernployed and rvlale] /p[rvIalC:
= /10/000 --;- 500/900 =/10/500,
2. SU}JPose we buy widgets fro111 :3 suppliers A,13 and C. They supply all pro-
ducLion and the 11ulnber of defedi ve itelns per bcttch as "veIl as their share
of our supply is gi ven below.
A
Proportion supplied
0.(-)0
Proportion defective 0.0]
\Vhd,t proportioll of \vidgets are defective'!
\Ve kllO\V
P[defed.iveIA] = 0.03
P[defed.ivel13]=0.0;3
P[defed.iveIC]=0.07
so using the fonnula \ve have
B C
Supplier
0.;30 0.10
0.05 0.07
P[oefedive: =P[oefediveIA: x P[A]+P[oefectiveIB] xP[B: +P[oefect.iveIC] xP[C]
So P[oefective] = 0,03 x 0.6 + 0.03 x 0.3 + 0.07 x 0.1 = 0.034
128
Mathematics for Com puter Scientists Chapter 10. Probability
10.0.5 Bayes
\Ve alRo Bayes Theorem
or
P[AIB] = P[BIAJP[AJ
P[BJ
P[AIB: IX P[BIA]P[A]
(10.1 J
(10.2;
Here :x 1'neanR eqw=d to h11t 1'n11ltiplieo by 8 c,onRtant.
Y011 will often fino t hRt Y011 c,;;m c:ompnte P I B j when re;=dlv von ,v;;mt
PlB I Aj. B8yeR theorem giveR yon the ll1e;;mR for tnrning one into the other.
Examples
J. Take tlle data in the example 2 above. \Ve kno\v that Pldefective I Aj=0.0:3
ano we f0l1l10 that P =0.0:34. Then Sl1ppORe ,ve pick 11p a defective
cOInpollent and ask \vhat ib the probability that it corne frorn A. Thus \ve
need P:A I defective].
\Ve (;8.11 11Re Bayes to give
P[A I defective] = P[defective I A:P:A]/P[defective]
= 0.03 X 0.6/0.34 = 9/17 = 0.529.
2. SnpPoRe tl18t the proh8,hility that a person h8,R 8, oiRease P j = 0.01. A teRt
it:) available vvhich ib correct 90% of the tirne. If \ve use Y to denote that the
test it:) positive and .--... Y negative \ve rnean
P:YID: = P[.--... YI .--... D] = 0.9
:\o\v the probability of a yeb is
P[Y] = P[yID]P[D] + P[YI .--... D]P[.--... D] = 0.9 x 0.01 + 0.1 x 0.99 = 0.108.
The Inore interesting case is
P[DIY] = = 0.009/0.108 = 0.0833
129
Mathematics for Com puter Scientists Chapter 10. Probability
Exercises
1. An insnrance hroker believes th;:'\J, :='t qnartpr of o.rivers are aceioent prone.
\Vhat is Inore the probability of an accident prone driver Inaking a clairn
is 1ri while for a non accident prone drive the probability ib 1/5. \Vhat is
the probability of a dairn'? On his way horne the broker sees that one of his
custorners has driven his car into ct tree. \Vhat is the probabilit}, that this
custorner is accident prone?
2. An nrn cont:=tinR 4 rea ano. 0 green hRllR. One ball iR dnrwn :='d n'mo.om ana
it colonr ohserveo. It iR tllen ret11rneo to the 11rn :=,mo. ;) n8vV h:dls of the
saIne colour are added to the urn, \vhich nO'\v contains 13 balls. .A becond
ball is now drawn frorn the urn.
(a) \Vhat ib the probabilit,y that the first ball dravvn \Vab green?
(h) \Vhat is the proh:thility of getting a red hall gi?}p17. the first h:dl onnvn
was greell
( c) \Vhat iR tlle probability of getting a green hall in the sec;ono dnnv?
3. Sometirne nseo by nnRcrnpnlons stnoents of proh:thility -
\Ve hAve 3 utros. The first c;:tro has t\VO reO. Rio.es, the sec;ono t\VO bl;:tek sideR.
The reInailling card has one black and one red side. Othenvibe the cards are
idelltical.
The three c;ArdR are mixeo in a hat ana one earo. iR Relecteo. at n'mo.om :='m
placpo. on a table. If the exposeo side iR rea \vhat is the prohahility that the
hiddell side is black?
130
Mathematics for Com puter Scientists Chapter 10. Probability
Independence
If P[AIBJ = P[AJ thell \ve say A and B ctre independent. This is usuall}' v.rriLLen in
the equi valent forn1
Independent ib ver,Y ubeful and plays (}, central role in btatibticb.
10.0.6 Random Variables and distributions
If we c;onourJ ;;mo experiment ;=mo Ree ;;m olltcorne we alrnost ;=thV8YR cooe the
olltcorne in Rame vvay, RRy H:T for he;=to ;;mo tRil or even 0,1. The c;ooing iR knO\vn
a.s a. randorn variable, ubually written a.s a. capital buch ab X. If \ve tObb a coin \ve
can bU,Y that the out corne ib X. The actual values rnay be head: head, tail, giving
the sequence of vctlues of X as It II, T: .. \-Ve use randorn variables \\rhen vve have
prouauility distributions, that is lists of possible outcOlnes ctnd prouctuilities: sud1
as in the table
o
0.1
1 2
0.3 0.5 0.1
\Ve point Ollt that the Sllrn of the probabilitieR mURt he one, that iR L o P [X = kJ
\Ve oefine the ellmulati?h' distrih1dion funrtion (c.d..) F( x) aR the curnlllative Rum
of the probabilitieb
k
F(x) = .L P[X = kJ
x l)
So in tlle example above
k 0 1 2 3
P[X=k 0.1 0.:3 0.5 0.1
F(x) 0.1 0.4 O.Y 1.0
It is 1I1Ore usual to give a fornmla for a randorn variable: for exarnple
P[x = kJ = 0.3 X 0.r-
1
x= 1,2,3""
As the fonnula ib cOHnnonly shorter you can see why.
131
Mathematics for Com puter Scientists Chapter 10. Probability
10.1 Expectation
\Ve can also view probability fron1 the point of vievv of vvhat happens in the long
run. Given a randorn variable X define the expected vctlue of X v.'l'iLLen E[X] as
E[Xl = L = xl
(lUx.
The expeded value can be regarded as the Long r(l'l/. avenzye. So if v,re roll a. fa.il
aie and the Ollt.come iR X t.hen = i = 1/6 i = 1,2, ,61 ana so
-11
1
2
1
6
1
..,
E X = x (; + x (; + ... + x (; = .:>.5
You UHl he Rure tll:='tt if YOll roll a die YOll \vill never get ::L,), hOWf'?}fT if YOll rolled
a die and kept an average of the score you \vill find that thib \vill approach see
the plot bclovv
0
.....
=
0
M
cP
=
M
w
0)
rn o.n
W N
0 0>-
m
0)
= c:
'E N
2
.....
0
=
o 20 40 60 80 100
no rolls
For a. coin \ve have Head and Tail. Suppose we count head as 1 and tail as zero,
then
P[X = 1J = 1/2 and P:X = 0: = 1/2
ana so E = 1 x 1 + 0 x :l = A similar experiment gives the following
132
Mathematics for Com puter Scientists Chapter 10. Probability
I"--
a
0
0 0
c.o
00
0
0
o ~
~
~
0
0
u 0
V)
(])
-<::t: 0)
0
~
0
(])
>
C? (1J
0)
0
~
c:
"!
c:
2
0
..-
0
0
0
c>
0 20 40 60 80 100
no rolls
10.1.1 Moments
SOllle inl}JorLant expec-Led values in statistics are the l1/.otru:,ul.s
I1-r = E[XI']
r = 1 )2""
since ,ve can lls11811y esti1'nate theRe \vhile proh;=thilitieR are much 1'nore difficult.
Yon vvill 11Hve met tlle
m.f'(w. ~ l = E [Xj
The 'Lim'iauu:, (J2 = E[(X - 11-)2:.
The pararneter () is knovvn a.s the standard deviation.
Tlle c;entral mo1'nents are defined as
r = 1,2, ...
The third and fourth rnornentb E[(X -11-)3],E:(X -11-)1J: (U'e less eorrnnonly used.
\\-'e ea.n pIove i:U} interebting link bet"\veen the rnean 11- and the variance 0'2, The
result s kno\vn as Chebyshev:s inequaliL}'
(10.3)
This tellb Ub that dep(}Tture frorn the rnean have srnall probability when 0' is srnall.
133
Mathematics for Com puter Scientists Chapter 10, Probability
10.1.2 Some Discrete Probability Distributions
\Ve shall rUll Lhrough sorne of the 1110sL COIIllIlOn and irnportant discrete probability
dis t ri bu tiOllS,
The Discrete 1) niform distribution
Suppose X can take OIle valueb 1) 2) ... ,n \vith equal that ib
1
PlX = kj =-
n
The Hleal1 is E:XJ = TL;-l
k = 1,2
"
" , n
Lhe vctriculCe is var(X) = + + in -
(10.4 )
For example a oie is tllro\vn: the oistrihlltion of the sc;ore X is uniform on the
integer J to 6,
The Binomial distribution
Suppose we have a. series if trials each of vvhich hab t\VO outcorneb, :::;UlTCSS S i:l,Ild
failure F. vVe aSSlll11e Lhat Lhe probctbiliLy of suc'c'ess, P: is c'onshtnL, so for every
trial
Pl Snccessj = p ;:'I,nd Pl fRilure j = 1 - p
e the prolJalJility of X successes in 11 Lra,ils is gi ven by
k=0,1)2,n (10.25)
Tlle meRn is = np
thc Vi:l,rii:l,flCC is "Tar(X) = np( 1 - p)
The IJrobability LhaL a person \vill survive a, serious blood disectse is 0.4. If
15 IJeople have Lhe disease the nUlllber of survi vors X has a, 13inornial 13( 15,0.4)
distribntion.
P [X = 3J = c:) ( 0.4 ) 3 ( 0.6) 12
P[X ::; 8J = (0.4 )X( 0.6) 15-x
P[3::; X::; 8J = P[X::; 8: - P[X:=; 2: = 2 C:)(0.4r(0.6)1!l-X
134
Mathematics for Com puter Scientists Chapter 10. Probability
Applying expectation using the Binomial
A Inore interesting usc is:
Suppose we wish to test wheLher N people have ct disease. It \vould SeelI1 that
Lhe only way 1,0 do Lhis is 1,0 Lake a blood Lest, v/hich v/ill require N blood tesLs.
Snppose WA try the following:
1. \Ve pool t.he hlood of k < N people.
2. If t.he combined s;:trnple is neg;:ttive ,ve have k people vvit hOllt. t.he diRease.
~ i If the pooled test is pot:litive vve then test all k people individually, retmlting
in k + 1 tet:ltt:l ill all.
"'1. Repeat until everyone it:l diagnosed
\VhaL does this save us'?
135
Mathematics for Com puter Scientists Chapter 10. Probability
Assnrne the probabilit:y of 8, person hmring thp, oise8,Re iR p ana that we h8ve a
Binornial dibtribution for the nurnber with the disease. Then for a group of k
1. Pl jnst J teRt = (1 - p) k
2. P[ k+ 1 tests] = 1 - P[ jUt:lt 1 test] = 1 - (1 - p) k
So the expected nurnber of tebtb is
Thib does give a cOllbiderable buving in the rnunber of see the diagrarn belo\v
OJ
J
..-'
-
-
p=
0.1
k
p=
0.001
0
0
_ 00
.0 000
0
a
0
111 1,.,
The Hypergeolnetric distribution
-
I
=
.rl
-
-
p=
0.01
p=
1e-04
0
0
0
_ 00
[a
caoo
0
Cl
1() 1;-'
SnppoRe \ve have :'\ itemR and D of theRe 8Te oefedive. I take a Rample of n
from tllese itemR, then the probability th8t this sample contains k oefediveR is
(
N-D) (D)
P [X = kJ = n-l< k
k = 0, 1,2, ... n (10.G)
The lIleall is E[X: =
1
. . (X) (N-nJ D (1 D)
t le vanance IS vax = (N-l :; n N - N
\\-'hile sit nations involving the lIypergeorneLric are c-onlIIlOn ii COIIllnon practice Lo
approxirnate \\'iLh Lhe 13inornial \vhen N is large cornpared Lo D. \Ve set p = DIN
<1.110 Rue
PiX = kJ = _ p)N-k k = 0,1,2"" n
136
Mathematics for Com puter Scientists Chapter 10. Probability
The Poisson distribution
Suppose events occur at randOlll
k = 1,2, , n (10.7)
The mean is ElX = A
tlle variance is var(X) = A
The average nUlnber of oil tankerb arriving per day at a port is 10. The facilities
at the port can handle at Inost 15 arrivals in a day. \Vhat is the probability that
the port will not be able to handle all the arrivals in a day? The variable X is
Poissoll A = 10 so
IX: lOx 15 lOx
P[X> 16J = -exp(-lOi = 1 - -exp(-lOi = 1 - 0.9513
- L xl ' L xl '
x=16 x=O
137
Mathematics for Com puter Scientists Chapter 10. Probability
10.1.3 Continuous variables
All the eases we have considered so feu' have been vvhere X ta,kes discrete values.
This does not have to be true - we CeUl irnagine X t etking a continuous set of values.
SInce we have tll011gh of :='t probability 8t X=k vve rnight think of the proh.:thility
of X being in Rome Rrnall interv;:tJ x, x + 8x This lwobability will he
< X < x + 8xl = f(x)8x
The function f(x) is called the probability density [unction.
8x
--
3.0
2.0
1.0
\
x
The as can be seen fr'oIn the sketch is Inade up of and if \ve add
these together we get a probability.
Persollally I find it sirnpler to think of the curnula.Live distribution function
F(x) v.'hkh is dellned as P:X :::; x: = F(x). This is just et probabilit}, etnd is what
yon fino in tableR. \Ve re];:tte thiR to the oenRity fnndion by
F(x) = ['" f(t)dt
It iR then not diffir;nlt to sho\v that
P[a < X < b = J: f(t)dt
Typical shetpes are
138
Mathematics for Com puter Scientists Chapter 10. Probability
density function
.........
><
ct'.!
-
E
0
a
c:
q
-0
0
-3 -2 -1
0 1 2 3
x
distribution function
.........
I
CX)
E
0
L-
a
c:
q
a.
0
I I
-3 -2 -1
0 1 2 3
139
Mathematics for Com puter Scientists
10.1.4 Some Continuous Probability Distributions
Unifornl Distribution
Here X is unifolTllly distributed on a, range, sc\y' (a, b) so
1
f(x) = b - a
It follows t.hat. F(x) = PlX < xj = lx-a :='mo Pk < X < dj = ld-C
I-ll 1-(\
Tlle mean is = Qi
b
the vctriculCe is var(X) = (b - a f
TlliR iR a nsefnl mooel for :='t 1'anoo1'n choice in he interval froma t.o b.
Exponential Distribution
Here X is distributed on the range (0) 00) and
f(x) = A exp( -AX)
Chapter 10. Probability
(lO.iS)
( 10.9)
where A is a constant. It follo\vs that f(x) = P[X < xJ
P[c :; X :; d] = exp(Ac)1 - exp(Ad)
- exp(Ax) and
The llleall is E:X] = *
the variance is var(X) = /1.
12
Normal Distribution
Here X is distributed Oll the range (-00) 00) and
1 {(X -
f(x) = JhW2 exp - 2 2
, IT
(10.10)
The HleaIl is E :XJ = J.!
the v:=t1'i;:tnr;e is var(X) = (J2
The nonnal distribution cropt:; up all over the place the probleln is that there it:;
no silnple "vay of working out the probabilities. They can be cOlnputed but you
either need the algoritlun or tables.
140
Mathematics for Com puter Scientists Chapter 10. Probability
N orInal Cornputation
Suppose X has a Norrnal distribution with lIlean 1-1 and Vctrictnce (}"2: often \\.'riLLen
N (1-1) (}"2). \Ve can show that X is rehtted to a, Slo;nda'rd Normal vctrictble z, Llw,t, is
z is lV ((). 1) by
And of course we have the reverbe
x -
Z=--
IT
(10.11)
(10.12)
:\ow the standard nonnal is what is given in the tables do we convert our
prohlem int.o a st<=tnoaro on8.
I. SnpPos8 X iR lV (100,9
2
) Then
(a) P[X:::; 70J = P [z = x-
9
WO :s; :::; -3.33J = 0.004
(b) P[X:::; 95J = P [z = :s; :::; -5/9J = 0.2893
(c) P[X 2:: 109J = 1 - P [z = 2:: 109
9
100 2:: 1J = 1 - 0.2893
(d) P[70:S; X:s; 109J = P:X 2:: 109: - P[X:::; 70J = 0.7017 - 0.004
SUPIJOSe vve wish to llnd the vctlue a so that P [X :::; oJ = 0.95. Then
X-IOO 0-100.
P[X> a] = P[z = > z = = 0.9
- 9 - 9
Fl'Olll htules = 1.645 and so 0 = 100 + 1.645 x 9
Another example
SUPP0i::lC vve kuo\v
1. P[X < 2J = 0.05
2. P[X> 14J = 0.25
So we have
PlX < 2j = = (X - I-..l)/u < (2 - I-..l)/uj = 0.05
ana so fro1'n t.ahles (2 - = -1.645
\Ve dlso have P[X > 14J = 0.25 or
PlX < 14 = PlZ < (X - < (X - I-..l)/uj = 1 - 0.25 = 0.975
lIenee (14 - 1-1)/IT = 1.96 \Ve have a pa,ir of equations
141
Mathematics for Com puter Scientists
1. 2 - I-l = -0- X 1.645
2. 14 - I-l = 0- x 1.96
Solving gives
(14 -I-t) - (2 -I-t) = 12 = 0.3150-
or 0- = 3.32871 and so I-t = 7.475728
The N ornlal approxirnation to the Binornial
Chapter 10. Probability
A 13illOll1ial vctrictble X which is B (n) p) can be apprOXill1a1,ed b}' a, :.\ onnal va,riahle
Y, 11lean np. varia.lKe np(l - p). This can be very useful as the 13illOll1ial 1,ahles
provioeo RTB not very extensive. This is known 0.8 the lVormal apPTo:n:moho17. to
the Rinomi(JL
In tllis CRse
z = (Y - np)/ J(np( 1 - p))
is st;;mdard NormaL
Excunple
SUPIJOSe X is nurnber of 6:s in 40 rolls of a die. Let '{ be :.\ ~ \ 4 i ~ ) . TheIl
5 - 20/3
P[X < 5J ~ P[Y < 5J = P[z < . J5679 J = <!J( -0.7071068) = 0.2398
, 50/9
You can refine thib approxiInation but \ve "vill bettIe for this at the rnornent.
Exercises
1. A die is rolled; \x,rhat is 1,he probahili1,}' that
(a) Tlle ol1tc;ome is even.
(0) The outC'OllIe is a, prirne.
( c) The 0 u t C'Olne exceeds 2.
(d) The outcolIle is -1.
(e) Tlle ol1tc;ome is leRR tl18Jl 12.
2. T\vo dice are rolled. \Vhat is the probability that
(a) The SUIn of the upturned faces ib 7'!
(b) The score on one die is exactly twice the score on the other.
142
Mathematics for Com puter Scientists Chapter 10. Probability
(c J You thro\v a double, that is the dice each have the SHIne beore.
3. Suppobe we toss a coin ;3 tinleb. Find the probability distribution of
(a) X=the nUIIlber of tails,
(b) Y = tlle number of nms. Here;:'l, run is a Rtring of or tailR. So for
HTT Y=2,
;1. The student population in the rvraths departIIlent at the niversity of San
Diego \vas rnade up ab follo\vs
10% were frOI11 California
6% \vere of Spanibh origin
2(7r: were fron1 California, and of Spanish origin.
If;:'l, Rtuoent from the d;:'l,RR vvas to be oravvn ;:'It ra11o.o1'n ,vhat iR the prohahility
that they are
(a) FroIn California or of Spanibh origin.
(b) .\either frol11 California, nor of Spanish origin.
(c) Of Spanish origin but not fr'oIn California
143
Mathematics for Com puter Scientists
5. FbI' two event.s A and 13 the follov.'ing probabilities are kno\vn
P:A] = 0.52
Determine tlle probabilitieR
(a,) P[A n B]
(h) Pl"" A
(c) [ ~ BJ
P:B] = 0.36 P:A u B: = 0.68
Chapter 10. Probability
6. A hospihtl Lrust dassilles a group of Iniddle aged Inen according Lo bod}'
weigllt and the incjoence of hypertension. The reRults :='ITe gi'ven in the table.
() ver\veight Nonna'! \Vcight l ~ ndcnveight Total
IIypertensi ve 0.10 0.08 0.02 0.20
Not HypertenRive 0.15 0.4;) 0.20 0.80
Total 0.25 0.53 0.22 1.00
(a) \Vhat is the probability that a person bclectcd at randorn horn this
group will have hypertension?
(h) A perRon seledeo at ranoo1'n from this gronp iR founo to he overvveight:
\vhat is the prohahility that t hiR person is :='IJso hypertensive?
(c) Find P)l.YI)('rtensivc U Undenvcight:
(d) Find P )wperLensi ve U Not U ndervveight]
7. T\vo cardR :='ITe orav{n from an ordinary deck of 52 C:='ITOS. \Vhat iR the proh-
ability of dru\villg
(a,) Two aces.
(h) Tlle two hlack :='I,ces.
(c) T\vo ulTds froIn the court cards KJl,.J
( a) Four cardt:l arc aceb
(b) Fbur cards are the sarne Le. 4 10's, 4 9'2 etc.
(c) All the C:='ITOS :='ITe of the Rame snit.
(d) All the card are of the sarne suit and are in sequence.
144
Mathematics for Com puter Scientists Chapter 10. Probability
9. A Rtudent. of st.atistics "vas t.old t.hat. tllere \vas a chance of 1 in a million that
there wab a. bornb on an aircraft. The reasoned that there would be a one in
10
12
chance of being two bornbs on a plane. He thus decided that he bhould
take a bornb with hirn ( defused - he vvas lloL st upid) 1,0 reduce Lhe odds of
an ex plosioll.
Assurning no securit.y problcrnb is this a bensible strategy?
10. There arc four ticketb rllunbered 1),;3,.-1. A two digit nurnber ib fonned by
drawing; a ticket at randorn frolll the four and a secolld frorn the relnaining;
three. So if Lhe tickets were 4 and 1 Lhe resulting; nurnber would be 41. \\7hat
is the probetbiliLy Lhat
(a) TllA rARulting nllmher is even.
(b) The resulting; nUlllber exceeds 20
( c) The rebulting rnunber ib bet\veen 22 and ;30.
11. Three production lines contribute to the total pool of parts ubed by a corIl-
pan,Y
Lille 1 conLributes 20% etnd 15(7r: of iLelllS etre defective.
Lille 2 contributes 50% and 5% of iterIlS arc defective.
Lille :3 conLributes 30% etnd 6% of iterns are defective.
(a) \Vhat. perr;entage of items in the pool :='ITe oefective?
(b) Suppose an iLelll was selected at ntndorn etnd foulld to be defective,
",,,-hal, is the probabiliLy LhetL it c-a.lne frolll line I?
(c) Suppose all itelIl "vas bclected at randorIl and found not to be defective,
whaL is the probabiliLy LhetL it c-a.lne frolll line I?
145
Mathematics for Com puter Scientists Chapter 10. Probability
10.2 The Normal distribution
This table gi,ies the cumulative probabilities for the standard
lIor1l1al d1stribllt1(11) thHt is
P[Z S zJ = -= exp( _x
2
j2)dx r 1
yl2n
This is the shaded area in the figure.
L
?; 0.00 -0.01 -U.U2 -0.04 -0.05 -0.00 -0.7 -O.OD
-3.'1 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0002
0.0005 0.0005 0.0005 0.OUU4 U.0004 (.1.0004 0.0004 0.0004 0.0004
-3.2 0.0007 0.0007 O.OOOG O.OOOG O.OOOG O.OOOG O.OOOG 0.0005 0.0005 0.0005
-3.1 0.0010 0.0009 0.0008 0.0008 0.0008 0.0008 0.0008 0.0008 0.0007 0.0007
0.001 ;) 0.001 ;) 0.0013 0.0012 0.0012 (.1.0011 0.0011 0.0011 0.0010 0.0010
-2.9 0.0019 0.0018 0.0018 0.0017 O.OOlG O.OOlG 0.0015 0.0015 0.0014 0.0014
-2.8 0.0026 0.002.5 0.002-'1 0.0023 0.0023 0.0022 0.0021 0.0021 0.0020 0.0019
-2.7 0.00:)5 0.00;)4 0.00;)3 0.0032 0.00:)1 O.O();)O 0.0029 0.002S 0.0027 (.1.0020
-2.G 0.0047 0.0045 0.0044 0.004:1 0.0041 0.0040 0.00:19 0.00:18 0.00:17 0.003G
-2.5 0.0062 0.0060 0.00.58 0.0057 0.0055 0.005.-1 0.00.52 0.00.51 0.00-'18 0.0018
-2.4 O.OOSO 0.007S 0.0075 0.007:) (.1.0071 0.00ti9 O.OOtiS 0.0000 0.00ti4
-2.:) OJ)107 0.0104 0.0102 o.omm O.OODti 0.00D4 0.0091 0.00S7
-2.2 0.0139 0.01:16 0.01:12 0.0129 0.0125 0.0122 0.0119 0.0116 0.011:1 0.0110
-2.1 0.0179 0.017--1 0.0170 0.0166 0.0162 0.0158 0.01.5'1 0.01.50 0.01-'16 0.0113
-2.0 0.0222 0.0217 0.0212 0.0207 (.1.0202 OJ)197 0.0192 O.OlSS 0.01
-1.9 0.0287 0.0281 0.0274 0.0268 0.0262 0.0256 0.0250 0.0244 0.02:19 0.0233
-1.8 0.0359 0.03.51 0.031-'1 0.0336 0.0329 0.0322 0.031-1 0.0307 0.0301 0.0201
-1.7 0.044ti 0.04;)ti 0.0427 0.041S 0.040D 0.0401 0.();)92 0.0375 (.1.0307
-1.6 0.0548 0.05:17 0.0526 0.0516 0.0505 0.0495 0.0485 0.0475 0.0465 0.0455
-1.5 0.0668 0.06.5.5 0.06.-13 0.0630 0.0618 0.0606 0.059-1 0.0.582 0.0571 0.0550
-1.4 0.079;) 0.077S 0.0704 0.074D 0.07:)5 0.0721 0.070S 0.0094
-1.3 0.0968 0.0951 0.09:14 0.0918 0.0901 0.0885 0.0869 0.085:1 0.08:18 0.0823
-1.2 0.1151 0.11:11 0.1112 0.109:1 0.1075 0.1056 0.10:18 0.1020 0.100:1 0.0985
-1.1 0.1357 0.133.5 0.13V1 0.1282 0.1271 0.1251 0.1230 0.1210 0.1180 0.1170
-1.0 0.15ti2 0.15;)9 0.1515 (.I. 14D2 (.I. 1409 0.144ti 0.1423 0.1401 0.137D
-0.9 0.1841 0.1814 0.1788 0.1762 0.1736 0.1711 0.1685 0.1660 0.16:15 0.1611
-0.8 0.2119 0.2090 0.2061 0.2033 0.2005 0.1977 0.19,19 0.1922 0.188;1 0.1867
-0.7 0.2420 0.2;)5S 0.2327 (.I. 22 Do (.I. 220ti 0.22;)ti 0.2200 0.2177
-0.6 0.274:1 0.2709 0.267G 0.2G4:1 0.2G11 0.2578 0.2546 0.2514 0.248:1 0.2451
-0.5 0.308.5 0.30.50 0.3015 0.2881 0.2816 0.2912 0.2877 0.28.-13 0.2810 0.2776
-0.4 0.:)44ti 0.:)409
(};);)72 0.;)330 0.3300 (.1.3204 (};)192 0.;)150 0.3121
-0.3 0.3821 0.378:1 0.:1745 0.:1707 0.:1G69 0.:1632 0.3594 0.:1557 0.:1520 0.:1483
-0.2 0.1207 0..t168 0.-1128 0.-1080 0.-'1052 0.-'1013 0.397--1 0.3936 0.3887 0.3859
-0.1 0.4002 0.45ti2 0.4522 0.44S3 0.444:) (.1.4404 0.4:)ti4 0.4;)25 0.42SO 0.4247
0.0 0.5000
146
Mathematics for Com puter Scientists Chapter 10. Probability
This table gives the cumulative probabilities for the standard
lIor1l1al distrilmt101I) thHt is
fZ 1 '
P[Z z] = f)"; exp( _x
2
/2) dx
--oc '\ 271
This is Lhe shaded area ill Lhe Iigure.
z 0.00 0.01 0.02 0.03 0.0'1 0.0.5 0.06 0.07 0.08 0.09
0.0 0.5000 0.5040 0.5080 0.5120 0.5160 0.5199 0.52;19 0.5279 0.5;119 0.5359
0.1 0.5398 0 .. 5''138 0 .. 5,'178 0.5517 0.5557 0.5.596 0 .. 5636 0 .. 5675 0.5711 0.5753
lL2 0.579:) U.5910 lU::i02ti lU::iOti4 0.ti10:) 0.ti141
0.;1 0.6179 0.6217 0.6255 0.6293 0.6331 0.6;168 0.6406 0.644;1 0.6480 0.6517
0.--'1 0.6.5.5--'1 0.6.5[H 0.6628 0.666'1 0.6700 0.6736 0.6772 0.6808 0.68'11 0.6879
0 .. 5 0.691.5 0.6950 0.6885 0.7019 0.705--'1 0.7088 0.7123 0.7157 0.7190 0.722--'1
lU::i 0.7257 lL 7291 lL7324 0.7357 0.7422 lL7454 0.7517 0.7549
0.7 0.7580 0.7611 0.7642 0.7673 0.7704 0.77;14 0.7764 0.7794 0.7823 0.7852
0.8 0.7881 0.7910 0.7839 0.7867 0.799.5 0.8023 0.80.51 0.8078 0.8106 0.8133
0,9 Sti (JS2:)S lJ.S2ti4 15 (JS3ti5 0.S:)S9
1.0 0.841;1 0.84;18 0.8461 0.8485 0.8508 0.85;11 0.8554 0.8577 0.8599 0.8621
1.1 0.86--'13 0.8665 0.8686 0.8708 0.8729 0.87-'19 0.8770 0.8780 0.8810 0.8830
1.2 (JS907 0.S9D7 0.9015
1.;1 0.90;12 0.9049 0.9066 0.9082 0.9099 0.9115 0.91;11 0.9147 0.9162 0.9177
1.,'1
0.0192 0.9207 0.9222 0.8236 0.9251 0.926.5 0.9278 0.9282 0.8306 0.8319
1.5 0.D;);)2 0,9;)45 lUJ357 0.9370 lU);)94 lUJ40ti lUJ41S 0.942D 0.9441
1.6 0.9452 0.946;1 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.963;1
1.8 0.06--'11 0.96,'18 0.9656 0.866,1 0.9671 0.9678 0.9686 0.9683 0.8600 0.8706
1.9 0.D71 ;) lUJ719 lUJ 72 ti 0.97:)2 0.D744 lUJ750 lUJ75ti 0.97til 0.97ti7
2.0 0.9772 0.9778 0.9783 0.9788 0.979;1 0.9798 0.980;1 0.9808 0.9812 0.9817
2.1 0.0821 0.9826 0.9830 0.883,1 0.9838 0.98-'12 0.98-'16 0.9850 0.885-1 0.8857
2,2 lUJStiS (J9S71 lUJSS4
2.;1 0.989;1 0.9896 0.9898 0.9901 0.9904 0.9906 0.9909 0.9911 0.9913 0.9916
2.,'1
0.0918 0.9920 0.9822 0.8825 0.9927 0.9929 0.9931 0.9832 0.883;1 0.8036
2,5 0,9940 lUW41 0.994:) 0.DD45 0.D94ti lUm4S lUW49 0.9951 lUHJ52
2.6 0.995;1 0.9955 0.9956 0.9957 0.9959 0.9960 0.9961 0.9962 0.9963 0.9964
2"" ./ 0.096.5 0.9966 0.9867 0.8868 0.9969 0.9970 0.9971 0.9872 0.8873 0.807--'1
2.8 0.097-'1 0.9975 0.9876 0.8877 0.9977 0.9978 0.9978 0.9878 0.8880 0.8081
2,9 lUmS2 lUWS2 lUWS5
;1.0 0.9987 0.9987 0.9987 0.9988 0.9988 0.9989 0.9989 0.9989 0.9990 0.9990
3.1 0.0990 0.9981 0.9881 0.8891 0.9992 0.9992 0.9992 0.9882 0.8803 0.8003
;),2 lUm93 0,9994 0.99D4 0.DDD4 0.D994 0,mm4 lUW95 (J99D5 0.9DD5
;1.;1 0.9995 0.9995 0.9995 0.9996 0.9996 0.9996 0.9996 0.9996 0.9996 0.9997
3.--'1 0.9997 0.9987 0.9887 0.8897 0.9997 0.9997 0.9997 0.9887 0.8897 0.8998
147
Mathematics for Com puter Scientists Chapter 11. Looking at Data
Chapter 11
Looking at Data
It is very much more difficult to handle data rather than to construct nice probability
arguments. \Ve begin by considering the problems of handling data. The first questions
prOVE-nla1}(;p. of tIlE-l data.
Is it rp.lia,bh-l?
\Vho collected it?
Ie; iL w haL iL is said Lo be?
Is it a srlmplp. rlnd frolll \vIlat population?
Such questions are inlportant because If the data is wrong no amount of statisticaL theory
'/1,"ill Tf/,(],k:p 'it lwttpf', Colh-lding YOllr O\Vll drltc-l, is tbE-l rlS you sll()llld knO\v \vhrlt is
going on. AlmosL all sLatistical Lheory is based on Lhe assumption thaL Lhe observaLions
are independent and in consequence there is a large body of methodology on sampling
alld drlta (;ollp.ctioll.
11.1 Looking at data
Once you have Lhe data vvhat is he nexL sLep? If it is presenLed as a Lable ( do read
the description) it may well be worth reordering the table and normalising the entries.
Silllplifyi11g amI rOllnding call p.spE-lcirllly ill rE-lports.
data, iL pays to look at Lhe daLa in as many \Nays as possible. Any unusual or inLeresUng
patterns in the data should be flagged for further investigation.
The Histogranl
Anyone \vho does noL dra\v a picLure 01' their daLa deserves all the problems LhaL they
'-vill undoubtedly encounter. The ba.,ic picture is the histogram, F'or the histogram we
split tbE-l rallgE-l of drlta i11tO intE-lrvrlls a11(1 COll1lt nll1llhE-lr of ohsE-lrvi-l.tions i11
148
Mathematics for Com puter Scientists Chapter 11. Looking at Data
interval. VVc thcn construct a diagrmn Inadc up of rcctangles crccted on cach intcrval.
ThE-l a'f'P(]. of tllE-l rE-lctallg1E-l proportiOllii,1 to thp. COllllt.
110 190
5,)
65 4:3 ]5 40 :32
11
;1 ..t 7f) 28 12 15 37
19 70 12 17
.",
,),.) ,19 If)
150 29 18 21 60
,13 2" ,.) ;3()
22 11 26 29 82 6 21 64
84 7;3 54 44 82 16 95 29
30 27
8,)
')r.
.. h) 5 22
,)2 ]9
18 17,) 10 20 29 Hi Hi 20
17 6 47 130 1 ]5
')'""'
IJ ( ,)0 ]7
..tl 61 116 55 67
2() 251 9
50
..t;3
80 52 17 22 28
8 27 ;32 75 10 45
Table 11.1: Dorsal lengths of octapodt:l
Histog..-a.-n of' oct:
=
,I
-
() 1 (ll) L(H)
oct
11.1.1 Summary Statistics
LocaUon This he; of Len called Lhe measure of cenLral in our texLbooks, or the
of Lhe daLaseL in oLher sources. Common measures of location are the
mcan and nlcdian. Lcss comnlon meW31HCS arc thc modc and thc truncated nlcan.
Giwm obsE-lrvrlti01IS Xl) X2, ... ) Xn
Thc sample mcan isjust 1 Xi. writtcn x. For thc Octopods it is ;H.67021.
Thp. H1E-ldirln is thE-l llliddlp. ValllE-l, WE-l armngp. tbE-l obsE-lI"vatlolls 111 oniE-lr ii.lId if
n he; odd pick Lhe middle one. If n he; even Lhen \\Ie take Lhe average of the
two middle values. For thc Octopods it is 32.5
149
Mathematics for Com puter Scientists Chapter 11. Looking at Data
A trllllcatE-ld H1P.<1.1I i:-; dip. 11JE-lrHl of rl dat<1. :-;E-lt whp.rp. :-;01JJE-l ]rlrgp. or :-;111<1.11 (or
bOLh) observaLions have been deleLed.
As you might expect the lllcdian is much less influenccd by outliers - it is a robust
P.:-;t i 11 I i1J P..
Histogram of oct
-
l.O
-
'"
=
'"
-
:>-..
U
c:
cr
CJ)
r--
U:::
;=
l.O
rn
=
I I I I I
0 50 100 150 200
ocL
Example
ThE-l Allstm]irl1l TIllrp.i1,1l of lVIdp.orology col1E-lds (htrl 011 ri1j1lfall rlcross Allstra]irl.
Given belO\v is Lhe mean monthly rainfall in Broken Hill a..c; 'well as Lhe median
monthly rainfall.
Average l\lonLhly n ainfall in Broken Hill (in millimeLers) 1900 Lo 1990
J\IonLh l\lean J\Iedian
.Tan 2;1 9
Fp.b 24 10
l\1ar 18
!)
Apr 19
!)
J\Iay 22
I")
d
.Tun 22 15
.1111 17 15
Aug 19 17
Sep 20 12
Od 25 15
"KOY 19 10
Dp.(: 20 7
150
Mathematics for Com puter Scientists Chapter 11. Looking at Data
(a) _\Jotc that thc median monthly rainfall is January is much smaller than thc
ll1E-lrH\ 111011tll1y rai1lfrllL \Vhrlt dOE-ls this illlply ahollt t hp. sllapp. of tlle distri-
bution of Lhe rainfall data for the monLh of January'!
(b) \Vhich measure of cenLral Lendency, Lhe mean or Lhe is more ap-
propriate for dcscribing rainfall in Brokcn Hill? Justify your answer using
knmvlp.dgE-l of ll1E-lrln amI lllE-l<iiall.
(c) UsP. tllE-l ahovE-l ti1hlE-l to caknlaJ,E-l thp. total YE-larly minfall for Orokp.ll Hill.
(d) In Lhe norLh of the \-veL season occurs from Novelllber to April.
Broken in central is occasionally drenchcd by a northern
stOrlll dllrillg t hp.sE-l months. TllE-lsE-l storllls tE-lnd drop rl Irlrge rlmOllnt of raill
in a comparaUvely short Lime. How does the Lable reLled this facL':
Spread This is Lhe amount of variaUon in Lhe daLa. Common measures of spread are the
sample variance, standard dcviation and the interquartile rangc. Lcss common is
tllE-l mngp.. Thp. traditionrll ll1E-lrlSnrE-l is tllE-l s(Jmplf'- '(7(].rimu'p
TL
,2 1 L - 2
t> -- (xi-xl
n '
i 1
and dip. squarp. root of tllE-l srlmplp. variiUlce kllO\Vll rlS t hE-l .c.;tando:rd (if:v-{ohon
For the odopods s=:1G.OGlf>9. AlLernaLi ves are:
The range This is delined as
range = largcst data value - smallest data value
tllis is obviously not vp.ry rolmst iUld llencE-l is not OftE-lll nSE-ld wllicll is a shrlmp..
InLerquartile Range The inLerquartile range Q:1-QL \vhile simple in concepL, has caused much
grief to introductory statistics teachcrs sincc differcnt rcspectable sources
dHfille it in different rp.spE-letahlE-l WrlYs! First WE-l find tlle lowp.r qllrlni.lE-l Ql
Lhis is the k = (n/4)th of Lhe ordered observations. If k is not an integer 'vve
take the intcger part of k plus 1 othcnvise \ve talw k+ 1. Thc upper quartilc
Q3 is obtrlilled by cOll1ltillg dmvll from t hE-l nppE-lr E-llHI of tllE-l ordered srlmplp..
This is a good robusL mea..c;ure of spread. For Lhe Odopods Q;1-Ql= 59.25
-18.00 =10.25.
151
Mathematics for Com puter Scientists Chapter 11. Looking at Data
Shape
The shapc of a datasct is commonly categorized a.., symmctric, right-skcwed
or bi-lllodaL TllE-l :-;hi1PE-l is ;1,11 importallt frldor informing tllE-l dE-lcisions on tIle best
measure of location and spread. There are several swmnary mea...c;ures. The sample
third InOlnent
mcasures skc\'lness-it is zero for a SYll1l11ctric distribution. The fourth moment
gives a flat top mea..,urc. It is 3 for a normal variable!
Outliers
Outliers are data values that lie mvay from the gcneral cluster of other data values.
Erldl olltlim' lIE-lE-lds to bE-l eXrlminE-ld to dE-ltE-lrlllillE-l if it rE-lpn-;sellts ;1, possiblE-l va.1uE-l frolll thE-l
population being sLudied, in \Nhich case it should be reLained, or if iL is non-represenLaLi ve
(or an error) in "\vhich case it can bc cxcludcd. It may be that an outlicr is the most
importallt fe;1,tllrE-l of a dataset. It is said t hrlt the 07.011e llOle rl hOVE-: tIlE-: SOllth Pole llad
bE-lE-ln detE-lded by a srltE-lllitE-l YE-lrlrs bE-lfore it "\Vl-l . '-\ dmectE-ld by gToll1}(1-hrlsed ohservations)
buL the values \vere Lossed ouL by a compULer program because Lhey \-vere smaller Ulan
\'lcrc thought possible.
Clustering
Clustering in1plies that thc data tends to bunch up around certain values.
Granularity
Granularity in1plics that only ccrtain discrete valucs arc c.g. a company may
ollly prlY srl],uies in mllltiples of 1 )000. A dotplot sllm'ls gmnnlarity rlS strlcks of dots
separaLed by gaps. DaLa LhaL is discreLe onen shovvs granulariLy because of its discreLe-
ness. ConLinuous daLa can show granulariLy if the daLa is rounded.
11.1.2 Diagrams
ThE-lrE-l is lII11ch to be si1,id for driPNillg pidllres. It is liard to illli1,gillE-l ii, di1,ta sm \vhE-lrE-l i1.
histOgTiUlI is lIot nSE-lfll1. If YOllr c01IlImtE-lr progTiull does lIot dri1w pidllres t hE-:ll replrlcE-l
iL! I rather like Lo Sl1lOoth the hisLogram Lo geL an idea of Lhe shape of Lhe p.d.L
l\ote hm'lever ,ve nced to takc care evcn \'lith the humble histogram! Ideally a
histOgTiUlI shollld show the slH-tpe of the distrilmtioll of the drlta. For somE-: dati1,sets 1mt
152
Mathematics for Com puter Scientists Chapter 11. Looking at Data
the choice of bin \vidth can hmre a profound effect on how the histogram displays the
(hbL
SteIn and Leaf charts
If YOll an-l hI a COl IlplltE-lr-fn-lE-l E-lHvir01l1llmlt a stE-lm-a1l<1-lml.f plot call hE-l a quick a11 E-lffp.ctivE-l
way of drawing up such a charLo ConI,ider Lhe daLa belO\v
stem
2
3
4
5
'27
37
,17
leaves
789
0123456789
0123456789
0123456
'2g
38
,18
2D 30
;)1 ;)'2 :):) :)4 :)5 36
39
,-to --11 --12
,13 ,1,1 ,15 /'16
,-t9
50 .51 .52 53
5,1
55 56
freq cum freq
3 3
10 13
10 23
7 30
Such a stem and leaf charL is valuable in giving an appro.x.imaLe hisLogram and giving
the ba.,is for some interesting data summaries. As you can see it is fairly ea.,y to find
tllE-l rallgE-l m.c. frolll thp. stmll iWeI Ip.i1f Cbiut.
Dotplots
A tmditi01H1.1 dotplot rE-lsE-lmblp.s r1 stE-l1Ilplor. lyi11g on its bc1,ck) with dots mplr1cillg tbE-l
values on Lhe leaves. H does a good job of displaying Lhe shape, location and spread of
the distribution, as \vell as shmving evidence of granularity and outliers. And for
slIlallisb dati1,sds r1 dotplot is E-lc-l..'-'Y to c01lstrllct, so r.11E-l dotplot is a piuticnlr1rly va.111a.blE-l
tool for Lhe sLaLisLics sLudenL vvho is \-vorking wiLhouL technology.
Box-Plots
A.llOLher useful pid ure is Lhe box ploL Here \ve mark Lhe quarLiles Ql Q2 on an axis and
drmv a box viTllOse ends are at these points. The ends of the vertical lines or
indici1JE-l tbE-l minimlllil amI llli1,ximlllll dati1, ValllE-ls) llnlE-lss olltliE-lrs r1rE-l prp.SE-lllt i11 \vllidl
ca..c;e the whiskers exLend Lo a maximum of 1.5 Limes Lhe illter-quarLile range. The points
outside the ends of the \vhiskers arc outliers or suspected outliers. can be very useful,
E-lspE-lcir111y vdlml llli1,king COl Ilpi1,ris01 IS.
One drmvback of boxplots is that they tend to empha.,ize the tails of a distribution,
\vbicb arE-l tllE-l IE-lr1st Cp.rtai11 poillts ill tbE-l di1Ja sd. TIIE-lY r11so bidE-l mr1ny of thp. ddr1ils
of Lhe disLribuLion. Displaying a histogram in conjundion \vith Lhe boxploL helps. BoLh
arc nnportant tools for exploratory data analysis.
153
Mathematics for Com puter Scientists
a
II)
a
=
=
II)
Octopod Boxplot
o
o
o
o
11.2 Scatter Diagram
Chapter 11. Looking at Data
A common diagram is the scaLter diagram 'where \ve plot x values againsl y values. \Ve
illustrate thc idcas '\vith hvo cxanlples.
Breast cancer
In a 19G5 repOrL Lea discussed lhe relationship bel'ween mean annual temperat ure and
the mortality rate for a type of brea..,t cancer in '\vomen. The subjccts '\vere residcnt.s of
certain regions of Grcat and Swcdcn. A simple regression of mortalit.y
011 tE-nnpm'i1JllrE--l shmvs ii, strong rE--llar,iollsllip t hp. two varii1,bh-ls,
Data
Data contains the mean annual tempcraturc (in dcgrces F) and rvlort.ality Indcx for
llE-lopla.'nlls of r,bE-l fmnrl]p. Di1Jrl wp.rp. frolll rp.giolls of Gmrlt TIritail1,
Konvay, and S\' . .:eden. )Jumber 01' cases: IG Variable )James
1. I\/fortalir,y: illdE-lx for of fP.1I1i1JE-l brp.i1,st
154
Mathematics for Com puter Scientists Chapter 11. Looking at Data
ity
102 .. 5 51.3
104.5 49.9
100.4 50
95.9 49.2
87 '18.5
9.5 '17.8
88.0 47.3
45.1
46.:)
8'1.6 '12.1
81.7 '11.2
72.2 43.f)
65.1 42.:)
40.2
67.3 31.8
52.5 ;14
0
a
0
- 0
0
0
0 -
en 0
0
0
0
1:: 0
0
0
00
-
0
E
0
0
-
r-
0
0
0
0 -
(!)
0
I I I I
35 40 45 50
temp
155
Mathematics
for
Computer
Scientists
Gareth J. Janacek & Mark Lemmon Close