Professional Documents
Culture Documents
Introduction of S&M
*
Introduction to
probability and ** ***
statistic
Generation of
First
random numbers Review
and Monte Carlo
Markov Simulation
and Discret Event
Modelling
Beer Game Second
Review
System Dynamics
Modelling
System Dynamics
Modelling
Agent Based Diserta Final
Delivery
Modelling tion review
*Quiz_1 (Concepts)
**Workshop_2 Introduction to Simulation * Note: It’s important in these classes that you
***Workshop_3 Probability
share knowledge with classmates and attend.
Outline
Ejemplo: Acertijo colegial de un animal que cae en un pozo de 30 metros de profundidad a las 6 de la mañana.
Sube 3 metros en el día, pero en la noche cae 2 metros (6 p.m. – 6 a.m.) ¿Cuándo sale a la superficie?
Conceptualisation: Randomness and Probability
Workshop_1
El tiempo entre la ciudad A y B es de 2 horas, mientras que el recorrido en sentido inverso toma 2,5
horas. Se debe tener un servicio cada hora, a la hora en punto (de las 6 a las 16 horas) entre cada
ciudad. El conductor del vehículo debe descansar media hora cuando termina un viaje.
Obtenga a través de la simulación, la mínima cantidad de vehículos necesarios para cumplir con este
plan.
Conceptualisation: Randomness and Probability
Hora salida Hora llegada Hora salida Hora llegada Sitio Hora
Vehículo A B B A Disponible Disponible
1 6 8 B 8,5
2 6 8,5 A 9
3 7 9 B 9,5
4 7 9,5 A 10
5 8 10 B 10,5
6 8 10,5 A 11
2 9 11 B 11,5
1 9 11,5 A 12
4 10 12 B 12,5
3 10 12,5 A 13
Conceptualisation: Randomness and Probability
Conceptualisation: Randomness and Probability
In simulation experiments there is a need to generate values of random variables that represent a
certain probability distribution. Some characteristics of random numbers are the following:
Uniformly Distributed
Statistically Independent
playable
Long period (no repeats within a given length of the sequence)
Generated through a quick method.
Generated through a method that does not require much storage capacity.
Additional Material:
https://www.youtube.com/watch?v=5Lwf1BWgMow
Conceptualisation: Randomness and Probability
X X2 N° Random
445 1| 9802 | 5 0,9802
9802 96| 0792 | 04 0,0792
792 6 | 2726 | 4 0,2726
2726 ............... ...............
Conceptualisation: Randomness and Probability
Workshop_2
Generate random numbers with the following seeds using the mean squares method:
a. 3892
b. 8364
c. 2749
d. 5357
e. 7600
f. 4583
g. 5555
Conceptualisation: Randomness and Probability
2. Congruential Methods
Example in Excel
a: multiplier
Xn
b: bias Un
m: modulus m
Xo: seed (initial value)
Conceptualisation: Randomness and Probability
Workshop_3
Generate random numbers with the following seed using the congruential method:
1. Seed: 22
a: 33
b: 9
m: 444
2. Seed: 4364
a: 45
b: 34
m: 3146
Conceptualisation: Randomness and Probability
1. sample(1:30,10,replace=F)
2. [1] 4 27 3 19 29 9 21 13 23 20
Accumulated
(Distribution Function)
Continuous
Theoretical
Conceptualisation: Randomness and Probability
Uniform
Exponential
gamma
Continuous Distribution Weibull
Normal
Normal – Logarithmic
Beta
Triangular
Poisson
Bernoulli
Discrete Distribution
Binomial
Discreet Uniform
Conceptualisation: Randomness and Probability
Uniform: unif
Exponential: exp
Continuous Distribution Gamma: gamma
Weibull: weibull
Normal: norm
T-Student: t
Poisson: pois
Discrete Distribution
Binomial: nbinom
Conceptualisation: Randomness and Probability
1. rbinom(15,10,0.6)
2. plot(dbinom(0:10,10,0.6),type="h",xlab="k",ylab="P(X=k)",main="Función de Probabilidad B(10,0.6)")
Conceptualisation: Randomness and Probability
Kolmogorov Smirnov
Shapiro Wilk
You need to check whether it is correct to assume that the fill volume (in ounces) of a
juice vending machine follows a normal distribution, so 25 bottles are drawn at
random. The fill volume data obtained from the sample is stored in the volume
vector.
volumen <-
c(8.39,12.14,11.80,12.04,7.34,12.62,11.51,12.4
7,11.08,14.32,11.33,11.56,12.79,11.72,12.84,1
1.73,12.14,11.88,11.95,10.84,11.79,13.21,12.5
6,12.55,12.80)
Steps
require(MASS)
Ajusten<-fitdistr(volumen, "normal") Calculate Hypothetical Distribution
Ajusten
mean sd
11.8160000 1.3755959
( 0.2751192) ( 0.1945386)
data: volumen
D = 0.21198, p-value = 0.2112
alternative hypothesis: two-sided
Conceptualisation: Goodness-of-fit-tests – Anderson-
Darling
require(MASS)
Ajusten<-fitdistr(volumen, "normal")
Ajusten Calculate Hypothetical Distribution
mean sd
11.8160000 1.3755959
( 0.2751192) ( 0.1945386)
require(goftest)
Adn<-ad.test(volumen, "pnorm", mean =Ajusten$estimate[1], sd= Ajusten$estimate[2])
Adn
Anderson-Darling test of goodness-of-fit
Null hypothesis: Normal distribution
with parameters mean = 11.816, sd = 1.3755958708865
Parameters assumed to be fixed
data: volumen
An = 1.6222, p-value = 0.1501
Conceptualisation: Goodness-of-fit-tests – Shapiro-
Wilk
require(MASS)
Ajusten<-fitdistr(volumen, "normal")
Ajusten Calculate Hypothetical Distribution
mean sd
11.8160000 1.3755959
( 0.2751192) ( 0.1945386)
Conclusion:
Swn<-shapiro.test(volumen) According to the p-value of the Kolmogorov Smirnov (0.2112)
Swn and Anderson Darling (0.1501) tests, the filling volume follows a
normal distribution, since these values are greater than the level
of significance used in this test (0.05). However, when analysing
Shapiro-Wilk normality test the Shapiro-Wilk test, it is observed that the p-value (0.00043) is
lower than the level of significance, therefore the null
data: volumen hypothesis would be rejected and it would be concluded, with a
W = 0.81611, p-value = 0.0004272 confidence level of 95%, that the data does not follow a normal
distribution and would give meaning to what was observed in the
exploratory analysis.
Conceptualisation: Goodness-of-fit-tests
Workshop_4
On the other hand, to take action on the current filling process, the quality department takes 15
samples each of size 8 and records the number of bottles that do not meet the volume specifications
stipulated by the department, these data are given in the rejected vector. However, the department
finds it more useful to analyse the proportion of bottles that do not meet specifications and wants to
verify that this variable does indeed follow a normal distribution using a significance level of 0.01.
H1: the proportion of bottles rejected does not follow a normal distribution.
rechazadas<-c(5,1,3,3,1,4,2,2,6,4,2,3,4,3,5)
proporcion<-rechazadas/8 proporcion
Conceptualisation: Goodness-of-fit-tests – Chi-square
In a Bank, 20 hours were analysed and the data associated with the number of people who enter the
bank per hour are defined in the users vector.
usuarios<-c(50,42,60,39,44,54,48,44,43,50,66,62,43,50,45,43,47,46,52,55)
H0: The number of people entering the bank per hour follows a Poisson distribution.
H1: The number of people entering the bank per hour does not follow a Poisson distribution.
Conceptualisation: Goodness-of-fit-tests – Chi-square
par(mfrow=c(1,2))
hist(usuarios, xlab = "Usuarios", ylab = "Frecuencia", las=1, main = "", col = "gray")
plot(density(usuarios), xlab = "Usuarios", ylab = "Densidad", las=1, main = "")
Conceptualisation: Goodness-of-fit-tests – Chi-square
Steps
require(vcd)
gf<-goodfit(usuarios, type = "poisson", method = "MinChisq") 1. Update package (vcd)
gf$par 2. Call goodfit function
summary(gf)
Results:
$lambda
[1] 49.63808
Goodness-of-fit test for poisson distribution
tiempo<-c(9.2,10.5,10.8,12.3,14.8,15.6,16.1,19.5,22.4,24.7,25.3,26.5,29.9,30.3,30.7,35.6,46.5,50.4,68.2,90.6)
H0: the time a user spends in the bank follows an exponential distribution.
Verify the following hypotheses H1: The time a user spends in the bank follows an exponential distribution.
and determine what distribution
function have a better fit.
H0: the time a user spends in the bank follows a Weibull distribution.
H1: the time a user spends in the bank follows a Weibull distribution.
Workshop Final Project
Markov Chains
Markov Chains
A Markov chain is a probabilistic model describing a system that changes from state to state, and in
which the probability of the system being in a certain state at a certain time step depends only on
the state of the preceding time step. The probability that the j is the next state of the chain, given
that the current state is state i, is called the transition probability from i to j.
Additional Reading:
https://ciencias.medellin.unal.edu.co/cursos/algebra-lineal/clases/8-clases/25-
clase-23-aplicaciones-cadenas-de-markov.html
Thanks!