Chapter 1
Chapter 1
Methods
Stuart Barber ([Link]@[Link])
Sunday October 01, 2023
Module information
The content is split into the following chapters, each to be covered in a period of around
one to two weeks.1
1. Introduction
3. Statistical Models
4. Estimation
5. Frequentist Inference
6. Bayesian Inference
You will be assessed via an exam (80% of your module mark) and a coursework
assignment (20%). The weekly exercises do not count towards your final mark.
The exam timetable will eventually be published at
[Link] I do not know precisely when, and I
cannot alter the exam timetable. Given that the exam timetable sometimes changes
unexpectedly, you are expected to be in Leeds for the entire exam period.
After the deadline of each weekly homework, you will be given detailed solutions. You will
also receive feedback on your coursework before the exam.
I will suggest some relevant reading at the beginning of each chapter, but that reading is
not compulsory. Some relevant books are:
These are available online through the library. The first two are similar, but the one by
DeGroot and Schervish is generally stronger and has more content, and that’s the one I
will refer you to most often (although having access to both will give you a larger
collection of exercises and examples). The third book might be of particular interest to
those of you with a biology background, and it also has the benefit of using the R
programming language.
Remember that all of these books contain some topics that are not covered in this
module. So please don’t imagine that you need to read them thoroughly, and try not to
get too distracted by topics that are not required here (e.g. ANOVA and linear models are
interesting, but you don’t need them right now).
Of course, there are many other helpful books not mentioned here. You are very strongly
encouraged to find books that meet your own specific needs, for example by simply
visiting the library. Finding materials to support your own learning is an important skill, so
don’t be lazy and don’t expect your lecturers to provide you with everything.
Even books on A-Level statistics could be helpful sources of examples and exercises,
particularly for probability and hypothesis testing (A-Levels are the exams taken by most
students in England before going to university). You might find cheap second-hand
copies in charity shops. Even very old A-Level textbooks are likely to be relevant. But
please remember that we will cover many topics in this module that go beyond A-Level.
Is programming required?
Yes, it definitely is. You cannot avoid programming in this module. R will be used in the
practical classes and for the coursework. Questions related to R could appear on the
exam (e.g. interpretation of code or output). You should install R ([Link]
[Link]/) on your computer before attempting any part of the module. I also
recommend installing the integrated development environment RStudio
([Link] which makes writing R scripts, saving them and sharing them a lot
easier.
You should fully engage with the teaching materials (attempt all exercises, run all
code provided, and ask me about anything that is not clear).
You should work on the coursework continuously throughout the module (it will
be treated as part of your learning, not just as an assessment).
I will set the exam under the assumption that you have done all of the above.
The notes are in HTML files to make them more accessible for students who are visually
impaired. You can convert the HTML files to PDF yourself in a few easy steps:
I will not hand out printed copies because the notes are likely to get small updates or
corrections throughout the semester. If you print the HTML notes on paper, you should
first wait a few seconds for the equations to reach their full size, otherwise your printout
might look weird.
Mathematical prerequisites
Some knowledge of maths is assumed in the module. If you feel that you are struggling
with this then please let me know. If you don’t tell me, there’s nothing I can do to help. If
you do tell me, then I’m happy to spend some extra time with you to explain anything you
don’t understand.
For revision of basic maths (around the standard of first-year A-level modules, including
calculus), you shouldn’t have much difficulty finding books at an appropriate level in the
library or in any bookshop. For example, the library provides free access to:
Probability and Statistics: A Course for Physicists and Engineers, by Mathai and
Haubold (Chapter 1 is most relevant).
Notation
In maths and statistics modules, the following symbols are quite common:
⇔ means “if and only if” or “is equivalent to”. For example, “
x = y/3 ⇔ y = 3x” means “the expression x = y/3 is equivalent to the
expression y = 3x ”.
∼ (tilde) usually means “has the distribution”. This will become clearer when
we discuss statistical models later in the module.
It is important to remember that we can only say two statements are equivalent (
A ⇔ B) if each statement implies the other (both A ⇒ B and B ⇒ A). For example,
we cannot say x < 3 ⇔ x < 4 because it is not true that x < 4 ⇒ x < 3 .
None of these three symbols above mean “equal to”. For example, ⇔ denotes logical
equivalence between two statements (statements that can be either true or false), it is
not used to denote equality between two numbers. So writing A ⇔ B (which makes
sense if A and B are logical statements) is not the same as writing A = B (which
makes sense if A and B take numerical values). Also, ∼ does not mean “approximately
equal to” (which would be denoted ≈).
Sequences
You won’t need a deep understanding of concepts such as convergence of sequences,
but you should at least make sure that you are comfortable with the notation for finite or
infinite sequences of numbers:
x1 , x2 , x3 , …
n n
∑ xi = x1 + x2 + … + xn and ∏ xi = x1 × x2 × … × xn
i=1 i=1
denote the sum and product (respectively) of the first n terms of our sequence. We will
sometimes write
xi → L as i → ∞,
which means that our sequence “tends to” (or “converges to” or “approaches”) the
number L when we make i extremely large. We say that L is the limit of the sequence.
Sets
We sometimes work with sets of numbers. This includes the set of all real numbers
(denoted R), the set of all integers (denoted Z , which includes all positive and negative
“whole numbers”, and also zero), and the set of all natural numbers (denoted N, which
includes only positive integers). For example, the notation
x ∈ R
Z ⊂ R
should be read as “the integers are a subset of the real numbers” (i.e. every x in the
integers must also be in the reals). Taking this notation further, we can define specific
subsets of R, Z and N. For example, we can write the set of even integers as
{x ∈ Z : x is even},
which we read as “all x in the integers such that x is even” (we read the colon as “such
that”). We might write the set of all real numbers between 2 and 4 as
which we read as “all real x such that x is more than 2 and less than 4”. This set is
actually an interval of the real line, i.e. a set that contains all real numbers between two
endpoints (with the endpoints here being 2 and 4). It is an open interval because it does
not contain the endpoints 2 and 4. We usually write open intervals as
[a, b] = {x ∈ R : a ≤ x ≤ b}.
We can even define half-open intervals that contain only one of the endpoints,
We can define new sets as combinations of two other sets (denoted here by A and B):
(1, 4) ∪ (3, 100) = (1, 100) and (1, 4] ∩ (3, 100] = (3, 4].
The notation for intersections, unions and differences doesn’t just apply to sets of
numbers. We can consider sets of objects, sets of people, sets of outcomes of an
experiment, and so on.
Functions
To denote a function or map from a set A to a set B, we will write
f : A → B,
2
f : x ↦ x .
(where e = 2.718282 … ) has inverse log(x), called the natural logarithm, such that
log(exp(x)) = x = exp(log(x)).
Unless stated otherwise, any logarithm in this module is assumed to be a natural (base
e) logarithm (often written as ln(x) in books and in other modules). You are expected to
be familiar with the basic rules for logarithms and exponents. For example,
log(ab) = log a + log b log a , b
,
= b log a exp(a + b) = exp(a) exp(b) and
exp(ab) = exp(a)
b
.
Calculus
You need to be able to differentiate and integrate simple functions (e.g. polynomials,
logarithms and the exponential function). You need to be able to differentiate using both
the product rule,
d df dg
(f (x) × g(x)) = (x) × g(x) + f (x) × (x),
dx dx dx
d dg df
f (g(x)) = (x) × (g(x)).
dx dx dx
df
∫ f (x) × g(x) dx = f (x) × ∫ g(x) dx − ∫ ( (x) × ∫ g(x) dx) dx.
dx
I will use integration by parts in lectures, but I will not expect you to use it yourself. You
will not be expected to evaluate difficult integrals, for example integrals that require the
use of partial fractions. You definitely don’t need to know how to integrate or differentiate
trigonometric functions.
df
′
(x) = f (x),
dx
are the product rule and chain rule, respectively (here f ∘ g just denotes the composition
of f and g).
1 Introduction
Relevant reading: DeGroot and Schervish, Chapters 1 and 2.
“I would claim that the unique strength of the statistics discipline is the extent of
its relevance to the whole of the natural and social sciences.” - Peter Diggle,
Statistics: a data science for the 21st century
As the quote from Professor Diggle suggests, statistics is very widely applicable to
science, including physics, biology and chemistry. The uses of statistics are particularly
well established in medicine, where randomised clinical trials allow us to assess the
effectiveness of medical treatments and where probabilistic sensitivity analyses allow us
to compare the cost-effectiveness of different treatments. As an exercise, please think
about your favourite field of scientific research and investigate the applications of
statistics or probability in that field.
But how is statistics related to data science? Do they overlap? Are they just the same
subject under different names? Are they in competition with each other? Is one just a
subset of the other? These questions have been discussed by statisticians who are
much more experienced than I am:
“There’s so much that goes on with “If data science is a close relation of
data that is about computing, not statistics, its increasing popularity must
statistics. I do think it would be fair to surely present us [statisticians] with an
consider statistics as a subset of data opportunity. We should embrace data
science. The tech industry has always science, proudly assert what we can
had to deal with databases and coding; offer it and humbly acknowledge what
that stuff is a necessity. The statistical we can learn from it. What can we
part of data science is more of an offer? Crucially, we can assert that
option.” - Andrew Gelman, Columbia uncertainty is ubiquitous and that
University probability is the correct way to deal
with uncertainty. We understand the
“Statistics can do all sorts of things. I uncertainty in our data by building
love statistics! But it’s not the most stochastic models, and in our
important part of data science, or even conclusions by probabilistic inference.” -
close.” - Andrew Gelman, Columbia Peter Diggle, Statistics: a data science
University for the 21st century
If your main interest is data science, Professor Gelman’s comments might lead you to
believe that statistics can be safely avoided. This might even be true. But it does not
mean that statistics cannot be very useful in data science, as it is in other sciences. As
Professor Diggle suggests, there is potential for statisticians (and other scientists with a
strong knowledge of statistics) to make meaningful contributions to data science.
In particular, Diggle’s comment highlights the fact that statistical methods offer the
correct way to handle uncertainty. This is important because, when we make conclusions
based on observational or experimental data, there will always be uncertainty in the data
and therefore uncertainty in our conclusions. Statistical models allow us to describe
mathematically the uncertainty in our data, and then statistical inference allows us to
quantify the uncertainty in our conclusions. Any good scientist (or data scientist) should
always try to measure the uncertainty in their own conclusions, and statistics gives them
the tools required to do this.
1.2 Probability
Before we can do anything with statistics, we need to understand some probability. Most
of the ideas here will be intuitively obvious, but we should make the notation and
definitions as clear as possible. We will achieve this through an example. Throughout
this module, motivating examples will be used to introduce any theory.
2. If we see that they have the disease, then what is the probability they are from
Scotland?
With some common sense, it would be possible to answer both questions without turning
them into questions about probabilities. However, we introduce probability here for two
reasons: to demonstrate that many of the ideas used in probability align well with what
we think of as common sense, and because probability gives us the tools to eventually
answer more complex questions for which common sense might not be enough.
1
P(ω) =
N
is the probability of each possible outcome ω (for us, ω would be a person in the UK
population). But we need to go further than this. We need define probabilities more
generally, so that we can apply them in situations where outcomes might not be equally
likely or where there are infinitely many possible outcomes.
Definition 1.1 A sample space (usually denoted Ω) is the set of all possible
outcomes of an experiment. An event is a set of possible outcomes (a subset of Ω).
Definition 1.2 Let A and B be events. We can define further events via set
operations:
E ∩ S means “from England and from Scotland” (which is just an empty set).
S
c
means “from the UK and not from Scotland”.
Ω ∩ S
c
means “from the UK and not from Scotland”.
Ω = E ∪ S ∪ W ∪ I.
⋃ Bi = Ω
i=1
In other words, events are mutually exclusive if they don’t overlap (cannot happen
together). They are a partition if they don’t overlap and, when combined, they include
every possible outcome.
B ↦ P(B)
that maps every event B to a number P(B) ∈ [0, 1] . Suppose that P has the
following two properties: P(Ω) = 1 and
P (B 1 ∪ B 2 ∪ B 3 ∪ …) = P(B 1 ) + P(B 2 ) + P(B 3 ) + ⋯
The truth is that we will rarely use this definition directly, so we don’t need to remember it
(we state it here for completeness and so that we understand it if we see it in textbooks).
Instead, we usually just think of P as a way to assign to any event a number between 0
and 1 that describes how likely that event is. The bigger the number, the more likely the
event (the more often it will occur if our experiment is repeated over and over again). The
two properties required in the definition just mean that these numbers are only really
considered to be probabilities if:
Ω has probability 100% (which make perfect sense because Ω it contains all
possible outcomes).
The probability of any union of non-overlapping events is just the sum of their
individual probabilities.
When phrased like this, the definition seems less intimidating and just fits nicely with our
intuitive understanding of how probabilities should work. When carrying out probability
calculations practice, rather than using the definition, we use some consequences of the
definition, such as the following theorem.
and
c
P(E ) = 1 − P(E) = 1 − 0.84 = 0.16.
Thus, there is a 92% probability of selecting someone from England or Scotland, and a
16% probability of selecting someone not from England. We can even combine the rules
P(A ∩ B)
P(A ∣ B) = .
P(B)
Of course, we assume in this definition that P (B) > 0 , otherwise the conditional
probability would not be defined. Throughout this module, whenever we work with
conditional probabilities, we will assume that the events we condition on have nonzero
probability.
All rules for probabilities also hold for conditional probabilities. Therefore we can handle
unions, intersections and complements for conditional probabilities just as we would for
ordinary probabilities. For example, the probability of someone not having the disease
given that they are from Scotland would be
c
P(D ∣ S ) = 1 − P(D ∣ S ) = 1 − 0.05 = 0.95.
Since P(S ) = 0.08, the definition allows us to calculate the proportion of the UK
population who are both in Scotland and have the disease
To answer question 1, we need P(D). But we only know the conditional probabilities:
i=1
This also applies when the partition consists of infinitely many events, B1 , B2 , …
(just replace k with ∞ in the sum). The partition theorem is sometimes called the
law of total probability.
In general, we usually apply the partition theorem when we want the probability of an
event but only have conditional probabilities for that event. Our previous equation is just
an example of this theorem, where we set B1 = E, B2 = S , B3 = W , B4 = I and
A = D to get
i=1
= 0.014.
in terms of P(D ∣ S ):
P(S ∩ D)
P(S ∣ D) =
P(D)
P(D ∣ S )P(S )
=
P(D)
0.05 × 0.08
= ≈ 0.3,
0.014
which tells us that around 30% of people with the disease are in Scotland. This
calculation is an example of Bayes’ theorem.
1.2.4 Independence
We should notice from our conditional probabilities in this example that someone’s
probability of having the disease does depend on where they come from. They are not
independent events. But what would it mean for two events to be independent?
Definition 1.8 Consider a finite collection of events. These events are mutually
independent if and only if
Please remember that being mutually independent is not equivalent to being mutually
exclusive.
If a variable can be thought of as random, we can use it to define events and can
consider their probabilities. For example, we can consider P(X ∈ C ) , the probability of
the event X ∈ C (that X will belong to some specific set C ).
We usually denote random variables in upper case (e.g. X ) and fixed numbers in lower
case (e.g. x ). In particular, X = x denotes the event that we observe X to take some
specific value x . We would say that the observed value x is a realisation of the random
variable X . We will use this convention throughout the module.3
In our hospital stay example, let’s think about how we might calculate the probability
of the event that a random patient’s hospital stay would be between 20 and 40 days
long.4
how can we ever hope to fully specify a distribution for X ? This seems like an impossible
task.
Instead of writing down every probability, we try to write down a statistical model from
which we can calculate any P(X ∈ [a, b]) whenever we need to.
Figure 1.3: The normal distribution curve. The area of the shaded
region over the interval [a, b] represents the probability of the event
X ∈ [a, b] . At each x ∈ R , the height of the curve is f (x) .
When we think of a statistical model, we often imagine a curve such as the normal
distribution’s familiar bell shape. For a normally distributed X , the shaded area under the
curve in the figure above would be
for any interval [a, b] . Along with the rules for probabilities seen in the previous section,
the ability to calculate this area allows us to calculate any probability P(X ∈ C ) that we
want. Thus, if X really is normally distributed, this fairly simple curve gives us the entire
probability distribution of X .
To calculate these areas, we would need to know the density function f (x) that defines
the curve. For a normal distribution, this is
2 2
exp[−(x − μ) /2σ ] b
Figure 1.4: The normal distribution curve for different values of μ and
σ
2
. It seems quite clear that μ determines the centre of the
distribution, while σ 2 determines the spread of the distribution.
How can we choose μ and σ ? First we should think about what they represent. It can be
shown that μ and σ are the average and the standard deviation (respectively) of X
across the population of interest.
So, for example, we might try to estimate μ via an experiment. Rather than just
considering the hospital stay X of just one patient, we would consider the hospital stays
X1 , X2 , … , Xn of n randomly chosen patients.
Definition 1.10 Condiser n independent random variables X1 , X2 , … , Xn that
all have the same probability distribution. We call these variables an independent
and identically distributed (IID) random sample from that distribution.5
X 1 = x1 , X 2 = x2 , …, X n = xn .
Finally, these observations could be used calculate the average hospital stay within this
sample,
x1 + x2 + … + xn
¯¯
¯
x = .
n
Our estimate, ¯¯
x , is therefore just a realisation (observed value) of the (random) statistic
¯
¯¯¯¯ X1 + X2 + … + Xn
X =
n
which varies randomly from sample to sample (if we performed the experiment over and
over again, taking n new patients each time, we would observe a different realisation of
¯¯¯¯
X each time).
The randomness of the statistic is why different studies, with the same design and same
population, can still produce very different conclusions. Because of this, there will always
be uncertainty in our estimates and we should ask the following questions:
¯¯¯¯
a. Is X likely to be close to the true value of μ ?
b. Are there better ways to estimate μ , and what is the best estimator of μ ?
These are very important questions because, as we saw in Figure 1.4, if we incorrectly
specify μ (or σ 2 ) in our model then that could affect our conclusions about the
distribution of X . But they are not easy questions. We will spend most of this module
gradually developing statistical tools to answer them.
By the end of this module, it is hoped that you will feel comfortable answering all three of
these questions.
2. Thinking of random variables as “numbers that vary randomly” will be enough for
us to understand the ideas presented in this module. But, if we wanted to be
more mathematically precise, would define a random variable to be a function
X : Ω → R defined on a sample space Ω . In our example, X assigns a real
number (days in hospital) to each patient in some population of patients (i.e. our
chosen sample space). ↩︎
3. The difference between a realisation x and a random variable X often confuses
students who are new to these concepts. It can help to think of X and x as
representing the same quantity before and after it is observed (respectively).
For example, let X be the height of the next person you will see today. You don’t
necessarily know who this will be (they will be a random person from some
population of people), so you don’t know a specific value for X . Because there is
some randomness in who this person will be, you can think about probabilities for
X by thinking of X as a random variable that varies from person to person.
However, once you meet this person, you observe their height x , which is some
fixed number, let’s say x = 5.5 feet. This observed value 5.5 is then something
that you know, so it is not random. Instead, it is what we call a realisation. It
would not make sense to think about probabilities for x , because it is just a fixed
number.
In summary, upper and lower case are used to distinguish between random and
non-random quantities. We can use X when we talk about what might happen,
and we use x when we talk about what actually did happen. For example, X is
used in planning experiments and x would then represent the actual result of
that experiment. ↩︎
4. Rather than using the notation X ∈ [20, 40], some textbooks might write this
event as as the set of all patients whose stay is 20 to 40 days:
module. More generally, for any set C of real numbers, we will use X ∈ C as
our notation for the event of X being in C , rather than the slightly more accurate
but much more cumbersome notation {ω ∈ Ω : X(ω) ∈ C }). ↩︎
5. Although we tend to use the word “sample” to refer to a set of random variables,
it is also common to see “sample” used much more loosely. For example,
sometimes people say that our sample is the subset of the population for which
we have information (in our example, that would be the set of n patients whose
hospital stays we can observe). Sometimes “sample” is used to refer to the data,
which are our collection of observations (in our example, this would be the
numerical values of the hospital stays of our n patients). This usually will not
cause much confusion. ↩︎