Examples to
Probability and Statistics
for Erasmus Students
Contents
1 Descriptive statistics
2
2 Probability definition
2
2.1
Axiomatic probability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
2.2
Classical probability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
2.3
Statistical probability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
3 Computation with probabilities
3
3.1
Example [conditioning and independency] . . . . . . . . . . . . . . . . . . . . .
3
3.2
Example [probability tree] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
3.3
Example [set diagram] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
3.4
Example [geometrical probability] . . . . . . . . . . . . . . . . . . . . . . . . . .
4
4 Random variable
4
4.1
Example [discrete random variable] . . . . . . . . . . . . . . . . . . . . . . . . .
4
4.2
Example [DF of continuous random variable] . . . . . . . . . . . . . . . . . . .
5
4.3
Example [characteristics of continuous RV]
6
. . . . . . . . . . . . . . . . . . . .
5 Random vector
6
5.1
Example [discrete random vector] . . . . . . . . . . . . . . . . . . . . . . . . . .
6
5.2
Example [marginal and conditional pdf] . . . . . . . . . . . . . . . . . . . . . .
7
5.3
Example [characteristics] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
1
Descriptive statistics
1. Determine expectation, variance, mode and median of the data sample given in the
following table
value
frequency
5
12
10
6
15
13
20
10
25
9
p = [0.24, 0.12, 0.26, 0.20, 0.18]
mx = sum(x. ∗ p) = 14.8
s2x = sum((x − mx)2 . ∗ p) = 49.96
x̂ = 5, x̃ = 15
2. Determine correlation coefficient of the following data
x=
y=
3
1
5
3
2
2
8
6
4
2
9
8
2
1
2
2
3
5
7
6
r = Sxy/sqrt(s2x ∗ s2y)
s2x =6.9444, Sxy =5.6667, s2y =6.0444
3. Find 0.18-quantile of the data set
4, 2, 6, 3, 5, 8, 7, 2, 3, 5, 9, 6, 6, 4, 9, 5, 5, 3, 2, 4
Order the data
22233344455556667899
Compute n = length(x) = 20
.
20*0.18 = 3.6 = 4 → quant. = 3
2
Probability definition
2.1
Axiomatic probability
1. Write a probability space for the random experiment:
There are three blue and two white balls in a box. We draw two balls and the result
are the colors of the drawn balls.
Ω = {A = [b, b] , B = [b, w] , C = [w, w]}
A = {∅, {A} , {B} , {C} , {A, B} , {A, C} , {B, C} , {A, B, C} = Ω}
P (A) = C2 (3) /C2 (5) = 0.3,
P (B) = 3 ∗ 2/C2 (5) = 0.6,
P (C) = 1/C2 (5) = 0.1,
P ({A, B}) = 0.3 + 0.6 etc.
2
2. Write a probability space for the random experiment:
Two persons compete. They alternately toss a coin. The winner is he, who first obtains
the head. Result of the experiment is the winner.
A = the winner is that who begins
B = the winner is that who played as the second one
Ω = {A, B}
A = {∅, {A} , {B} , {A, B} = Ω}
P (A) = 2/3 (geom. series with the firs term 1/2 and quotient 1/4)
P (B) = 1/3
2.2
Classical probability
1. What is the probability that a randomly written number with 5 digits that must not
repeat will be even?
[(V4 (10) + 4 (V4 (10) − V3 (9))) / (V5 (10) − V4 (9)) = 0.85]
2. In a pack (consignment) of 100 bulb there are 4 bad. We choose a sample of 5
bulbs. What is the probability that in the sample there will be just one bad bulb.
[C4 (96) C1 (4) /C5 (100) = 0.1765]
2.3
Statistical probability
1. By questioning, the following data sample has been acquired
X = living place \ Y = pay category
N (north)
S (south)
A
32
55
87
B
65
49
114
C
48
61
109
145
165
310
where the events: X is the place of living and Y is the category of the pay (somehow
defined). The table contains corresponding counts of individual cases.
(a) What is a probability that a randomly chosen person:
i) Lives in the South region and has the pay B?
ii) Lives in the North region?
iii) Does not have a pay B?
iv) Does not have a pay B and lives in the South region?
(b) Are the events X and Y independent?
3
3.1
Computation with probabilities
Example [conditioning and independency]
We toss a dice. What is the probability that:
3
1. We obtain even number?
[0.5]
2. We obtain even number that is less than 5?
[1/3]
3. We obtain even number if we know that the number which fell is less than 5?
[0.5]
4. We obtain even number if we know that the number which fell is less than 4?
[1/3]
5. Are the events even number and less than 5 or less than 4 independent?
3.2
[yes, no]
Example [probability tree]
There are 10 balls in a box. Three of them are red, five are white and two are black. Two
men compete alternately drawing one ball. White ball wins, red ball ends the game in a tie
and after drawing the black ball the game continues. What is a probability that
winner
1 the
115
37
+
will be the one who started the game?
2
5 9 8 = 72
3.3
Example [set diagram]
In a class with 27 students two tests have been written. One from Spanish the other from
French. Ten students passed the Spanish test, 18 passed the French one and 5 passed both
the tests. What is the probability, that a randomly chosen student failed in both the tests.
[4/27]
3.4
Example [geometrical probability]
A rod long 1 meter fell on the ground and broke into three pieces. What is the probability
that a triangle can be composed of these three pieces?
[3/4]
4
4.1
Random variable
Example [discrete random variable]
Given the probability function
x
f (x)
3
p
5
0.1
6
1 − 2p
8
0.3
determine p, the distribution function F (x), mean and variance.
Solution:
p + 0.1 + 1 − 2p + 0.3 = 1 → p = 0.4
and
4
x
f (x)
0
0.4
F (x) = 0.5
0.7
1
for
for
for
for
for
x<3
x ∈ h3,
x ∈ h5,
x ∈ h6,
x ∈ h8,
3
0.4
5
0.1
6
0.2
8
0.3
5)
6)
8)
∞)
E [X] = 3 × 0.4 + 5 × 0.1 + 6 × 0.2 + 8 × 0.3 = 5.3
D [X] = (3 − 5.3)2 × 0.4 + (5 − 5.3)2 × 0.1 + (6 − 5.3)2 × 0.2 + (8 − 5.3)2 × 0.3 = 4.41
Remark:
The same, but with
3
5
6
x
f (x) 2p 0.1 1 − p
8
0.3
· · · is not a probability function
and with
3
x
f (x) p
8
0.3
· · · p ∈ (0, 0.5)
4.2
5
0.2
6
0.5 − p
Example [DF of continuous random variable]
Given the density function
(
1 − |x − 1|,
f (x) =
0
on x ∈ (0, 2)
othevise
compute F (x)
Solution:
Z
x
F (x) =
f (x) dx
∞
0
x
f (x) =
2−x
0
for
for
for
for
x<0
x ∈ (0, 1)
x ∈ (1, 2)
x>0
F (x) = 0, for x < 0
Rx
F (x) = 0 + 0 t dt = 12 x2 , for x ∈ (0, 1),
F (1) = 0.5
Rx
F (x) = 0 + 0.5 + 0 (2 − t) dt = − 21 x2 + 2x − 1, for x ∈ (1, 2),
F (x) = 1, for x > 0
5
F (2) = 1
4.3
Example [characteristics of continuous RV]
Compute mean, variance and median for a random variable with the density function (exponential distribution)
f (x) = a exp {−ax} , x ≥ 0, a > 0
Solution:
∞
Z
E [X] =
u = x Rv = a e−ax
|=
u0 = 1
v = −e−ax
x a e−ax dx = |
0
∞
= −x e−ax 0 +
Z
∞
e−ax dx =
0
D [X] similarly, 2x per partes =
1
a
1
a2
Median x̃
x
Z
F (x) =
0
x
a e−at dt = −e−ax 0 = 1 − e−ax
F (x̃) = 1 − e−ax̃ = 0.5
x̃ = −
5
ln 0.5 . 0.6931
=
a
a
Random vector
5.1
Example [discrete random vector]
The random variable Z =
X
Y
is given by its joint probability function. Determine marginal
and conditional pfs.
f (x, y)
x\y
1
2
3
fY (y)
fY |X = f /fY
1
0.1
0.04
0.02
0.16
0.625
0.250
0.125
2
0.02
0.2
0.02
0.24
0.083
0.083
0.083
3
0.02
0.01
0.5
0.53
0.038
0.019
0.943
6
4
0.05
0.01
0.01
0.07
0.714
0.143
0.143
fX (x)
0.19
0.26
0.55
fX|Y = f /fX
0.526 0.105 0.105 0.263
0.154 0.769 0.038 0.038
0.036 0.036 0.909 0.018
5.2
Example [marginal and conditional pdf]
For the joint pdf
f (x, y) =
1
exp x2 + a2 + 1 y 2 − 2axy , x, y ∈ R
2π
compute both marginal and conditional pdfs.
Solution:
After factorization f (x, y) = g (x) h (x, y) = fX (x) fY |X (y|x) we obtain marginal and conditional pdfs.
Can be performed by competition to square in the exponent of f (x, y)
1. x2 − 2axy + a2 + 1 y 2 = x2 − 2axy + a2 y 2 + y 2 = (x − ay)2 + y 2
2. a2 + 1 y 2 − 2axy + x2 =
"
2 #
2
a2
a
a
2
2
+
x
−
xy +
x
x2 =
= a +1 y −2 2
a +1
a2 + 1
a2 + 1
= a2 + 1
y−
a
x
a2 + 1
2
+
1
x2
a2 + 1
All are Gaussian distributions with expectations and variance following from the above derivation.
5.3
Example [characteristics]
Compute expectation, variance and covariance for the RV given by its
Joint pdf
f (x, y) =
2
(x + 2y) , on (0, 1) × (0, 1)
3
Marginal pdfs
Z
fX (x) =
Z
f (x.y) dy,
fY (y) =
Y∗
f (x, y) dx
X∗
Conditional pdfs
fX|Y (x|y) = f (x, y) /fX (x) , fY |X (y|x) = f (x, y) /fY (y)
Expectations
Z
E [X] =
X∗
xfX (x) dx, E [Y ] = · · ·
7
Conditional expectations
Z
E [X|Y ] =
X∗
Variance
Z
D [X] =
X∗
xfX|Y (x|y) dx, E [Y |X] = · · ·
(x − E [X])2 fX (x) dx, D [Y ] = · · ·
Conditional variance
Z
D [X|Y ] =
X∗
Covariance
(x − E [X|Y ])2 fX|Y (x|y) dx, D [Y |X] = · · ·
Z
Z
(x − E [X]) (y − E [Y ]) f (x, y) dx dy
C [X, Y ] =
X∗
For Z =
X
Y
Y∗
we have:
Expectation
E [Z] =
E [X]
E [Y ]
Covariance matrix
C [Z] =
D [X] C [X, Y ]
C [X, Y ]
D [Y ]
% PROGRAM IN MATLAB ( u s e s s y m b o l i c t o o l b o x )
% −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
clc , clear
%% C h a r a c t e r i s t i c s o f two−d i m e n s i o n a l d i s t r i b u t i o n
syms x y
disp ’ Density function ’
f =2/3∗(x+2∗y )
d i s p ’ ( Marginal ) e x p e c t a t i o n s ’
Ex=i n t ( i n t ( x∗ f , y , 0 , 1 ) , x , 0 , 1 )
Ey=i n t ( i n t ( y∗ f , y , 0 , 1 ) , x , 0 , 1 )
d i s p ’ V a r i a n c e s and c o v a r i a n c e ’
Dx=i n t ( i n t ( ( x−Ex) ˆ 2 ∗ f
,y ,0 ,1) , x ,0 ,1)
Dx=i n t ( i n t ( ( y−Ey) ˆ 2 ∗ f
,y ,0 ,1) , x ,0 ,1)
Cxy=i n t ( i n t ( ( x−Ex ) ∗ ( y−Ey ) ∗ f , y , 0 , 1 ) , x , 0 , 1 )
8
d i s p ’ Marginal d i s t r i b u t i o n ’
f x=i n t ( f , y , 0 , 1 )
d i s p ’ Marginal e x p e c t a t i o n − t h e same a s above ’
Exfx=i n t ( x∗ f x , x , 0 , 1 )
disp ’ Conditional distribution ’
f x I y=f / f x
d i s p ’ C o n d i t i o n a l e x p e c t a t i o n and v a r i a n c e ’
ExfxIy=i n t ( x∗ f x I y
,x ,0 ,1)
DxfxIy=i n t ( ( x−Ex) ˆ 2 ∗ f x I y , x , 0 , 1 )
d i s p ’ Mind , c o n d i t i o n a l d e n s i t y i s a d i s t r i b u t i o n ’
d i s p ’ o f o n l y one random v a r i a b l e . I t has no s e n s e ’
d i s p ’ t o speak about c o v a r i a n c e o f X and Y ’
% RESULTS OF THE PROGRAM
% −−−−−−−−−−−−−−−−−−−−−−
Density function
f =
(2∗ x )/3 + (4∗ y )/3
( Marginal ) e x p e c t a t i o n s
Ex =
5/9
Ey =
11/18
V a r i a n c e s and c o v a r i a n c e
Dx =
13/162
Dx =
23/324
Cxy =
−1/162
Marginal d i s t r i b u t i o n
fx =
( 2 ∗ x ) / 3 + 2/3
Marginal e x p e c t a t i o n − t h e same a s above
Exfx =
5/9
Conditional d i s t r ib u t i o n
fxIy =
((2∗ x )/3 + (4∗ y ) / 3 ) / ( ( 2 ∗ x )/3 + 2/3)
C o n d i t i o n a l e x p e c t a t i o n and v a r i a n c e
ExfxIy =
l o g ( 2 ) − ( 4 ∗ y ∗ ( ( 3 ∗ l o g ( 2 ) ) / 2 − 3 / 2 ) ) / 3 − 1/2
DxfxIy =
9
( 4 ∗ y ∗ ( ( 9 8 ∗ l o g ( 2 ) ) / 2 7 − 2 9 / 1 2 ) ) / 3 − ( 1 9 6 ∗ l o g ( 2 ) ) / 8 1 + 275/162
Mind , c o n d i t i o n a l d e n s i t y i s a d i s t r i b u t i o n
o f o n l y one random v a r i a b l e . I t has no s e n s e
t o speak about c o v a r i a n c e o f X and Y
10
© Copyright 2025 Paperzz