Sie sind auf Seite 1von 10

Maestría Modelado y Simulación – Simulación Estocástica

Taller 2
Simulación de Procesos de Poisson, Simulación de eventos discretos, Análisis
Estadístico e Inferencia Estadística

Julián Mauricio Marroquín Suáreza,


a
Estudiante de Maestría. julianm.marroquins@utadeo.edu.co

Ejercicios:

1. Simulating a Poisson process:

a) Write a program that generates the times of the first n events of a Poisson process having
rate λ (exercise done in class).

____________________________
Maestría Modelado y Simulación – Simulación Estocástica

b) Write a program that generates both, the times of the events until time t, and the
number of events N(t) until time t of a Poisson process having rate λ (note that this is
different to the previous item).

____________________________
Maestría Modelado y Simulación – Simulación Estocástica

2. Application of Poisson processes:

Buses arrive at a sporting event according to a Poisson process with rate 5 per hour. Each bus is
equally likely to contain either 20; 21;…; 40 fans, with the numbers in the different buses being
independent. Write an algorithm to simulate the arrival of fans to the event by time t = 1.

Corrida 1 2 3 4 5 6 7 8 9 10 11 12 13
Fans 228 176 152 87 119 271 118 123 60 121 155 88 146

3. A recursion to calculate the sample mean and sample variance of a data set (From pages 139
and 140 in Ross):

In order to use the "Method for Determining When to Stop Generating New Data"(slide 9 in
presentation 6) it is valuable a method for recursively computing the successive sample means and
sample variances, rather than having to recompute from scratch each time a new datum value is
generated. Consider the sequence of data values X1; X2; …; and let:
𝑗 𝑗 2
𝑋𝑖 (𝑋𝑖 − 𝑋̅𝑗 )
𝑋̅𝑗 = ∑ , 𝑆𝑗2 =∑ , 𝑗 ≥ 2,
𝑗 𝑗−1
𝑖=1 𝑖=1

denote, respectively, the sample mean and sample variance of the first j data values. The following
recursion should be used to successively compute the current value of the sample mean and
sample variance.

With 𝑆𝑗2 = 0, 𝑋0 = 0,

𝑋𝑗+1 − 𝑋̅𝑗
𝑋̅𝑗+1 = 𝑋̅𝑗 +
𝑗+1

1
̅ 2 = (1 − ) 𝑆𝑗2 + (𝑗 − 1)(𝑋̅𝑗+1 + 𝑋̅𝑗 )2
𝑆𝑗+1
𝑗

____________________________
Maestría Modelado y Simulación – Simulación Estocástica

Write a program that uses the recursions given by these equations to calculate the sample mean
and sample variance of a data set.

4. Stopping generating new simulation data:


Write a program to generate standard normal random variables until you have generated n of
them, where n ≥ 100 is such that 𝑆/√𝑛 < 0.1, where S is the sample standard deviation of the n
data values. Note that this is the "Method for Determining When to Stop Generating New
Data"(use the program of the item 3. To calculate the sample mean and variance recursively).

a) How many normals do you think will be generated?

b) How many normals did you generate?

c) What is the sample mean of all the normals generated?

d) What is the sample variance?

e) Comment on the results of (c) and (d). Were they surprising?

____________________________
Maestría Modelado y Simulación – Simulación Estocástica

5. Method of moments
Find the method of moments estimators for the parameters of the Geom(p), Poisson(λ), and
Gamma(α;λ) distributions.

____________________________
Maestría Modelado y Simulación – Simulación Estocástica

____________________________
Maestría Modelado y Simulación – Simulación Estocástica

6. Modelo de urna de Ehrenfest:

a) Halle la matriz de transición P (para el caso de m = 3).


[0 1 0 0]
[⅓ 0 ⅔ 0]
[0 ⅔ 0 ⅓]
[0 0 1 0]
b) Halle el vector de probabilidades límite
[0 1 0 0]
[⅓ 0 ⅔ 0]
[π0, π1, π2, π3] [ 0 ⅔ 0 ⅓ ] = [π0, π1, π2, π3]
[0 0 1 0]

π0 + π1 + π2 + π3 =1
⅓(π1) = π0
π0 + ⅔ (π2)= π1
⅔(π1) + π3 = π2
⅓(π2)= π3

Resolviendo el sistema se tiene:


[π0, π1, π2, π3] = [ ⅛ ⅜ ⅜ ⅛ ]

c) Simule el modelo de urna. Para ello cree una función urn.sim que tenga: Entradas: N (número
de pasos de la simulación), m = 3 (número de bolas), p0 (vector inicial de probabilidades), P (matriz
de transición). Salida: Xn (realización del proceso para cada paso n = 1,2, ···, N)

____________________________
Maestría Modelado y Simulación – Simulación Estocástica

d) Estime el vector de probabilidades límite 𝜋̂ como la proporción de veces que se repite cada
valor 0, 1, 2, 3 después de un largo tiempo (N ≥ 100). Tome los últimos ℓ < N valores para estimar
esta probabilidad. Para ello cree una función longrun.prob que tenga: Entradas: Xn (realización del
proceso para cada paso n = 1, 2, ···, N), ℓ (número de datos para estimar la proporción). Salida: 𝜋̂
(estimador de las probabilidades límite).

Compare el estimador 𝜋̂ con el valor real de π hallado en el numeral b). ¿Cómo puede mejorar la
precisión de su estimación?

7. (Bonus point) Gaining confidence with confidence intervals


We know that the U (-1; 1) r.v. has mean 0. Use a sample of size 100 to estimate the mean and
give a 95% confidence interval. Does the confidence interval contain 0? Repeat the above a large
number of times. What percentage of time does the confidence interval contain 0? Write your
code so that it produces output similar to the following.

____________________________
Maestría Modelado y Simulación – Simulación Estocástica

____________________________
Maestría Modelado y Simulación – Simulación Estocástica

____________________________

Das könnte Ihnen auch gefallen