You are on page 1of 6

Lunds Universitet FMSF15/MASC03 Markovprocesser

Matematikcentrum
Matematisk statistik

Markov processes, lab 2


The first part of the lab is about simple Poisson processes. You will simulate
and analyse Poisson processes for various intensities, on the line as well as in the
plane. In addition, the intensity of a real process will be estimated.
In the final part, you will do both simulation and estimation for a non-homogeneous
processes.

1 Preparations
Read through the instructions and answer the following questions. It is required
that you bring your written answers with you to the computer lab. In the begin-
ning of the computer session the lab supervisors will check your answers before
you carry out the rest of the assignment.

1. What is meant by independent increments of a stochastic process?

2. What is the distribution of the number of events N (t) in the interval (0, t]
for a Poisson process? What is the mean and standard deviation of N (t)?

3. What is the distribution of the time between two consecutive events in a


Poisson process?

4. We have observed a process that may be modelled as a Poisson process in


the interval (0, t].

(a) Derive the ML estimator of the intensity λ.


(b) How can one compute a confidence interval for the estimator in (a)?

5. If one has observed two independent Poisson processes with different in-
tensities λ1 and λ2 , during different time intervals, how can one compute a
confidence interval for the difference λ1 − λ2 ?

6. How can one simulate a non-homogeneous Poisson process?

1
2 The Poisson process
Log in at one of the PCs in the computer room MH:230 or MH:231 with your
STIL-account. Choose the latest version of Matlab from the Start menu. If you
have problems either logging in or starting Matlab, ask for help.
After starting Matlab write mh init(´fmsf15´) in the command window in
Matlab. This will add the directory containing the m-files which you will use
in this assignment.

2.1 Simulation of exponentially distributed holding times


The distance between two events in a Poisson process is exponentially distributed
with intensity λ, where λ is the intensity of the Poisson process. To simulate a
Poisson process we need to simulate these distances, but standard MATLAB
can only generate uniform and normal random variables (the Statistics Toolbox
can do a lot more, however). We can generate exponentially distributed random
variables through a transformation of uniform ones.
Assume that we want to simulate random variables with the distribution function
F (y), and that F (y) is invertible. Denote its inverse by F −1 (y) and let U be a
random variable that has a uniform distribution on (0, 1). If we put Y = F −1 (U ),
then

P (Y ≤ y) = P (F −1 (U ) ≤ y) = P (F (F −1 (U )) ≤ F (y)) = P (U ≤ F (y)) = F (y).

This shows that the transformed variable Y has distribution function F , and we
can obtain exponentially distributed variables from a uniform U as

Y = − ln (1 − U )/λ,

where the intensity of the exponential distribution is λ. In MATLAB one can


generate a vector of 100 exponentially distributed random variables with intensity
λ through the commands:
>> u=rand(1,100);
>> y=-log(1-u)/lambda;

2.2 The counting process


We now have a vector y of inter-event times, but our interest is often in the
absolute time points of the events. We can obtain these by summing the inter-
event times. MATLAB provides a function cumsum, doing just that. Through
T=cumsum(y) we obtain a vector containing the time points of the simulated
events. The value of the process is the number of events so far, hence 1 at the
time point of the first event, 2 at the time point of the second one, and so on.

2
Such a vector may be created as N=1:100, if we want 100 events. The process can
be plotted by stairs(T,N).
Choose an intensity λ and make a few simulations using different random se-
quences u. Plot them in the same figure using hold.

2.3 Estimation of a Poisson intensity


The intensity λ of a Poisson process is the expected number of events per time
unit. The parameter λ may be estimated by dividing the number of events during
a time interval by the length of that time interval.
Estimate the intensity for some realisations and compute confidence intervals. Do
the cover they the true λ?
Answer:

Make a somewhat longer realisation and compute a confidence interval. How does
the width of the confidence interval change with the number of events?
Answer:

2.4 Estimation of the intensity of a real process


The file coal.dat contains data about coal mine catastrophes in the United
Kingdom from 1851 to 1918. The first column contains day of month, the second
column contains the month, the third column contains the year, the fourth column
contains the number of days elapsed thst year, the fifth column is the number
of days since the last catastrophe and the sixth column contains the number of
casualties in the catastrophe. The number of catastrophes since the start time
may be viewed as a stochastic process that we may plot through summing the
inter-event times.
Load the data using the command load coal.dat and sum the inter-event times
by T=cumsum(coal(:,5)). Put N=1:size(coal,1) and plot the process. Does is
look like a Poisson process?
Answer:

3
Estimate the intensity λ and compute a confidence interval. Give the answer in
the unit catastrophes/year.
Answer:

The intensity does not appear constant throughout the whole period. Split the
data into two time periods with two different intensities λ1 and λ2 . Estimate the
intensities and compute a confidence interval for the difference λ1 − λ2 .
Answer:

Plot the process with years on the x-axis by, for example,
>> stairs(coal(:,3)+coal(:,4)/365,N)
When do the changes occur? What can the underlying reasons be? Also look at
the accumulative casualties process by
>> stairs(coal(:,3)+coal(:,4)/365,cumsum(coal(:,6)))
Answer:

2.5 A different method of simulation on the line and in


the plane
When we studied the Poisson process in one dimension, we used a method based
on inter-event times. The lecture notes also describe a different method. This
method is based on the result that, given n events until t, these n events are
uniformly and independently distributed on [0, t]. Hence we can simulate a Poisson
process on [0, t] by first drawing a number from Po(λt) and then drawing n random
variables Ti from a uniform distribution on the interval.
Make a few simulations on [0, 100] for some different intensities. Use the function
porand to simulate the Poisson variable. Use sort to sort the event times. Plot
Poisson events as marks using e.g. plot(T,0*T,’x’).
The method can also be extended to simulate a Poisson process on the plane.
The intensity is the the number of points per area unit.
Simulate a Poisson process in the area 0 ≤ x ≤ 1, 0 ≤ y ≤ 1, and plot the result
for some different intensities. Use, for example plot(x,y,’x’).

4
Simulate a Poisson process on the triangle with corners in (0, 0), (0, 1) and (1, 0).
Is there more that one way of doing that?
Answer:

3 Non-homogeneous Poisson processes

3.1 Simulation
Find a way to simulate a non-homogeneous process over the interval [0, t] with
t = 10, having intensity λ(u) = 4(1 − cos(u2 /4)). Plot the Poisson points Ti and
the intensity function in the same graph, using e.g.

>> u=0:0.01:10;
>> plot(u,4*(1-cos(u.^2/4)),T,0*T,’x’)

Is the result as you expect it?

3.2 Simulation and estimation


We will now consider an inhomogeneous Poisson process, N (t), on an interval
t ∈ [0, S] with intensity function

λ(t) = θ1 + θ2 cos(2πt/S) + θ3 sin(2πt/S)


p
where θ1 ≥ θ22 + θ32 to ensure λ(t) ≥ 0 for all 0 ≤ t ≤ S.
Given event times T1 , . . . , TN (S) , the negative log-likelihood function is

N (S)
X
l(θ) = Λ(S) + ln(N (S)!) − ln(λ(Tk ))
k=1

RS
where Λ(S) = 0
λ(t)dt = θ1 S.
The following pre-written functions will be used in this part:
• inhom_poisson_simulate: Simulates a random sample from the model.

• inhom_poisson_est: Calculates estimates of the model parameters, the


estimation covariances, and approximate 95% confidence intervals.

5
Use help inhom_poisson_simulate, etc for more information and also read the
Matlab code.
Start with parameter values S = 10 and θ = [20, 15, 0]. Use inhom_poisson_simulate
and simulate a sample with these parameters. As before, plot the intensity fun-
ction and simulated event points and convince yourself that the results are as
expected.
Answer:

The pre-written function inhom_poisson_est mentioned above uses a robustified


Newton optimisation on l(θ) to find the Maximum Likelihood estimate of the
parameters for a given process sample. Find the estimates of the parameters
using the sample you generated above. Do the confidence interval cover the true
parameter values?
Answer:

The accuracy of the estimates depends on the true parameter values. Simulate
new samples with different parameter values and run the estimation function for
each sample. How low can you make the intensity before the estimates deteriorate
significantly? Also increase the intensity; are the three parameters equally easy
to estimate accurately? Why?
Answer:

You might also like