You are on page 1of 41

LECTURE 22

LECTURE 22 Statistics – Probability – Continuous Random Variable – Distributions – More on Histograms –

Statistics

Probability Continuous Random Variable Distributions More on Histograms More on Random Numbers Matlab Functions

Probability relates to events, which are phenomena that may be observed either to happen or not
Probability relates to events, which are phenomena that may be observed either to happen or not

Probability relates to events, which are phenomena that may be observed either to happen or not to happen.

Examples: flipping a coin, rolling dice, …

Probability of an event is a numerical measure of the likelihood of its occurrence

Probability relates to events, which are phenomena that may be observed either to happen or not
Experiment: A situation whose outcome depends on chance; example: throwing of a die Sample Space S
Experiment: A situation whose outcome depends on chance; example: throwing of a die Sample Space S

Experiment:

A situation whose outcome depends on chance;

example: throwing of a die

Experiment: A situation whose outcome depends on chance; example: throwing of a die Sample Space S

Sample Space S:

The set of all possible outcomes of an experiment;

Experiment: A situation whose outcome depends on chance; example: throwing of a die Sample Space S

example: S =

Event:

A subsets of the sample space S; example: observing an even number of dots

Experiment: A situation whose outcome depends on chance; example: throwing of a die Sample Space S
Experiment: throwing a pair of dice (one red and one blue) • The sample space has
Experiment: throwing a pair of dice (one red and one blue) • The sample space has

Experiment: throwing a pair of dice (one red and one blue) The sample space has 36 outcomes:

S =

Experiment: throwing a pair of dice (one red and one blue) • The sample space has

• The event L of obtaining the number 7 is

Experiment: throwing a pair of dice (one red and one blue) • The sample space has
L occurs if any of the outcomes in L occurs
L occurs if any of the outcomes in L occurs
Probability: • A number between 0 and 1, inclusive, that indicates how likely an event is
Probability: • A number between 0 and 1, inclusive, that indicates how likely an event is

Probability:

• A number between 0 and 1, inclusive, that indicates how likely an event is to occur

– An event with probability of 0 is a null event

(e.g., there will be two moons tonight)

– An event with probability of 1 is a sure event

(e.g., the sun will set tonight)

• Probability of event A is denoted as P(A) • The closer P(A) to 1, the more likely is A to occur

An experiment is repeated n times under essentially identical conditions and event A occurred m times
An experiment is repeated n times under essentially identical conditions and event A occurred m times

An experiment is repeated n times under essentially identical conditions and event A occurred m times

As n grows large

An experiment is repeated n times under essentially identical conditions and event A occurred m times
An experiment is repeated n times under essentially identical conditions and event A occurred m times

relative frequency of event A

probability of event A

Experiment: flipping a fair coin Two Outcomes (and Events): Heads Tails 7
Experiment: flipping a fair coin Two Outcomes (and Events): Heads Tails 7

Experiment: flipping a fair coin

Experiment: flipping a fair coin Two Outcomes (and Events): Heads Tails 7

Two Outcomes (and Events):

Experiment: flipping a fair coin Two Outcomes (and Events): Heads Tails 7

Heads

Tails

7

>> n = 10; >> outcomes = randi([1 2],1,n) outcomes = 2 1 2 1 2
>> n = 10; >> outcomes = randi([1 2],1,n) outcomes = 2 1 2 1 2
>> n = 10; >> outcomes = randi([1 2],1,n) outcomes = 2 1 2 1 2
>> n = 10;
>> outcomes = randi([1 2],1,n)
outcomes =
2
1
2
1
2
2
2
1
1
1
>> heads = outcomes(outcomes == 1)
heads =
1
1
1
1
1
>> m = length(heads)
m =
5
>> f = m/n
f =
0.5
Generates a uniformly distributed random number between n and m size of x >> x =
Generates a uniformly distributed random number between n and m size of x >> x =

Generates a uniformly distributed random number between n and m

size of x >> x = randi([1 3],3,5) x = 2 2 1 3 3 2
size of x
>> x = randi([1 3],3,5)
x =
2
2
1
3
3
2
2
1
3
1
3
3
2
1
3
>> n = 10; >> outcomes = randi([1 2],1,n) outcomes = 2 1 2 1 2
>> n = 10; >> outcomes = randi([1 2],1,n) outcomes = 2 1 2 1 2
>> n = 10; >> outcomes = randi([1 2],1,n) outcomes = 2 1 2 1 2
>> n = 10;
>> outcomes = randi([1 2],1,n)
outcomes =
2
1
2
1
2
2
2
1
1
1
>> outcomes(outcomes == 2) = 0
outcomes =
0
1
0
1
0
0
0
1
1
1
>> f = cumsum(outcomes)./(1:n)
f =
Columns 1 through 8
0 0.5 0.33333 0.5 0.4 0.33333 0.28571 0.375
Columns 9 through 10
0.44444
0.5
>> plot(f)
n = 100 n = 10 n = 1,000,000 n = 1,000
n = 100
n = 10
n = 1,000,000
n = 1,000
12

12

12 Union of events A and B set of outcomes that are in A or B

Union of events A and B

set of outcomes that are in A or B or both

12 Union of events A and B set of outcomes that are in A or B
S A B
S
A
B

Intersection of events A and B

set of outcomes in both A and B

12 Union of events A and B set of outcomes that are in A or B
S A B
S
A
B

Complement of an event A

A
A

S

If A and B are mutually exclusive events A S B If A and B are
If A and B are mutually exclusive events A S B If A and B are

If A and B are mutually exclusive events

If A and B are mutually exclusive events A S B If A and B are

A

S B
S
B

If A and B are independent events

If A and B are mutually exclusive events A S B If A and B are
Two Outcomes (and Events): Heads Fair coin: P (Heads) = P (Tails) = P Tails =
Two Outcomes (and Events): Heads Fair coin: P (Heads) = P (Tails) = P Tails =

Two Outcomes (and Events):

Heads
Heads

Fair coin:

P(Heads) = P(Tails) = P

Tails = sure event

Two Outcomes (and Events): Heads Fair coin: P (Heads) = P (Tails) = P Tails =
Random Variable is a variable • which will have value as a result of a test
Random Variable is a variable • which will have value as a result of a test

Random Variable is a variable

which will have value as a result of a test but the value is unknown whose value is subject to variations due to chance (hence, randomness) it can take on a set of possible different values, each with an associated probability

Discrete Random Variable

can have only values from a countable set

Continuous Random Variable

may assume any numerical value in an interval

The sample space has 36 outcomes: S = X is a discrete random variable associated with
The sample space has 36 outcomes: S = X is a discrete random variable associated with

The sample space has 36 outcomes:

S =

The sample space has 36 outcomes: S = X is a discrete random variable associated with

X is a discrete random variable associated with events, e.g., observing sums of the dice dots:

X = {x i } = {x 1 , x 2 , …, x 11 } = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}

X is a discrete random variable associated with events e.g., sums of the dice dots: X
X is a discrete random variable associated with events e.g., sums of the dice dots: X

X is a discrete random variable associated with events e.g., sums of the dice dots:

X = {x i } = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}

Each event has a probability of its occurrence, for example,

P(X = x 1 ) = p 1 P(X = x 2 ) = p 2 .

.

.

the probability that, after throwing a dice, X will be equal to x i
the probability that,
after throwing a dice,
X will be equal to x i

i.e., P(x) = {p i } = {p 1 , p 2 , …, p 11 }

discrete distribution function

18

18

18 The sample space has 36 outcomes: S = Fair dice: outcomes are equiprobable—i.e., all outcomes

The sample space has 36 outcomes:

S =

18 The sample space has 36 outcomes: S = Fair dice: outcomes are equiprobable—i.e., all outcomes

Fair dice: outcomes are equiprobable—i.e., all outcomes have th e same probability, p Mutually exclusive outcomes: their union is a sure event

18 The sample space has 36 outcomes: S = Fair dice: outcomes are equiprobable—i.e., all outcomes
18 The sample space has 36 outcomes: S = Fair dice: outcomes are equiprobable—i.e., all outcomes

p = 1/36

probability of each outcome

Experiment: throwing a pair of dice (one red and one blue) S = The probability of
Experiment: throwing a pair of dice (one red and one blue) S = The probability of

Experiment: throwing a pair of dice (one red and one blue)

S =

Experiment: throwing a pair of dice (one red and one blue) S = The probability of

The probability of throwing, say, a red 1 and a blue 5 is

P(1 5 ) = P(1) P(5) = 1/6 1/6 = 1/36

The probability of 1 out of 36 possible outcomes

S = probability of each outcome 1/36 X = m when the throw of dice results

S =

S = probability of each outcome 1/36 X = m when the throw of dice results

probability of each outcome

1/36

X = m when the throw of dice results in the number m

we now estimate:

P(m) = P(X = m)

S = probability of each outcome 1/36 X = m when the throw of dice results
S = probability of each outcome 1/36 X = m when the throw of dice results
S = probability of each outcome 1/36 X = m when the throw of dice results
S = probability of each outcome 1/36 X = m when the throw of dice results
S = probability of each outcome 1/36 X = m when the throw of dice results
S = probability of each outcome 1/36 X = m when the throw of dice results
S = probability of each outcome 1/36 X = m when the throw of dice results
S = probability of each outcome 1/36 X = m when the throw of dice results
S = probability of each outcome 1/36 X = m when the throw of dice results
S = probability of each outcome 1/36 X = m when the throw of dice results
• random variable X takes values • probability distribution function takes the corresponding values:
• random variable X takes values • probability distribution function takes the corresponding values:

random variable X takes values

• random variable X takes values • probability distribution function takes the corresponding values:

probability distribution function takes the corresponding values:

• random variable X takes values • probability distribution function takes the corresponding values:
• random variable X takes values • probability distribution function takes the corresponding values:
the probability distribution function satisfies:
the probability distribution function satisfies:

the probability distribution function satisfies:

the probability distribution function satisfies:
>> x =[2 3 4 5 6 7 8 9 10 11 12]; >> p =[1
>> x =[2 3 4 5 6 7 8 9 10 11 12]; >> p =[1
>> x =[2 3 4 5 6 7 8 9 10 11 12];
>> p =[1 2 3 4 5 6 5
4 3 2 1] / 36;
>> bar(x,p)
>> xlabel('x_i')
>> ylabel('p(x_i)')
>> x =[2 3 4 5 6 7 8 9 10 11 12]; >> p =[1
• The cumulative distribution function (CDF) for a discrete random variable X is defined as
• The cumulative distribution function (CDF) for a discrete random variable X is defined as

• The cumulative distribution function (CDF) for a discrete random variable X is defined as

• The cumulative distribution function (CDF) for a discrete random variable X is defined as
• The cumulative distribution function (CDF) for a discrete random variable X is defined as
• The cumulative distribution function (CDF) for a discrete random variable X is defined as
• The cumulative distribution function (CDF) for a discrete random variable X is defined as
>> x =[2 3 4 5 6 7 8 9 10 11 12]; >> p =[1
>> x =[2 3 4 5 6 7 8 9 10 11 12]; >> p =[1
>> x =[2 3 4 5 6 7 8 9 10 11 12];
>> p =[1 2 3 4 5 6 5
4 3 2 1] / 36;
>> bar(x,cumsum(p))
>> xlabel('x_i')
>> ylabel('F(x_i)')
>> x =[2 3 4 5 6 7 8 9 10 11 12]; >> p =[1
Discrete Random Variable • can have only values from a countable set • discrete distribution function
Discrete Random Variable • can have only values from a countable set • discrete distribution function

Discrete Random Variable

can have only values from a countable set discrete distribution function

Discrete Random Variable • can have only values from a countable set • discrete distribution function

Continuous Random Variable

probability density function
probability
density function

may assume any numerical value in an interval continuous distribution function

cumulative distribution function probability density function 27
cumulative distribution function probability density function 27
cumulative distribution function probability density function 27
cumulative distribution function probability density function
cumulative distribution function
probability density function

27

=area a b
=area a b
=area a b
=area a b
=area
a
b
discrete continuous Normalized distr. funct. probability of 1 1 “sure event” Mean = Expectation of X
 

discrete

 

continuous

Normalized distr. funct.

probability of

1

1

1

“sure event”

 

 

Mean = Expectation of X E[X] =

Expectation of X 2

 

E[X 2 ] =

2

2 2

 

 

Expectation of g(X) E[g(X)] =

Variance 2 =

Variance =

2

2

Standard Deviation

Standard Deviation
Standard Deviation
Standard Deviation
A histogram is a plot of frequency of occurrence of data values versus the values themselves.
A histogram is a plot of frequency of occurrence of data values versus the values themselves.

A histogram is a plot of frequency of occurrence of data values versus the values themselves.

>> histogram(X) Aggregates vector data X into 10 evenly spaced bins between min(X) and max(X) Returns
>> histogram(X)
Aggregates vector data X into 10 evenly spaced bins between
min(X) and max(X)
Returns handle
>> h = histogram(X,n)
handle
into n bins
 Probability Density Function (pdf) –distribution of random variable X
 Probability Density Function (pdf) –distribution of random variable X
 Probability Density Function (pdf) –distribution of random variable X
 Probability Density Function (pdf) –distribution of random variable X

Probability Density Function (pdf) –distribution of random variable X

 Probability Density Function (pdf) –distribution of random variable X

MATLAB STATISTICAL FUNCTIONS

MATLAB STATISTICAL FUNCTIONS var average value variance std median corrcoef standard deviation 50th percentile correlation coefficient

mean

var

average value

MATLAB STATISTICAL FUNCTIONS var average value variance std median corrcoef standard deviation 50th percentile correlation coefficient

variance

MATLAB STATISTICAL FUNCTIONS var average value variance std median corrcoef standard deviation 50th percentile correlation coefficient

std

median

corrcoef

standard deviation

MATLAB STATISTICAL FUNCTIONS var average value variance std median corrcoef standard deviation 50th percentile correlation coefficient

50th percentile correlation coefficient

Matlab statistics toolbox: normpdf, normcdf, …  mean  standard deviation
Matlab statistics toolbox: normpdf, normcdf, …  mean  standard deviation
Matlab statistics toolbox: normpdf, normcdf, …  mean  standard deviation
Matlab statistics toolbox: normpdf, normcdf, …
Matlab statistics toolbox:
normpdf, normcdf, …

mean standard deviation

Matlab statistics toolbox: normpdf, normcdf, …  mean  standard deviation
 mean  standard deviation
 mean  standard deviation
 mean  standard deviation
 mean  standard deviation

mean standard deviation

Generates Normal (Gaussian) random numbers with  = 0 and  = 1 >> x =
Generates Normal (Gaussian) random numbers with  = 0 and  = 1 >> x =

Generates Normal (Gaussian) random numbers with = 0 and = 1

>> x = randn(1,1e6); >> h = histogram(x,100) h = Histogram with properties: Data: [1×1000000 double]
>> x = randn(1,1e6);
>> h = histogram(x,100)
h =
Histogram with properties:
Data: [1×1000000 double]
Values: [1×100 double]
NumBins: 100
BinEdges: [1×101 double]
BinWidth: 0.1
BinLimits: [-5.31 4.69]
Normalization: 'count'
FaceColor: 'auto'
EdgeColor: [0 0 0]
Show all properties
>>
Generates Normal (Gaussian) random numbers with  = 0 and  = 1 >> x =
Probability interpretation:             
Probability interpretation:             

Probability interpretation:

Probability interpretation:             
Probability interpretation:             
Probability interpretation:             





  
  
  

  

  

    
    
    

    

  

    
    
    

    

Probability interpretation:             
Probability interpretation:             
Probability interpretation:             
Probability interpretation:             
The error function erf(x) is twice the integral from 0 to x of the Gaussian distribution
The error function erf(x) is twice the integral from 0 to x of the Gaussian distribution

The error function erf(x) is twice the integral from 0 to x of the Gaussian distribution with 0 mean and 1/2 variance

The error function erf(x) is twice the integral from 0 to x of the Gaussian distribution
The error function erf(x) is twice the integral from 0 to x of the Gaussian distribution
The complementary error function erfc(x) is
The complementary error function erfc(x) is

The complementary error function erfc(x) is

The complementary error function erfc(x) is
The complementary error function erfc(x) is
Generates Uniformly distributed random numbers between 0 and 1. >> x = rand(1,1e6); >> histogram(x)
Generates Uniformly distributed random numbers between 0 and 1. >> x = rand(1,1e6); >> histogram(x)

Generates Uniformly distributed random numbers between 0 and 1.

>> x = rand(1,1e6); >> histogram(x)
>> x = rand(1,1e6);
>> histogram(x)
Generates Uniformly distributed random numbers between 0 and 1. >> x = rand(1,1e6); >> histogram(x)

MATLAB FUNCTIONS

MATLAB FUNCTIONS rand, randi, randn randperm histogram bar, barh, bar3, bar3h pie, pie3 stairs, stem, stem3

rand, randi, randn randperm histogram

bar, barh, bar3, bar3h pie, pie3 stairs, stem, stem3

pcolor

try >>pcolor(rand(10))

• Probability is a number between 0 and 1, inclusive, that indicates how likely a chance
• Probability is a number between 0 and 1, inclusive, that indicates how likely a chance

• Probability is a number between 0 and 1, inclusive, that indicates how likely a chance event is to occur.

• Basic probability concepts

– Sample space, outcome, event

• Random variables

– Discrete and continuous

• Distribution functions

– Discrete, cumulative

• Properties of distribution functions

– mean, variance, standard deviation

• Converting histograms into PDF • Normal and Uniform distributions • Matlab functions rand, randn, randi, cumsum,…