Professional Documents
Culture Documents
Risk
Risk
Risk
• Understand how tail risks are influenced by the number of Monte Carlo replicates
• What the standard normal distribution table is (AKA z-values, normal scores, etc.)
0.2 =2
= 5 = 10
= 20
0
40 60 80 100 120 140 160
1
Probability
0
40 60 80 100 120 140 160
Not all distributions are normal, but every distribution’s spread has a standard deviation
(which might be infinite)
a = N(m,1)
Homework 02 sd(a) < sd(abs(a))
a abs(a)
Homework 02
• What is the value of max(a)?
30
d = a + a^2
sd(d)
sd(a + b)
1.0
Cumulative probability
0.8
Homework 02
0.6
0.4
0.2
0.0
• What happens when you enter runif(1000,2,4); U(2,4) ? 2.0 2.5 3.0 3.5 4.0
…
[910] 2.469481 3.537798 3.386743 3.405579 2.665324 2.608697 2.144858 2.169205 2.176538
[919] 2.586882 3.777938 2.291973 3.245451 2.659889 3.814183 3.812559 2.751853 2.008008
[928] 2.934167 2.946754 3.247294 2.918095 2.343682 2.588088 3.332253 2.006413 2.585856
[937] 3.405006 2.242065 2.990343 3.051423 2.872148 2.913489 3.938031 3.584531 3.803559
[946] 2.756841 3.640123 2.991660 3.504637 2.184287 2.530199 2.114401 3.292859 2.977973
[955] 2.172667 3.571079 3.402172 2.577729 3.524411 2.941902 3.936480 3.328031 3.712335
[964] 2.033870 2.129998 2.398178 2.099636 2.211583 2.552924 3.290095 3.095562 2.781243
[973] 3.388212 3.940027 2.082203 2.275819 3.569186 2.443720 2.417047 3.277920 3.678258
[982] 2.598554 2.443464 3.676692 3.150439 2.314507 3.116093 3.324041 3.526336 3.617612
[991] 2.425114 3.291598 2.064151 3.356522 3.565127 3.379629 3.102189 3.888492 2.032470
[1000] 2.087093
MC (min=2.0000289, median=2.98896430, mean=2.9937513, max=3.99998002)
1.0
Cumulative probability
0.8
Homework 02
0.6
0.4
0.2
0.0
• What happens when you enter runif(1000,2,4); U(2,4) ? 2.0 2.5 3.0 3.5 4.0
Cumulative probability
1
uniform deviate
0.8
0.6
0.4
0.2
0
0 50 100 150 0 800 1600
op
pe
p
osi
rfe
te
ct
Homework 02
• Let G=c(6, 10, 11, 8, 7, 3, 10, 11, 7, 8, 3, 11, 2, 4) and let H=c(5, 11, 11, 10,
4, 8, 2, 11, 3, 7, 4, 5, 3, 8). What is the mean of G+H?
G=c(6, 10, 11, 8, 7, 3, 10, 11, 7, 8, 3, 11, 2, 4)
H=c(5, 11, 11, 10, 4, 8, 2, 11, 3, 7, 4, 5, 3, 8)
mean(G+H)
13.78571
• Using G and H from above, plot G versus H in R using the plot(). What
does the plot look like?
plot(G,H)
10
8
6
4
2 4 6 8 10
Homework 02
• Using R's cor( ) function, what is the correlation between G and H?
cor(G,H)
[1] 0.3820118
• Enter sG = sort(G); sH = sort(H); rH = rev(sH) in the R Console. What is
the mean of the sums sG+sH? mean(sG+sH) mean(sG+rH)
[1] 13.78571 [1] 13.78571
• Enter plot(sG,sH). What does the plot look like?
10
10
Points Points
8
8
plot(sG,sH) plot(sG,rH)
sH
monotonically monotonically
rH
6
6
increasing decreasing
4
4
2
2
Homework 02
• What does it mean to say that random variables X and Y are independent
of one another?
knowing something about X doesn't tell us anything about Y, and vice versa
c = U(-2,5, r=a)
purple(a + c) # perfect
d = U(-2,5, r = -a)
green(a + d) # opposite
Other correlations in sra.r
• You can specify other intermediate correlations
• Between opposite and perfect which are the extreme cases
Different people will have different probabilities for the same event,
depending on what they each know about the world and the event
Rules of probability Kolmogorov’s axioms defining probability theory
• Probability for any event is a value between zero and one
0 P(A) 1
P(∅) = 0
If A B, P(A) P(B)
P(A ∩ B) P(A) P(A & B) P(A)
P(A ∩ B) P(B) P(A & B) P(B)
P(A) P(A ∪ B) P(A) P(A v B)
P(B) P(A ∪ B) P(B) P(A v B)
P((A ∪ B)C) = P(AC ∩ BC) P(not(A v B)) = P(not A & not B)
P((A ∩ B)C) = P(AC ∪ BC) P(not(A & B)) = P(not A v not B)
Derived rules
• Probability of a complement of A is one minus the probability of A
P(not A) = P(AC) =1 P(A)
• The empty set is a subset of the sample space, but the empty set is not
an element of it, so the empty set is an event but it is not an outcome
Fair die
Experiment: roll a fair, six-sided die
Outcome:
Sample space: {1, 2, 3, 4, 5, 6}
Event space: {∅,1,2,3,4,5,6,{1,2},{1,3},,…,{1,6},{2,3},…,{1,2,3},…,{1,2,3,4,5,6}}
• The event space is often the power set of the sample space if it’s finite
• The sample and event spaces for unfair dice are the same so long as all sides
of the die are possible outcomes
The probability of each face is 1/6 for a fair die
A = {2,4,6} B = {1,5}
P(A) = 3/6 P(B) = 2/6
A ∩ C = {2,4} A ∪ C = {1,2,3,4,6}
P(A ∩ C) = P({2,4}) = 2/6 P(A ∪ C) = P(A) + P(C) – P(A ∩ C)
P({1,2,3,4,6}) = 3/6 + 4/6 – 2/6 = 5/6
Two distinguished dice
Experiment: toss two dice
• Probability of any pair is 1/36 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6)
(2,1) (2,2) (2,3) (2,4) (2,5) (2,6)
(3,1) (3,2) (3,3) (3,4) (3,5) (3,6)
(4,1) (4,2) (4,3) (4,4) (4,5) (4,6)
(5,1) (5,2) (5,3) (5,4) (5,5) (5,6)
(6,1) (6,2) (6,3) (6,4) (6,5) (6,6)
Playing dice
• You can figure out the chance of any event A just by summing the
probability masses of each elementary event in the event A
• In this case, it’s easy because each elementary event has mass 1/36
0.8
Cumulative probability
0.6
0.4
0.2
0.0
1 2 3 4 5 6
fair
1.0
1 2 3 4 5 6
2 4 6 8 10 12
0.8
Cumulative probability
3 6 9 12 15 18
0.6
4 8 12 16 20 24
0.4
5 10 15 20 25 30
0.2
6 12 18 24 30 36
0.0
0 10 20 30 40
fair
each face is equally likely
0
1 2 3 4 5 6
1
Cumulative probability
Cumulative probability
B = sample(unfair, many, replace=TRUE)
m=R*B
purple(m)
sum(20 <= m)/many # 0.47
edf(R*B,col=rgb(112/255,48/255,160/255),lwd=3) 0 5 10 15 20 25 30 35
R*B
Note that 0.47 is one minus the intercept on the probability axis
Computing with unfair dice (using sra.r)
p = 1:6
R = dice(6,p)
Cumulative probability
purple(R * B)
20 <= R * B # 0.47
edf(R*B,col=rgb(112/255,48/255,160/255),lwd=3)
0 5 10 15 20 25 30 35
R*B
• But we can pose the question, just to see how different the answers are
1:6 * 1:6
• Perfect: sort both sets random deviates
[1] 1 4 9 16 25 36
1:6 * rev(1:6)
• Opposite: sort one and sort the other in reverse order [1] 6 10 12 12 10 6
many = 3000
Cumulative probability
0.8
sides = 6
0.4
fair = 1:sides # 1 2 3 4 5 6
0.0
1 2 3 4 5 6
Cumulative probability
black(fair,new=TRUE)
0.8
0.4
#assume independence
0.0
i=R*B
0 10 20 30 40
pl(0,40); purple(i)
Cumulative probability
# assume perfect dependence
0.8
R = sort(R)
0.4
B = sort(B)
0.0
p=R*B 0 10 20 30 40
pl(0,40); orange(p)
0.8
B = rev(B)
0.4
o=R*B
0.0
pl(0,40); gray(o) 0 10 20 30 40
General rules for probability logic aka
calculus
• Probability of a complement of A is one minus the probability of A
P(not A) =1 P(A) = P(AC) = P(A)
close-up of .500
0.01
left hand tail .250
0.00
.000
0.00
1.000
0.02
10,000 Trials: .750
close-up of left
0.01
.500
hand tail
.250
0.00
.000
0.00 125.00 250.00 375.00 500.00
0.020
0.020
0.020
Cumulative probability
Cumulative probability
Cumulative probability
Cumulative probability
0.010
0.010
0.010
0.010
0.000
0.000
0.000
0.000
0 100 200 300 400 500 0 100 200 300 400 500 0 100 200 300 400 500 0 100 200 300 400 500
10000 Monte Carlo replicates 20000 Monte Carlo replicates 1e+05 Monte Carlo replicates 1e+06 Monte Carlo replicates
0.020
0.020
0.020
0.020
Cumulative probability
Cumulative probability
Cumulative probability
Cumulative probability
0.010
0.010
0.010
0.010
0.000
0.000
0.000
0.000
0 100 200 300 400 500 0 100 200 300 400 500 0 100 200 300 400 500 0 100 200 300 400 500
But these graphs are themselves random, so they’ll vary when we estimate them again…
100 Monte Carlo replicates 1000 Monte Carlo replicates 2000 Monte Carlo replicates 5000 Monte Carlo replicates
0.020
0.020
0.020
0.020
Cumulative probability
Cumulative probability
Cumulative probability
Cumulative probability
0.010
0.010
0.010
0.010
0.000
0.000
0.000
0.000
0 100 200 300 400 500 0 100 200 300 400 500 0 100 200 300 400 500 0 100 200 300 400 500
10000 Monte Carlo replicates 20000 Monte Carlo replicates 1e+05 Monte Carlo replicates 1e+06 Monte Carlo replicates
0.020
0.020
0.020
0.020
Cumulative probability
Cumulative probability
Cumulative probability
Cumulative probability
0.010
0.010
0.010
0.010
0.000
0.000
0.000
0.000
0 100 200 300 400 500 0 100 200 300 400 500 0 100 200 300 400 500 0 100 200 300 400 500
…although those made from large numbers of replicates are the most stable
Confidence interval for a fractile
The a100% confidence interval for the pth fractile is estimated by [Yi, Yj ],
where Yk is the (n k + 1)th largest value from the Monte Carlo simulation,
i = floor(np b), j = ceiling(np + b), b = z1((1 a)/2)(np(1 p))
• What’s the opposite, the confidence interval for the probability at point?
Kolmogorov-Smirnov bounds
0.8 0.8
0.6 0.6
0.4 0.4
0.2 0.2
0 0
1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9
95% of the time, the entire distribution will lie within the bounds
Register your attendance for today
3. Enter 213653
000000
Do it now
The code’s valid only until 17:30 today
What you should know from today
• How to create variables in sra.a with no, perfect, or opposite dependence
• But that dependence is much more general, and can be nonlinear
• That dependence can affect convolutions, especially in the tails
• How to detect intervariable dependence with plot() and cor()
• Do homework at https://forms.gle/F1KW93Acp9MQr2hk6