X ~ Binomial( , )
FOUNDATIONS OF
X ~ Normal( , )
X ~ Poisson( )
WITH
2
HELLO!
I am Elijah Appiah from
Ghana.
I am an Economist by
profession.
I love everything about R!
You can reach me:
secret behind the smile! [Link]@[Link]
3
Lecture Series
Introduction to Data and Statistics
Foundations of Probability
Inferential Statistics
Modeling and Regression Analysis
4
Lesson Goals
Introduce the basics of probability,
probability calculations for random
events, and probability distributions
in R.
Fundamentals relevant for providing
a conceptual framework for
statistical inference.
5
Probability
There is a random process.
We know the outcomes that could happen
but not the particular outcome that will
happen.
Examples of random processes:
Coin toss, Rolling a die, Stock Market, etc.
6
Probability Events
P(A) = Probability of Event A
Fundamental Rule of Probability
7
Schools of Thought
Frequentist View – proportion of
times an outcome occurs.
Bayesian View – subjective
degree of belief.
8
DISTRIBUTION
9
Probability of Random Event
Toss a coin.
10
Probability of Random Event
Assume you toss a coin 10 times, and
Head appears each time. What do you think
the chance is that another head will come
up on the next toss? 0.5? Less than 0.5?
More than 0.5?
HHHHHHHHHH?
11
Simulation with R
Simulate a coin toss
rbinom(n, size, prob)
Number of Probability of
Coin Outcomes
observations/draws occurrence
prob = 0.5 simulates a
size = 0 means one outcome (0 for tails) fair coin toss
size = 1 means two outcomes (0 for tails and 1 for heads) prob ≠ 0.5 simulates a
bias coin
size 2 means the number of ones (heads) that occur
12
Now, let’s practice
13
Binomial Distribution
Coin flips yield outcome that follow a
binomial distribution.
Number of Coins Probability
of Heads
14
Fair Coins
When you flip a fair coin 10 times, what is
the most likely number of heads?
The likelihood of outcomes would be 5
heads and 5 tails.
15
Density and Cumulative Density
Why 100,000 draws?
Simulate 100,000 draws from a binomial
distribution of X~Binomial(10, 0.5).
What is the probability of getting exactly 5
heads?
If you flip 10 coins each with a 50% chance of
getting heads, what is the probability exactly 5 of
them are heads?
16
Now, let’s practice
17
Density of Binomial Distribution
Mean of X~Binomial(10, 0.5)
with exactly 5 heads was
approximately 25%.
This is known as the density
of the binomial distribution at
exactly 5 heads (X = 5).
18
Probability Density of Binomial Distribution
dbinom(n, size, prob)
Number of Heads Number of Probability
Coin Flips
dbinom(5, 10, 0.5)
19
Now, let’s practice
20
Cumulative Density of Binomial Distribution
Simulate 100,000 draws from a binomial
distribution of X~Binomial(10, 0.5).
What is the probability of getting 4 heads
or less?
21
Now, let’s practice
22
Cumulative Density
Mean of X~Binomial(10, 0.5)
with 4 heads or less was
approximately 38%.
This is known as the
cumulative density of the
binomial distribution at 4 heads
or less.
23
Cumulative Density of Binomial Distribution
pbinom(q, size, prob, [Link] = TRUE)
Number Number of
of Heads Probability If TRUE, ,
Coin Flips otherwise
pbinom(4, 10, 0.5)
24
Now, let’s practice
25
Properties of Binomial Distribution
Every distribution has a center and spread.
Measure of center for binomial distribution
is mean or expected value.
Measure of spread is variance.
26
Mean and Variance of Binomial Distribution
Simulate 100,000 draws from a
binomial distribution with
Find the mean and variance.
27
Now, let’s practice
28
Mean and Variance of Binomial Distribution
Expected value:
Variance:
29
Mean and Variance of Binomial Distribution
Mean:
Variance
30
Mean and Variance of Binomial Distribution
What is the expected value and variance of a
binomial distribution with 100 coin flips with a
30% probability of getting heads?
Mean:
Variance:
31
Probability of Random Events A and B
Let’s consider two events A and B.
Probability of Event A = Pr(A)
Probability of Event B = Pr(B)
Toss two coins. What is the probability of
obtaining two heads?
Head Head Tail Tail Total
Head Tail Head Tail Probability
0.25 0.25 0.25 0.25 =1
32
Probability of Random Events A and B
Pr(two Heads) = Pr(Heads) Pr(Heads)
=
=
Let’s try to see if simulating a binomial
distribution verifies this multiplicative rule
of probability.
33
Probability of Random Events A and B
Simulate 100,000 draws of a fair coin flip
for an event A.
Simulate 100,000 draws of a fair coin flip
for an event B.
Is Pr(A and B) = Pr(A) Pr(B)?
34
Probability of Random Events A and B
Simulate 100,000 draws of a bias coin flip
for an event A with probability of 0.2
coming up heads.
Simulate 100,000 draws of a bias coin flip
for an event B with probability of 0.7
coming up heads.
Is Pr(A and B) = Pr(A) Pr(B)?
35
Probability of Random Events A and B
If events A and B are independent, and A
has a 40% chance of happening, and event
B has a 20% chance of happening, what is
the probability they will both happen?
Is Pr(A and B) = Pr(A) Pr(B)?
36
Now, let’s practice
37
Probability of Random Events A or B
Pr(A or B) = Pr(A) + Pr(B) – Pr(A and B)
38
Probability of Random Events A or B
Pr(A or B) = Pr(A) + Pr(B) – Pr(A and B)
Pr(A or B) = Pr(A) + Pr(B) – Pr(A) Pr(B)
Pr(A or B) = 0.5 + 0.5 – 0.5 0.5 = 0.75
39
Probability of Random Events A or B
Simulate two events and find
the probability that either
events happen.
If coins A and B are independent, and A has a 60%
chance of coming up heads, and event B has a 10%
chance of coming up heads, what is the probability
either A or B will come up heads?
40
Now, let’s practice
41
Probability of Random Events A or B or C
Pr(A or B or C) =
Pr(A) + Pr(B) + Pr(C) –
Pr(A and B) – Pr(A and C) – Pr(B and C) +
Pr(A and B and C)
42
Now, let’s practice
43
Multiplying Random Variables
Flip a fair coin ten times and count the
number of heads.
Take that number and triple it. What
happens? Mean? Variance?
Simulate 100,000 draws from a binomial
distribution
44
Now, let’s practice
45
Multiplying Random Variables
When you multiply a random variable by a
number, you multiply the expected value by
that number.
The variance gets bigger by a factor of the
number squared.
46
Adding Two Random Variables
Suppose:
What happens?
47
Now, let’s practice
48
Adding Two Random Variables
Did you observe what happened when two
variables are added?
49
DISTRIBUTION
50
Normal Distribution
Recall:
What happens when…
Visualize both distributions and observe!
51
Now, let’s practice
52
Normal Distribution
The normal distribution:
Mean Standard
Deviation
53
Normal Distribution
rnorm(n, mean, sd)
54
Normal Approximation to Binomial
Simulation:
Let’s approximate this to normal
distribution and compare histograms.
Recall:
55
Now, let’s practice
56
DISTRIBUTION
57
Poisson Distribution
Flip many coins, each with a low
probability.
Simulate a binomial distribution with:
58
Now, let’s practice
59
Poisson Distribution
Mean
Note that the mean of the binomial
distribution with size 1000 and probability
1/1000 is 1.
60
Poisson Distribution
rpois(n, lambda)
Number
Mean
of Draws
61
Now, let’s practice
62
Poisson Distribution
Interesting properties of Poisson
Distribution:
63
DISTRIBUTION
64
Geometric Distribution
Assume you flip a coin with 10% probability
of getting heads.
How many times would you have to flip the
coin until you get head?
You could get heads on the first trial, or
you could get it on the 1000th trial.
65
Geometric Distribution
A situation where you wait for a random
event to occur is known as Geometric
Distribution.
Let’s simulate waiting for heads in a 100
draws.
66
Now, let’s practice
67
Geometric Distribution
Probability
68
Geometric Distribution
rgeom(n, p)
Number
Probability
of Draws
69
Now, let’s practice
70
Any questions?
Reach me anytime!
Email
[Link]@[Link]
LinkedIn
[Link]