Probability and Statistics
IC252
Random variables
Random variables
Often we take measurements which have different
values on different occasions. Furthermore, the values
are subject to random or stochastic variation - they are
not completely predictable, and so are not deterministic.
They are random variables.
Examples are crop yield, maximum temperature,
number of cyclones in a season, rain/no rain.
Random variables
In an experiment a number is often attached to each outcome.
S
s X(s) R
Definition:
A random variable X is a function defined on S, which takes
values on the real axis
X: S → R
Sample space Real numbers
Continuous and discrete random
variables
A continuous random variable is one which can (in theory)
take any value in some range, for example crop yield,
maximum temperature.
A discrete variable has a countable set of values. They
may be
⚫ counts, such as numbers of cyclones
⚫ categories, such as much above average, above
average, near average, below average, much below
average
⚫ binary variables, such as rain/no rain
Random variables
Example:
Random variable Type
Number of dots when rolling a dice discrete
The sum of dots when rolling two dice discrete
counting
Number of children in a family discrete
Time of running 5 km continuous
continuous
Amount of sugar in a coke measure
Height of males continuous
Discrete: can take a finite number of values or an
infinite but countable number of values.
Continuous:takes values from the set of real numbers.
Example:
Discrete Random Variable
Treat 4 patients with a drug
that is 75% effective
Let X ≡ the [variable] number
of patients that respond to
treatment
X is a discrete random
variable can be either 0, 1, 2,
3, or 4 (a countable set of
possible outcomes)
Example:
Continuous Random Variable
Continuous random
variables have an
infinite set of possible
outcomes
Example: generate
random numbers with
this spinner
Outcomes form a
continuum between 0
and 1
Random Variable
•A random variable x takes on a defined set of values with different
probabilities.
•For example, if you roll a die, the outcome is random (not fixed) and there are 6 possible
outcomes, each of which occur with probability one-sixth.
•For example, if you poll people about their voting preferences, the percentage of the sample that
responds “Yes on Proposition 100” is a also a random variable (the percentage will be slightly
differently every time you poll).
•Roughly, probability is how frequently we expect different outcomes to
occur if we repeat the experiment over and over (“frequentist” view)
Probability functions
A probability function maps the possible values
of x against their respective probabilities of
occurrence, p(x)
p(x) is a number from 0 to 1.0.
The area under a probability function is always 1.
Discrete example: roll of a die
p(x)
1/6
x
1 2 3 4 5 6
P(x) = 1
all x
Probability mass function (pmf)
x p(x)
1 p(x=1)=1/6
2 p(x=2)=1/6
3 p(x=3)=1/6
4 p(x=4)=1/6
5 p(x=5)=1/6
6 p(x=6)=1/6
1.0
Cumulative distribution function (CDF)
1.0 P(x)
5/6
2/3
1/2
1/3
1/6
1 2 3 4 5 6 x
Cumulative distribution function
x P(x≤A)
1 P(x≤1)=1/6
2 P(x≤2)=2/6
3 P(x≤3)=3/6
4 P(x≤4)=4/6
5 P(x≤5)=5/6
6 P(x≤6)=6/6
Examples
1. What’s the probability that you roll a 3 or less?
P(x≤3)=1/2
2. What’s the probability that you roll a 5 or higher?
P(x≥5) = 1 – P(x≤4) = 1-2/3 = 1/3
Practice Problem
Which of the following are probability functions?
a. f(x)=.25 for x=9,10,11,12
b. f(x)= (3-x)/2 for x=1,2,3,4
c. f(x)= (x2+x+1)/25 for x=0,1,2,3
Answer (a)
a. f(x)=.25 for x=9,10,11,12
x f(x) Yes, probability
function!
9 .25
10 .25
11 .25
12 .25
1.0
Practice Problem:
The number of ships to arrive at a harbor on any given day is a
random variable represented by x. The probability distribution for x is:
x 10 11 12 13 14
P(x) .4 .2 .2 .1 .1
Find the probability that on a given day:
a. exactly 14 ships arrive p(x=14)= .1
b. At least 12 ships arrive p(x12)= (.2 + .1 +.1) = .4
c. At most 11 ships arrive p(x≤11)= (.4 +.2) = .6
Practice Problem:
You are lecturing to a group of 1000 students. You ask them
to each randomly pick an integer between 1 and 10.
Assuming, their picks are truly random:
• What’s your best guess for how many students picked the
number 9?
Since p(x=9) = 1/10, we’d expect about 1/10th of the
1000 students to pick 9. 100 students.
• What percentage of the students would you expect picked a
number less than or equal to 6?
Since p(x≤ 6) = 1/10 + 1/10 + 1/10 + 1/10 + 1/10 + 1/10
=.6 60%
Probability distribution function
PDF
Discrete Continuous
X P(X) PDF
Height
2 1 1/100
1 …
2 1/100
… … UK
100 POPULATION
100 1/100
P(X)
PMF
𝑃𝑀𝐹 𝑋 = 1 X P(X)
𝑋
1.8 m 0
1/100
P given by the area
X
1 2 … 100 1.75 ≤ 𝑋 ≤ 1.85
Summarize
Two views of random variables
Think of a R.V. as
• a function from S to the reals
• or It’s a variable with a probability
distribution on its values
Discrete random variable
Probability function
Definition:
Let X : S → R be a discrete random variable.
The function f(x) is a probabilty function for X, if
1. f(x) 0 for all x
2. f(x) = 1
x
3. P(X = x) = f(x),
where P(X=x) is the probability for the outcomes sS : X(s) = x.
Discrete random variable
Probability function
Example: Flip three coins X : # heads X : S → {0,1,2,3}
Outcome Random variable X Probability function
TTT X=0 f(0) = P(X=0) = 1/8
HTT, TTH, THT X=1 f(1) = P(X=1) = 3/8
HHT, HTH, THH X=2 f(2) = P(X=2) = 3/8
HHH X=3 f(3) = P(X=3) = 1/8
Notice! The definition of a
probability function is fulfilled:
1. f(x) 0
2. f(x) = 1
3. P(X=x) = f(x)
2
2
Discrete random variable
Cumulative distribution function
Definition:
Let X : S → R be a discrete random variable with
probability function f(x).
The cumulative distribution function FX (x) is defined by
FX (x) = P(X x) for - < X ≤ x
associated with the r.v (X x)
The role of the subscript X is only to identify the actual r.v.
Continuous random variable
A continuous random variable X has probability 0 for all
outcomes!!
Mathematically: P(X = x) = f(x) = 0 for all x
Hence, we cannot represent the probability function f(x) by a
table or bar chart as in the case of discrete random variables.
Instead we use a continuous function – a density function.
26