Bayesian Inference for Stochastic Processes
Bayesian Inference for Stochastic Processes
Lyle D. Broemeling
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742
This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been made to
publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or
the consequences of their use. The author and publishers have attempted to trace the copyright holders of all material reproduced
in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright
material has not been acknowledged, please write and let us know so we may rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any
form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and
recording, or in any information storage or retrieval system, without written permission from the publishers.
For permission to photocopy or use material electronically from this work, please access [Link] ([Link]
.[Link]/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-
8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For organizations that have
been granted a photocopy license by the CCC, a separate system of payment has been arranged.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for
identification and explanation without intent to infringe.
and love that helped me face the many challenges in this effort.
[Link]
Contents
2. Bayesian Analysis................................................................................................................... 35
2.1 Introduction .................................................................................................................... 35
2.2 Bayes Theorem ............................................................................................................... 36
2.3 Prior Information............................................................................................................ 38
2.3.1 Binomial Distribution ........................................................................................ 38
2.3.2 Normal Distribution .......................................................................................... 41
2.4 Posterior Information..................................................................................................... 42
2.4.1 Binomial Distribution ........................................................................................ 42
2.4.2 Normal Distribution .......................................................................................... 43
2.4.3 Poisson Distribution........................................................................................... 44
2.5 Inference .......................................................................................................................... 47
2.5.1 Introduction ........................................................................................................ 47
2.5.2 Estimation............................................................................................................ 49
2.5.3 Testing Hypotheses............................................................................................ 50
vii
viii Contents
Index............................................................................................................................................. 423
[Link]
Preface
Bayesian methods are being used in many areas of scientific investigation. This is dem-
onstrated by referring to scientific literature, which shows that the Bayesian approach
is prevalent in medicine, finance, astronomy, economics, cryptology, engineering, and
various branches of biology. For example, in medicine, Bayesian sequential stopping rules
are employed in the design and analysis of clinical trials and are used to assess the accuracy
of various diagnostic tests.
This book is intended to be a textbook for graduate students in statistics and biostatistics
and a reference for consulting statisticians. It will be quite valuable for those involved in
using stochastic processes to model various phenomena. The book adopts a unique data
analytic approach to making inferences for the unknown parameters of the process. The
examples are taken from biology, finance, and sociology; thus, the book should be a good
resource for those consulting in those areas of scientific endeavor. A good background in
probability and statistical inference is required. Courses in stochastic processes would
further aid the student; however, the book does provide a solid background in stochastic
processes and in Bayesian inference. Two software packages are used in this book. The first
is the R package, which simulates realizations from the relevant stochastic process, while
WinBUGS provides the Bayesian analysis for the unknown parameters. The code for R and
WinBUGS is available at the author’s website: [Link]
Bayesian Inference for Stochastic Processes is a valuable reference for the consulting stat-
istician and for the Bayesian working in the area of stochastic processes. The book can
be thought of as a companion to Bayesian Analysis of Stochastic Process Models by Insua,
Ruggeri, and Wiper, whose approach is more theoretical than that of Bayesian Inference for
Stochastic Processes, which takes a more Bayesian data analysis method.
xiii
[Link]
Author
Lyle D. Broemeling, PhD, is the director of Broemeling and Associates, Inc., and is a con-
sulting biostatistician. He has been involved with academic health science centers for about
20 years and has taught and been a consultant at the University of Texas Medical Branch in
Galveston, the University of Texas MD Anderson Cancer Center, and the University of
Texas School of Public Health. His main interest is developing Bayesian methods for use in
medical and biological problems and in authoring textbooks in statistics. His numerous
books include Bayesian Biostatistics and Diagnostic Medicine, Bayesian Methods in Epidemiol-
ogy, and Bayesian Methods for Agreement.
xv
[Link]
1
Introduction to Bayesian Inference for Stochastic
Processes
1.1 Introduction
Chapter 1 presents the overall objectives of the book and a preview of the book. Bayesian
inference is becoming the predominant way to make statistical inferences about the
parameters of a model, and in this case, the model is a stochastic process. Stochastic pro-
cesses is a branch of probability theory, where the parameters of the process are assumed
to be known, but in this book, based on data about the process, inferences about the
parameters will be performed from a Bayesian perspective. Thus, the book requires a good
background in both stochastic processes and Bayesian inference. Fortunately, the reader
will be able to learn these two subjects, namely, stochastic processes and Bayesian inference.
Inference means estimating parameters, testing hypotheses about those parameters, and
predicting future observations of the process. Of course, in order to provide Bayesian
inferences, essential information about the relevant stochastic process is necessary, and this
preview begins with that information.
This book uses R, mainly for generating observations for stochastic processes and for
plotting various observations pertinent for stochastic processes. Also, WinBUGS plays an
important role for executing a Bayesian analysis for the unknown parameters of the model.
It is sometimes employed to generate observations from stochastic processes with known
parameters.
1
2 Bayesian Inference for Stochastic Processes
The next population to be considered is normal with three cases: (1) the mean unknown
and variance known, (2) the mean known and the precision unknown, and (3) both mean
and variance of the normal unknown. In the first case, the prior distribution for the mean is
assumed to be normal with known mean and precision, and then applying the Bayes
theorem results in a normal distribution for the mean. In the second case, a gamma dis-
tribution is assigned to the precision, resulting in a gamma posterior distribution. The third
case is the most realistic, where both the mean and precision are unknown, where a normal
gamma prior is assigned, resulting in a normal gamma posterior for the mean and preci-
sion. The marginal posterior distribution of the mean is a univariate t while that for the
precision is a gamma.
Chapter 2 continues with presenting Bayesian inferential techniques based on the pos-
terior distribution for the binomial and normal populations.
For example, for the normal with both mean and precision unknown, a point estimate of
the mean is the mean of the posterior distribution of the mean. In all three cases of the
normal, the predictive distribution of future observations is derived.
Also, Chapter 2 introduces the fundamental ideas of computing the posterior distribution
via simulation methods. In particular, Monte Carlo Markov chain (MCMC) methods are
described and illustrated with WinBUGS for the normal and binomial populations.
transition probability matrix and the initial distribution that allows one to determine all the
probabilistic properties of the chain.
Continuous Markov chains are those with a continuous index set, and the birth and death
process is a good example. For such a process at a given time, there is the positive prob-
ability of a birth, the positive probability of a death, and, hence, the probability of neither.
These probabilities might depend on the current state of the process, or they may be
independent of the current state, and both situations are explained. What happens in the
long run for a Markov process? For example, suppose the Markov chain initially is in a
given state, then what is the probability that the process will remain in that state in the long
run? Therefore, limiting distributions are important to know, and several examples illus-
trate the limiting distributions of several stochastic process.
As mentioned earlier, the Wiener process (or the Brownian motion) is an example of a
Markov process with continuous state and continuous time, which is used to characterize
the behavior of tiny microscopic particles called the Brownian motion.
Chapter 3 ends with a discussion of stochastic calculus, where the derivative and integral
of Wiener processes are defined and illustrated with many examples. The student will
benefit from solving the many exercises at the end of Chapter 3.
For this example, the R language was used to generate multinomial observations for
the first row of the one-step transition probability matrix, then assuming a uniform prior
for the first-row probabilities, the resulting posterior Dirichlet distribution allows one to
execute a Bayesian analysis for estimating these one-step transition probabilities. In addi-
tion to estimation, a formal Bayesian test of the null hypothesis is performed. The last step of
Bayesian techniques is to derive the predictive distribution for the cell counts of the first row
of the process.
It is very important to know the long-term behavior of a stochastic process. In the long
run, what are the possible states of a Markov chain? And how do they depend on the
initial state? Such problems come under the subject of limiting probabilities. R Code 4.2
(Matrixpower) will be employed to determine the long-term behavior of a Markov chain.
An example based on a study by Albert1 reveals the long-term behavior of the Canadian
Forest Fire Weather Index. A five-state transition matrix is based on data taken over
26 years at 15 weather stations. The time unit is a day, and the following matrix, taken from
one location in the early summer, gives the probability of daily changes in the fire index (the
states of the chain). The fire index has five values: nil, low, moderate, high, and extreme.
0 1
:575, :118, :172, :109, :026
B C
B :453, :243, :148, :123, :033 C
B C
B C
P=B
B :104, :343, :367, :167, :019 C
C: (1.2)
B C
B :015, :066, :381, :505, :096 C
@ A
:000, :060, :149, :567, :224
The limiting probabilities of the five states are determined by computing the matrix
powers of the preceding one-step transition matrix. Stationary distributions are those that
satisfy the matrix equation
π = πP, (1.3)
where P is the one-step transition matrix and π is the vector representing the stationary
distribution. It is explained under what conditions the stationary distribution exists and the
idea illustrated with the preceding five-state chain.
Chapter 4 continues with a presentation of irreducible chains and Bayesian inferences for
transient and recurrent states and the estimation of the period of a state. Also discussed
are ergodic chains and time reversibility and finding the probability of recurrence using
Bayesian methods of inference. Chapter 4 is concluded with a social mobility example
where the stationary distribution is determined by a Bayesian analysis.
Several examples will illustrate the Bayesian approach to making inferences: (1) an
example of inbreeding in genetics; (2) the general birth and death process; (3) the logistic
growth process; (4) a simple model for an epidemic; (5) the chain binomial model and
the Greenwood and the Reed–Frost versions of an epidemic; (6) several genetic models,
including the Wright model; and (7) the Ehrenfest model for diffusion through a cell
membrane.
Bayesian inferences will include determining the posterior distribution of the relevant
parameters, testing hypotheses about those parameters, and determining the Bayesian
predictive distribution of future observations.
Such Bayesian procedures will closely follow those presented in Chapter 4 and will be
composed of generating simulations from the chain, displaying the associated transition
graph for the chain of each example, and employing the appropriate R Code and WinBUGS
Code for the analysis. Inheritance depends on the information contained in the chromo-
somes that are passed down to future generations; humans have two sets of chromosomes,
one from the mother and one from the father. Certain locations of the chromosome contain
detailed information about the physical characteristics of the individual. Chemicals that
make up the chromosome at specific locations (loci) are called genes, and at each locus, the
genes are manifested in one of several forms called alleles.
The first process to be considered is the so-called inbreeding problem, which leads to a
probability transition matrix with three states.
Suppose there are two forms of alleles for a given gene symbolized by a and A; thus,
humans could then have one of three types, namely, aa, AA, or Aa, and are called genotypes
of the locus. In addition, the two genotypes AA and aa are denoted as homozygous, while
Aa is referred to as a heterozygous genotype.
The inbreeding problem has six states: (1) AA × AA, (2) AA × Aa, (3) Aa × Aa, (4) Aa × aa,
(5) AA × aa, and (6) aa × aa.
The laws of inheritance imply the following makeup of the next generation: (1) If the
parents are both of type AA, the offspring will be AA individuals, so that the crossing of a
brother and a sister will be of one type, and P11 = 1. (2) Now suppose the parents are type 2,
namely, AA × Aa, and the offspring will occur in the following proportions: ½ AA and ½ Aa;
therefore, the crossing of a brother and a sister will be ¼ type {AA × AA}, ½ type {AA × Aa},
and ¼ type {Aa × Aa}. (3) Lastly, if the parents are of type Aa × Aa, the offspring are in the
proportion of ¼ type AA, ½ type Aa, and ¼ type aa; thus, brother-and-sister mating will give
1/16 type {AA × AA}, ¼ type {AA × Aa}, ¼ type {Aa × Aa}, ¼ type { Aa × aa}, 1/8 type {AA ×
aa}, and 1/16 type {aa × aa}. It can be shown that the transition matrix is
0 1
1, :0, :0, :0, :0, :0
B C
B 1=4, 1=2, 1=4, 0, 0, :0 C
B C
B C
B 1=16, 1=4, 1=4, 1=4, 1=8, 1=16 C
B C
P=B C: (1.4)
B :0, :0, 1=4, 1=2, :0, 1=4 C
B C
B C
B :0, :0, 1:0, :0, :0, :0 C
@ A
:0, :0, :0, :0, :0, 1:0
Using R, cell counts corresponding to the third row of Equation 1.4 are generated using a
multinomial distribution; then with WinBUGS, the posterior Dirichlet distribution of the
6 Bayesian Inference for Stochastic Processes
transition probabilities is computed. In the same way, Bayesian inferences for the Wright
model for genetics are described.
Next to be considered in Chapter 5 is a general birth and death process that is formulated
as a discrete-time Markov chain (DTMC). We consider a finite population of maximum size
N and a chain {X(n), n = 0,1,2,...} with state space {0,1,2,…,N}, where X(n) is the size of the
population at time n. The birth and death probabilities bi and di depend on the size of
population where
and i = 1,2, …, P00 = 1, and P0j = 0, j ≠ 0 Also note that PN,N+1 = bN = 0; therefore, the N + 1 ×
N + 1 transition matrix is given by
0 1
1, 0, 0, 0, 0,:::::...........................,0
B C
B d1 , 1 − ðd1 + b1 Þ, b1 , 0, 0, 0, 0, 0, 0, 0,:::,,0 C
B C
B C
B 0, d2 , 1 − ðd2 + b2 Þ, b2 ,0, 0, 0, 0, 0, 0,:::,0 C
B C
B C
B
P = B: C: (1.6)
C
B C
B: C
B C
B C
B 0, 0, 0,::::::::::,0, dN−1 , 1 − ðdN−1 + bN−1 Þ, bN−1 C
@ A
0, 0,:::::::::::::::::::::::::::::::::,0, dN , 1 − dN
Thus, the population increases by one, decreases by one, or remains the same. There are
two communicating classes, namely, {0} and {1,2,…,N}, where 0 is an absorbing state and
the remaining are transient. Based on the one-step transition probability matrix in Equation
1.6, corresponding cell counts are generated with R using a multinomial generator for the
rows; then assuming a uniform prior for the transition probabilities, the resulting posterior
distribution for a given row has a Dirichlet distribution, from which WinBUGS is employed
to determine appropriate Bayesian inferences, including estimates for the stationary dis-
tribution for the birth and death process. This is generalized to the logistic growth process,
which is a variation of the birth and death process, where similar inferences are carried out.
Chapter 5 continues with using Markov chains to model the evolution of an epidemic and
then explores the use of Bayesian techniques to provide inferences for the unknown tran-
sition probabilities (which contain the basic parameters that describe the epidemic) of the
process. The first to be discussed is an explanation of the basic principles of an epidemic,
that is, the biological foundation of an epidemic. Next, a deterministic version of a simple
epidemic is presented, which lays rudiments of the stochastic version of an epidemic model.
Of primary importance in the study of epidemics is to determine the average duration of the
epidemic. Various versions which generalize the simple epidemic are the chain binomial
models, which include the Greenwood model and the Reed–Frost model. The relationship
Introduction to Bayesian Inference for Stochastic Processes 7
between the epidemic model and the previously discussed birth and death process is
obvious.
It can be shown for the stochastic version of a simple epidemic that the one-step transition
matrix of the number of infected people is
0 1
1, 0, ::::::::::::::::::::::::::::::::::::::::::::::, 0
B C
B b + g, 1 − b − g − l1 , l1 , 0, ::::::::::::::::, 0 C
B C
B C
B 0, 2ðb + g Þ, 1 − 2ðb + g Þ − l2 , 0,::::::::, 0 C
B C
B C
P=B
B : C:
C (1.7)
B C
B: C
B C
B C
B: C
@ A
0, ::::::::::::::::::0, N ðb + g Þ, 1 − N ðb + g Þ
Bayesian inferences are executed as before, and based on R, multinomial realizations are
generated for the cell counts according to the transition probabilities of Equation 1.7. Also
considered is another version of the stochastic epidemic called the chain binomial epidemic
model.
Chapter 5 is concluded with various molecular modes for human evolution, and finally,
the Ehrenfest model of cell diffusion is considered. Note that a one-step probability tran-
sition matrix corresponds to each model, allowing one to generate multinomial observa-
tions for the rows followed up with Bayesian inferences for the transition probabilities
executed with WinBUGS.
a common mean 1=l; thus, the waiting times to the occurrence of events are gamma dis-
tributions. Bayesian inferences are based on the prior information and sample information
expressed by the likelihood function.
Suppose Y1 , Y2 , :::, Yn is a random sample from an exponential population of size n
with parameter l and corresponding observations y1 , y2 , :::, yn , then the likelihood function
for l is
!
X
i=n
lðljdataÞ ∝ ln exp −l yi , l>0 (1.8)
i=1
X
i=n
Note that yi is the waiting time to the nth event.
i=1
Prior information will be expressed with the gamma distribution with density
In the former case with the gamma prior, the posterior distribution of l is gamma (n +
X
i=n X
i=n
a, b + yi ), while for the improper prior, the posterior distribution is gamma (n, yi ).
i=1 i=1
Bayesian inferences are illustrated with the following waiting times for a bus problem. A
bus station serves three routes labeled 1, 2, and 3. Buses on each route arrive at the bus
station according to three independent Poisson processes.
Buses on route 1 arrive at the station on the average every 10 minutes; those on route 2
arrive on the average every 15 minutes; while route 3 buses arrive on the average every
20 minutes. Some interesting problems are as follows:
1. When a person arrives at the station, what is the probability that the first bus to
arrive is from route 2?
2. On average, how long will the person wait for some bus to arrive?
3. The person has been waiting for 20 minutes for a bus on route 3 to arrive, and
during this time, three route 1 buses arrive at the station. What is the expected
additional time the person will have to wait for the arrival of a route 3 bus?
Note that we have three independent Poisson processes with parameters: l1 = 10, l2 = 15,
and l3 = 20. Since the parameters are known, it is straightforward to calculate these
probabilities. Let Y1 , Y2 , and Y3 denote the waiting times for buses from routes 1, 2, and 3,
respectively, then it is known that Y1 ∼ exp (1=10), Y2 ∼ exp (1=15), and Y3 ∼ exp (1=20).
To answer question 1, note that the desired probability is given by
Taking a statistical approach, interarrival times for the three Poisson processes are gen-
erated with R, then assuming the three parameters are unknown, and that the priors
are improper, and using as sample information the interarrival times generated by R,
WinBUGS is used to execute the Bayesian analysis, which determines the posterior distri-
bution of the probability in Equation 1.11.
A Bayesian formal test of the null hypothesis
is conducted with the result that the posterior probability of the null hypothesis is very close
to 1. The data used for the test are the 14 waiting times for the first Poisson process with
l1 = :1, the value used to generate the data! It should be noted that in order to conduct a
formal Bayesian test, the prior probabilities of the null hypothesis have to be specified as
well as the prior distribution for l1 under the alternative. This section of Chapter 6 ends
with a derivation of future waiting times for bus number 1.
The Poisson process is generalized to the so-called thinning Poisson processes. A thinning
Poisson event (arrival) can be one of several types, each occurring with some nonzero
probability. The initial process has a given rate l, but the subsequent thinned processes
have rates smaller than l induced by the thinning probabilities of the component processes.
A good example of this is the birth of humans, where the overall birth rate is, say, l, and
the birth rates for males and females are, say, pl and (1 − p)l, respectively, where p is the
probability of a male birth.
If the overall birth process follows a Poisson process, it can be shown that the male births
follow a Poisson process, as do female births; that is to say, both component processes have
stationary and independent increments. Several examples are used to illustrate the idea of
thinning processes. For example, R is used to generate birth rates for males with Poisson
processes and, then based on those data, the Bayesian estimation of p, the proportion of
males, and the overall birth rate l. Also presented is another interesting example of a
thinned Poisson process concerning earthquakes in Italy, where p is the proportion of
major quakes and l is the overall rate of earthquakes. The Bayesian analysis is based on
actual earthquake information. Additional Bayesian inferences are conducted including
the test of hypotheses concerning the equality of the interarrival rates of earthquakes in
three areas of Italy. Lastly, the Bayesian predictive mass function of future earthquakes is
derived.
An important generalization is that the spatial Poisson process is a generalization of the
one-dimensional process studied in Section 6.4 to two or higher dimensions, and there are
many examples: models of location of trees in a forest, the distribution of galaxies in the
universe, and clusters of disease epidemics. Let dimension d > 1 and subset A ⊂ Rd .
Suppose that the random variable N(A) counts the number of points in subset A and |A|
denotes the size of A (in one dimension, |A| would be length, and in two, it would be area,
etc.), then the spatial Poisson process {N(A), A ⊂ Rd } is defined as follows:
Note how properties 1 and 2 generalize the Poisson process to higher dimensions, where
property 1 is the generalization of stationary increments and property 2 describes independent
10 Bayesian Inference for Stochastic Processes
increments. Consider the following problem, in two dimensions with parameter l = 1=3,
then what is the probability that a circle of radius 2 centered at (3,4) contains three points?
The spatial Poisson process is a generalization of the one-dimensional process studied in
Section 6.4 to two or higher dimensions.
Consider the following statistical problem, in two dimensions with parameter l = 1=3,
then what is the probability that a circle of radius 2 centered at (3,4) contains five points? To
answer this question, spatial Poisson process data are generated with R, then parameter l is
estimated by Bayesian techniques including estimation, and tests of hypotheses about l are
executed with WinBUGS.
Three versions of concomitant Poisson processes are considered: (1) independence,
(2) complete similarity, and (3) partial similarity.
Suppose k Poisson processes Ni (t) with parameter li , i = 1, 2, :::, k, where ni events are
observed over the interval (0, ti . The processes could be related.
For example, consider the case where the different processes correspond to different
intersections in a large city where for the ith intersection, Ni (t) counts the number of
accidents at intersection i and the average number of accidents per day (over a 24-hour
period) is denoted by li . One should know enough information about the network of
intersections, such as their proximity to each other and their location to busy businesses etc.
In large cities, traffic communication centers continuously monitor the accidents at each
intersection in the networks. Thus, there are k homogeneous Poisson processes, and we
present Bayesian inferences about parameters li for the cases, namely, of independence of
and complete and partial similarity between the k processes. As before, R is used to gen-
erate accident data at the various intersections; then Bayesian inferences for the three cases
of concomitant processes (independence, partial similarity, and complete similarity) are
provided. Concomitant processes lead us into the ideas of considering Poisson processes
with covariates.
Covariates can be incorporated into the Poisson model in a variety of ways, but only two
are considered here, namely, (1) the direct approach and (2) as part of the prior distribution
of the rate l.
The goal is to determine relationships between several Poisson processes via their
covariates. For example, consider the previous example concerning traffic accidents at
several intersections. We may want to see what factors (covariates) affect the accident
rates between intersections. If the two intersections share the same covariates, one would
compare the two accident rates by comparing the effects of the covariates on the accident
rates.
A simple case is presented: consider two intersections 1 and 2 with a common covariate,
say, the population density of the neighborhoods, which encompasses those neighbor-
hoods (an area surrounding the intersections). Let fN1 (t), t > 0g and fN2 (t), t > 0g be
the Poisson processes that count the number of accidents for intersections 1 and 2 with
accident rates l and lμ, respectively. Thus, the parameter μ modifies the accident rate l,
and one would think that l and lμ reflect the population density of intersections 1 and 2,
respectively. R generates the accident data, and then Bayesian inferences about l and μ are
carried out with noninformative priors for the parameters. Another way to incorporate
covariates into a Poisson process is introduced by assigning the Poisson rate l a gamma
prior distribution, where the parameters of the gamma directly depend on the vector of
covariates.
Chapter 6 concludes with a presentation of the nonhomogeneous Poisson process and
how to choose its intensity function.
Introduction to Bayesian Inference for Stochastic Processes 11
for all states i, j, and x(u), where 0 ≤ u < s. Of course, it is understood that the state space is
countable.
Also, a CTMC is time homogenous, that is to say
Thus, the probabilistic properties of a CTMC over the interval [s,t + s] are the same as that
over the interval [0,t]. Or to express it another way, when the chain visits state i, its forward
behavior from that time toward the future is the same as if the process started in i at time t = 0.
Note that the function Pij (t) is called the transition function of the process. Recall that for a
Poisson process, the interarrival times are identically exponentially distributed; however,
for the CTMC, there is a difference as follows. Let Ti be the holding time of the process, that
is, the time the process occupies state i before switching to another state, then it can be
shown that Ti has an exponential distribution. It is important that one knows the funda-
mental ideas for continuous chains, including transition rates, holding times, and transition
probabilities. An alternative to describing a CTMC is by transition rates between pairs of
states. When the process is in state, there is a chance that it will change to one of the other
possible states, that is, state i is paired with state j for all states j ≠ i. If j can be reached from i,
one can associate an alarm that is activated after a time that has an exponential distribution
with parameter qij . When state i is first occupied, the alarms are all started at the same time,
and the first alarm that is activated determines the next state to be occupied. If alarm (i,j) is
first activated and the process moves to state j, a new set of alarms are activated with
exponential transition rates qj1 , qj2 , :::. Thus, to repeat, the first alarm that is activated
12 Bayesian Inference for Stochastic Processes
determines the next state to be occupied etc. The qij are called transition rates, and from
them, the transition probabilities and holding time parameters can be determined.
Suppose the process starts at i, then the alarms are initiated and the first one that
is activated determines the next transition; therefore, the time of the first alarm is the
minimum of independent exponential random variable X with parameters qi1 , qi2 , :::, which
are exponential random variables with parameter qik . Thus, the process remains in state
k X
i for a holding time which has an exponential distribution with parameter qik = qi . From
k
i, the chain moves to state j if alarm (i,j) is first activated which occurs with probability
which is the transition probability of moving from state i to state j of the embedded chain.
One sees from Equation 1.15 that the transition probabilities of the chain are completely
determined by the transition rates qij .
Consider the matrix Q with off-diagonal elements and transition rates qij , that is, qij = Qij
and i ≠ j; and the diagonal entries are − qi ; thus, each row of Q has a sum of 0. The infin-
itesimal generator matrix Q plays an important role for the Bayesian analysis of the system.
We now see the role that equation pij = qij =qi plays in determining the transition proba-
bility matrix P(t), which is a solution to the forward Kolmogorov equation:
P0 ðtÞ = PðtÞQ,
where Q is the infinitesimal matrix and P0 (t) is the derivative matrix of the transition
probability matrix.
This is also expressed as
X X
P0ij (t) = pik ðtÞqkj = −pij ðtÞqj + pik ðtÞqkj : (1.16)
k k≠j
It is obvious that solution P(t) to Equation 1.16 is given by the matrix equation
where P(0) = I.
Also, the solution can be written as
X
n=∞
P0 ðtÞ = ðd=dtÞetQ = ð1=n !ÞðtQÞn = I + tQ + t2 Q2 =2 + t3 Q3 =3 ! +::::
n=0
It is important to know that R can be used to find the transition probability of the
embedded chain if one knows the infinitesimal generator matrix Q. Consider a four-state
chain with generator matrix
Introduction to Bayesian Inference for Stochastic Processes 13
0 1
−3, 1, 1, 1
B C
B 2, − 6, 2, 2 C
B C
Q=B C: (1.18)
B 3, 3, − 9, 3 C
@ A
4, 4, 4, − 12
X
It is known that πi Qij = 0, ∀ j, which implies that the probability transition matrix of
i
the embedded chain is
0 1
0, 1=3, 1=3, 1=3
B C
B 1=3, 0, 1=3, 1=3 C
B C
P=B C: (1.19)
B 1=3, 1=3, 0, 1=3 C
@ A
1=3, 1=3, 1=3, 0
Chapter 7 continues by demonstrating that R can be used to compute Equation 1.19 based
on the Q matrix (Equation 1.18).
As with discrete time chains, the ideas of stationary and limiting distributions and time
reversibility are defined for the continuous case. See Section 7.3. The first example to be
examined is the deoxyribonucleic acid (DNA) evolution model, which was studied for the
discrete time case in Section 5.7, where the chain had four states, namely, the four base
nucleotides: (1) adenine, (2) guanine, (3) cytosine, and (4) thymine. In the Jukes–Cantor
model, the transition rates are all the same with infinitesimal generator matrix:
0 1
−3r, r, r, r
B C
B r, − 3r, r, rC
B C
Q=B C, (1.20)
B r, r, − 3r, rC
@ A
r, r, r, − 3r
where the first row and column correspond to adenine; the second row and column, to
guanine; the third, to cytosine; and the last row and column, to thymine.
Thus, the corresponding transition matrix is
PðtÞ = expðtQÞ
0 1
1 + 3e−4rt , 1 − e−4rt , 1 − e−4rt , 1 − e−4rt
B C
B 1 − e−4rt , 1 + 3e−4rt , 1 − e−4rt , 1 − e−4rt C
B C
= ð1=4ÞB C: (1.21)
B 1 − e−4rt , 1 − e−4rt , 1 + 3e−4rt , 1 − e−4rt C
@ A
1 − e−4rt , 1 − e−4rt , 1 − e−4rt , 1 + 3e−4rt
14 Bayesian Inference for Stochastic Processes
Thus, at time t, the probability that the DNA base adenine is replaced by quinine (or by
cytosine or by thymine) is (1=4)(1 − e−4rt ), etc. On the other hand, the probability that
adenine at time t is not replaced by another base is (1=4)(1 + 3e−4rt ).
The statistical problem is to make inferences about the rate r based on observing the
evolution at various times.
Based on Equation 1.21, the infinitesimal rates are
qij = r, i ≠ j, i, j = 1, 2, 3, 4;
qi = 3r, i = 1, 2, 3, 4:
If one assigns a value to r, one can make inferences about the holding time parameters
and the transition probabilities; however, one knows that the transition probabilities are all
1/3; thus, only the holding time exponential parameters will be of interest.
In practice, one would observe the holding times of the various states and then from those
observations, estimate r. Using WinBUGS, we will assume a value of r then generate the
exponential holding times. Consider the holding time for occupying the first-state adenine
and assume that its mean time is 2 time units. A WinBUGS analysis is based on 50 obser-
vations of the holding time for adenine with an average holding time of 2 time units. The
main objective is to estimate the average holding time for adenine. WinBUGS is used to
generate the exponentially distributed observations and is used to determine the posterior
distribution of the average holding time of staying on the first state. Also explained is a
formal Bayesian test of hypothesis about the mean holding time:
decrease one unit corresponding to a death, where X(t), t > 0 is the size of the popula-
tion at time t. Since this is a continuous-time process, the chain is defined in terms of the
infinitesimal rate matrix:
0 1
−l0 , l0 , 0, 0, :::::::::::::::
B C
B μ1 , −ðl1 + μ1 Þ, l1 , :::::::: C
B C
B C
B 0, μ2 , −ðl2 + μ2 Þ, l2 , :::: C
B C
B C
B
Q = B 0, 0, μ3 , −ðl3 + μ3 Þ, l3 , : CC, (1.22)
B C
B ::: C
B C
B C
B :: C
@ A
::
corresponding to the state space S = f0, 1, 2, :::g. State 0 is an absorbing barrier; that is,
once the population size reaches 0, it dies out.
Thus, if the population size is 1, the holding time distribution of state 1 until the next
death has an exponential parameter μ1 , while on the other hand, the holding time distri-
bution of state 1 until a birth is exponential with parameter l1 . Note the birth rates li and
death rates μi depend on the present size of the population.
Since the process is time reversible, one can derive the stationary distribution via the local
balance equations
In the infinite case, notice that all states are transient except the absorbing state 0.
Now consider a finite state space with infinitesimal rate matrix and state space
S = {0,1,2,3,4}:
0 1
−l0 , l0 , 0:0, 0:0, 0:00
B C
B μ1 , −ðμ1 + l1 Þ, l1 , 0, 0 C
B C
B C
Q=B
B 0, μ 2 , −ð μ 2 + l2 Þ, l 2 , 0 C
C (1.23)
B C
B 0, 0, μ3 , −ðμ3 + l3 Þ, l3 C
@ A
0:0, 0:0, 0:0, μ4 , −μ4
this important parameter. Other versions of the birth and death process such as the random
walk and Yule process are investigated with the Bayesian approach to inference.
From the least complex, such as the Yule process, to the more complicated, we now
study the so-called birth and death process with immigration. Suppose the immigration
has a rate n included in the simple birth and death process, then the infinitesimal rate
matrix is
0 1
−n, n, 0, 0, 0, 0, 0, 0, 0, ::::::::::::::::::::::::::::::
B C
B μ, −ðn + l + μÞ, n + l, 0, 0, 0, 0, ::::::::::::::: C
B C
B C
B 0, 2μ, −ðn + 2ðl + μÞÞ, n + 2l, 0, 0, 0, 0, ::::: C
B C
B C
B
Q = B 0, 0, 3μ, −ðn + 3ðl + μÞÞ, n + 3l, 0, 0, 0::::::: C C, (1.24)
B C
B: C
B C
B C
B: C
@ A
:
where the rates μ, n, and l are positive and are the parameters of the relevant holding
times, which have an exponential distribution.
Referring to Equation 1.24, it is apparent that if the population is 0, it can increase by one
person if one person immigrates to the population. Our goal is to estimate the parameters
and to test hypotheses about those parameters. In order to perform a Bayesian analysis, let
μ = 1=2, n = 1=3, and l = 1; that is, if the population is size i (i = 1,2, …), the average number
of immigrants per day is 3, the average number of birth is 1, and the average number of
deaths is 2 per day. Note the birth and death rates depend in the present population size,
but the immigration rate does not. The Bayesian analysis is relatively straightforward and
is executed with noninformative prior gamma (.01, .01) distributions and using 35,000
observations for the simulation and a burn-in of 5,000.
Chapter 7 ends with the introduction of the continuous-time version of epidemic models
and is a generalization of the discrete version of stochastic epidemic model of Sections 5.6.1
and 5.6.2. Recall the dynamics of SI and SIS models, where the number of susceptible
people at time t is denoted by S(t) and the number of infected individuals is given by I(t).
Infected individuals are also infectious; that is, there is no latent period, and the total
population size N = I(t) + S(t) remains constant over the period of observation.
This SI model has been used to explain such diseases as the common cold and influenza
where the epidemic is best described by the system of differential equations:
where S(0) + I(0) = N and b is the transmission rate, the number of contacts per unit time
that result in an infection of a susceptible individual. The main parameter of interest is the
transmission rate b, which is estimated by Bayesian methods where the analysis is executed
with WinBUGS. Chapter 7 reveals the details necessary to understand Bayesian inferences
for stochastic epidemics.
Introduction to Bayesian Inference for Stochastic Processes 17
where f (y, t) represents the number of particles per unit volume at position y at time t. It can
be shown that the solution to Equation 8.1 is
pffiffiffiffiffiffiffi 2
f ðy, tÞ = 1= 2πt e−y =2t ; (1.27)
that is, the solution is the density of a normal distribution with mean 0 and variance t. Thus,
the process called the Brownian motion is a continuous-time continuous-state stochastic
process. Albert1 investigated the properties of this process, and the model is sometimes called
a Wiener process, and he showed that the sample functions of the process are continuous
18 Bayesian Inference for Stochastic Processes
almost everywhere, but the process is not differentiable at any time point. The Wiener process
fB(t), t > 0g or standard Brownian motion is defined as follows:
1. For all t > 0, B(t) has a normal distribution with mean zero and variance t.
2. The process has stationary increments, namely, for s,t > 0; B(t + s) − B(s) has the
same distribution as B(t).
3. The process has independent increments; that is, for 0 ≤ q < r ≤ s < t, B(t) − B(s) and
B(r) − B(q) are independent.
4. The function B(t) is continuous with probability 1.
Note that we use the notation that B(t) ~ N(0,t) and recall that the Wiener process can be
interpreted as the movement of a particle that diffuses randomly along a line, where at time,
the
pffiffi location of the particles is normally distributed about the line with standard deviation
t. Wiener’s fundamental contribution to our knowledge was to prove the existence of such
a process as the Brownian motion. Bayesian inferences will be based on independent
increments; because each increment B(t) − B(s) has a normal distribution with mean 0 and
variance t − s for s < t, it is easy to write down the likelihood function. Independent
increments make it easier to evaluate complicated probabilities involving the Brownian
motion.
Also, it is easy to use R to generate Brownian motion values.
The following R Code shows how to generate standard Brownian motion variables over
the interval [0,50], with adjacent observations one unit apart:
t<-1:50
sig2<-1
x<-rnorm(n=length(t)-1,sd=sqrt(sig2))
x<-c(0,cusum(x, t))
plot(t,x,type= "1", ylim=c(-10,10))
In the preceding code, sig2 is the variance of process which is one for standard Brownian
motion, and the corresponding standard deviation is sd. Brownian motion-generated
values are designated by the vector x, and the plot command has an abscissa range from 1 to
50 with time units of length one and with the ordinate range from −10 to 10.
On the other hand, the following R Code generates 30 Wiener variables with s2 = 4.
t<-0:50
sig2<-4
x<-rnorm(n=length(t)-1,sd=sqrt(sig2))
x<-c(0,cusum(x, t))
plot(t,x,type= "1", ylim=c(-8,8))
where the B(i) are the 30 Wiener values generated with the R Code shown earlier, then the
X(i) have independent increments and are distributed as
XðiÞ ∼ Bð2iÞ − Bð2i − 1Þ ∼ Bð1Þ ∼ N 0, s2 (1.29)
The 15 observed increments provide the sample information for the Bayesian analysis
which is executed with 45,000 observations and a burn-in of 5,000. Noninformative prior
distributions are assigned to μ and t, and the posterior distributions show that the posterior
mean of s2 is quite close to the value of 4 used to generate the data. The mean μ should be
zero; thus, it is of interest to test in a formal Bayesian way the null hypothesis H: μ = 0
versus the alternative A: μ ≠ 0 and is conducted with the result that the posterior probability
of the null hypothesis is very close to 1, implying that the simulated independent incre-
ments do indeed have a mean of 0.
Chapter 8 continues by showing the connection between various Brownian motions, and
the Bayesian analysis focuses on the estimation of the parameters (the variance) of the
Brownian motion whose values are generated with R. For example, the following R Code
computes the maximum of a symmetric random walk using 50 replications, where the
generating process is the sequence of binary random variables with values plus one and
minus one with equal probability:
n<-50
sim<-replicate(50,
max(cumsum(sample(c(-1,1),n, replace =T))))
max(sim)
mean(sim)
sd(sim)
s<-seq(1,50,1)
plot(s,sim)
Based on this sample information, Bayesian inferences for the parameters of the Brownian
motion are easily determined, but the details are found in Chapter 8.
One interesting problem for the Wiener process is to determine the time until the process
reaches a particular value, say, the real number v. The first hitting time is described and
defined as follows:
Let Tv be the random variable starting from 0 until reaching v, then
If Tv is thought of as the stopping time, then the process begins with the translated process
at time v.
For a standard Brownian motion at time t, the process is equally likely to be above zero as
to be below zero. Assume v > 0, then for the process beginning at time v, at any time t > v,
the process is equally likely to be above the horizontal line v units above the line y = 0. In
symbols,
ð∞ pffiffiffiffiffiffiffi
P½Tv < t = 2P½BðtÞ > v = 2 1= 2πt exp −x2 =2t dt
v
(1.32)
ð∞ pffiffiffiffiffi
=2 1= 2π exp −x2 =2 dx:
pffi
v= t
Based on a realization of the general Brownian motion with unknown mean and variance,
the goal of the Bayesian approach will be to estimate these two parameters as well as the
preceding moments and to test hypotheses about μ and s2 . R easily generates observations
from the Brownian motion process with known parameters, and then based on the corre-
sponding sample increments, a Bayesian posterior analysis is easily conducted. Remember
that the main focus is to estimate the average hitting time of the target value of 10. The
Bayesian analysis finishes with a test of the hypothesis that the variance of the Brownian
motion is indeed 0.016, the value used in generating the sample information.
The Wiener process reaches a particular level, regardless of how small or large with cer-
tainty, and reaches the level 0 infinitely often. The times the process assumes the value 0 are
called the zeros of the process. Of course, the process has infinitely many zeros occurring in
the interval (0, e), regardless of how small e > 0.
Our goal is to develop Bayesian inferences for the zeros of the Brownian motion and the
last time that the origin is visited by the process. This as will be seen is related to a coin
tossing experiment. Our analysis will focus on the probability zr,t that standard Brownian
motion has at least one zero in the interval (r, t), namely,
pffiffiffiffiffiffi
zr,t = ð2=πÞ arccos r=t , 0 ≤ r < t (1.33)
This is related to the random variable Lt ; the time to the last 0 is shown to be related to an
interesting experiment in coin tossing with two players 1 and 2. If the coin lands heads,
player 1 pays player 2 $1, and if tails occurs, player 2 pays player 1 $1. If the coin is flipped a
large number of times, when would you expect the players to be even? The data for the
Bayesian analysis depend on R as follows: The R Code generates 10,000 tosses of a fair coin,
and the histogram is the last time the two players are even. Of course, this is related to the
number of zeros occurring over a given time interval, and the details of the Bayesian analysis
are described in Chapter 8. A useful generalization of the Brownian motion is when drift is
included.
Consider the Brownian motion with drift defined as
where s > 0, μ is any real number, and fB(t), t > 0g is standard Brownian motion. It can be
demonstrated that this is a normal process with mean μt and variance s2 and that the
process has independent and stationary increments ½X(t + s) − X(t) with mean μs and
variance s2 s, where s,t > 0.
Consider the following application of the Brownian motion with a drift, where the
objective is to estimate the home field advantage by determining the probability that the
home team leads by y points after a fraction t (0 < t < 1) of the game is played. To evaluate
this probability, let X(t) denote the difference in scores between the home team and the
visiting team after 100t% of the game is played.
This approach is based on a Brownian motion process fX(t), 0 < t < 1g, where μ denotes
the magnitude of the home field advantage.
The probability that the home team wins, conditional on the fact they have a y point lead
at time t, is
In order to evaluate this probability, data from the 1992 National Basketball Association
season with 493 games were used, which gave a home field advantage estimated as μ = 4:87
and an estimated standard deviation of s = 15:82. Instead of substituting these two esti-
mates into Equation 1.36, the Bayesian approach will be based on data generated (via R)
with the Brownian motion model and will use the estimates μ = 4:87 and s = 15:82, and then
find the posterior distribution of μ and s2 and finally estimate the desired probability
(Equation 1.36) with WinBUGS. The Bayesian analysis computed a posterior mean of .5025
for the probability that the home team wins when the teams are tied at half time.
Next to be considered in Chapter 8 are two generalizations of the Brownian motion,
namely, geometric Brownian motion and the Brownian bridge.
Geometric processes are used to model exponential growth and decay and are often used
in finance to model stock prices and represent the return from stock options.
22 Bayesian Inference for Stochastic Processes
where fX(t), t > 0g is the Brownian motion with drift μ and variance s2 .
It can be shown that the first two moments for G(t) are
EðGðtÞÞ = Gð0Þ exp t μ + s2 =2
and
2
VarðGðtÞÞ = ets − 1 G2 ð0Þ exp 2t μ + s2 =2 : (1.38)
It is obvious that the mean of the process exhibits exponential growth with growth rate
(μ + s2 =2).
The goal is to develop Bayesian inferences for the parameters of the geometric Brownian
motion using an example about stock prices.
Realizations for the geometric version are easily generated with R by transforming stan-
dard Brownian motion. This is done by transforming the Brownian motion with trend μ = 1
and variance s2 = 0:5, then based on those values, conduct a Bayesian analysis for μ and s2
based on noninformative priors. The last example for Chapter 8 is based on a model for the
selection of stock option on geometric Brownian motion.
An option is a contract that gives its owner the right to buy shares of a stock sometime in
the future at a fixed price.
The following approach is not based on the Black–Scholes model of Section 8.6. Assume
the stock is selling for $90 per share, and under the terms of contract, in 80 days, you may
buy a share of stock for $110. Once having bought the option, several alternatives need to
be considered. Assume that in 80 days, the price of the stock exceeds $110, so if you
exercise the option and buy the stock for $110 and sell it at the current prize, your payoff
would be G(80/365) − 110, where G(80/365) is the price of the stock in 80 days.
However, the other alternative has to be considered, namely, that in 80 days, the stock
price is less than $110, and the option would not be exercised; consequently, you receive
nothing. In general, the two alternatives imply that the payoff is max{G(80/365)−110,0}.
What is the profit for such a situation? It is the payoff minus the cost of the option of $15.
Assuming that the stock price follows the geometric Brownian motion, the following
explanation of how to find the future average payoff is repeated here.
Let G(0) denote the current stock price, and t, the future time the option is exercised.
Suppose k denotes the strike price, the price you can buy the stock if you exercise the option.
Note for this illustration that G(0) = 90, t = 80/365, and k = $110. Our goal is to determine the
average profit of the option, namely,
where
b = ½lnðk=G(0) − tμÞ=s:
Introduction to Bayesian Inference for Stochastic Processes 23
Notice the similarity in the expected payoff of an option and the price of stock given by
the Black–Scholes approach. The two parameters μ and s2 are the drift and variance of the
geometric Brownian motion process, respectively. R easily generates 365 daily values for
the stock process with parameters s2 = 0.25 and μ = 0.1 for the underlying Brownian motion
process, and the Bayesian analysis is executed using these generated values as sample
information. The posterior mean of the expected payoff (Equation 1.39) for the stock option
is $52. The exercises at the end of Chapter 8 increase the knowledge of using Bayesian
methods for Markov chains in continuous times.
process (which can be represented by deterministic or stochastic mechanisms), and then they
have to wait if required before being attended to by one or more servers.
Analytical results for the queuing model are often difficult to determine; thus, interest will
be focused on a case where it is possible, namely, with the M/M/1 process, where the
arrival process is Poisson with parameter l; hence, with exponentially distributed inde-
pendent interarrival times with mean 1=l and independent exponentially distributed
service times with mean 1=μ. The system is denoted by M(l)=M(μ)=1. Notice the similarity
of the queuing process to a birth and death process, where the arrival of a customer is
interpreted as a birth, and the completion of service, as a death. An important parameter is
the traffic intensity that is
r = l=μ; (1.40)
hence, the system is stable if the arrival rate is less than that of the service rate. From
previous considerations, the equilibrium distributions exist, and the limiting distribution
for the number of people in the system is geometric:
with mean E½N = r=(1 − r) and that the number of clients in the queue waiting for service
has the following mass function:
h i
P Nq = n = P½N = 0 + P½N = 1, n=0
(1.42)
= P½N = n + 1, n ≥ 1:
In addition, the limiting distribution for the W spent by an arriving customer in the
system is
The purpose of a Bayesian analysis will be to provide inferences for the unknown param-
eters μ and l. Remember that in practice, one would have data organized as follows: For
each customer, the time of arrival to the queue is recorded, the waiting time also recorded,
and the service time for that client would be noted.
Introduction to Bayesian Inference for Stochastic Processes 25
For the statistician, a distribution needs to be assigned to the waiting times and service
times. These are determined empirically with goodness-of-fit tests, etc., then classical infer-
ences such as maximum likelihood made for parameters μ and l.
For the M/M/1 process, one is assuming that the interarrival times and service times are
exponential, but one must remember that this assumption needs to be justified. For this
case, Bayesian inferences are quite simple. Suppose one has the following information: the
total time ta taken for the first na arrivals and the total time ts taken to service the first ns . It is
obvious that the likelihood function is
Prior distributions must be assigned to l and μ; thus, consider the improper prior
then the posterior distribution of l is gamma (na ,ta ), and that of μ is gamma (ns ,ts ), and l
and μ are independent. Thus, Bayesian inferences are somewhat straightforward if one
knows the sufficient statistics na , ta , ns , and ts ; however, it should be remembered that these
depend on the individual waiting and service times.
Suppose it is assumed that the arrival rate to the queue is Poisson with l = 2 and the
service rate is Poisson with μ = 4, then WinBUGS generates 32 interarrival times with
parameter l = 2 and 24 service times with μ = 4, where the data generated so far is the
sample information for Bayesian inferences. Vector y is composed of the 32 interarrival
times, while vector x denotes the 24 service times.
The main focus of the Bayesian analysis is on the traffic intensity r and the probability the
queue is stable; that is, Pr½r < 1jdata, and the Bayesian analysis computes a posterior mean
of .9838. Chapter 9 continues with Bayesian analyses for the G/M/1 and G/G/1 queues,
where the general interarrival and service time distributions are gamma.
The bulk of Chapter 9 deals with Bayesian inferences for the time series, beginning with
the fundamental properties of a time series, including the three basic components: the trend,
the seasonal effects, and the noise or errors of the process. An R function called decompose
will estimate these three components by graphically delineating a time series into plots
of the trend over time, the seasonal effects over times, and errors versus time. Next to be
considered is the R function acf, which plots the autocorrelations of lag 1, 2, 3, … and
computes estimates of the lagged autocorrelations. The first process to be studied is the
autoregressive process AR(p), with p autoregressive coefficients that determine the auto-
correlation function.
For the AR(1) model,
μðt Þ = 0
26 Bayesian Inference for Stochastic Processes
It is obvious from Equation 1.50 that the autocorrelations are nonzero and decay expo-
nentially with k. Another important second-order property of the AR(p) process is that the
partial correlation function at lag k, which is the correlation that results after removing the
effects of correlations of terms with lags less than k. Note the condition jqj < 1 guarantees
that the process is stationary.
The following R Code generates 100 values from the AR(1) process with autoregression
coefficient q = 0:6. The autocorrelation function is acf while that for the partial autocorre-
lation is pacf. Note that the variance of white noise is s2 = 1.
[Link](1)
y<-w<-rnorm(100)
for( t in 2:100) y[t]<-.6*y[t-1]+w[t]
time <- 1:100
plot(time,y)
acf(y)
pacf(y)
AR(1) process, and the autocorrelation coefficient is assigned with the value of q = :6, while
the regression coefficients are assumed to be 3 for the slope and 50 for the intercept.
The first 20 observations are used as the sample information and are considered vectors
with a multivariate normal distribution with mean vector consisting of 20 values of 50 + 3t,
t = 1, 2, …, 20, and a 20 × 20 precision matrix, which is the inverse of the variance–
covariance matrix with components specified by Equation 1.49, the covariance matrix of an
AR(1) process. Thus, in WinBUGS, one must use the multivariate normal distribution with
mean vector and variance covariance matrix as described earlier. The Bayesian analysis
reported that the posterior means were very close to the corresponding values used to
generate the sample information. Another regression model is analyzed where the trend is
quadratic, and seasonal effects are included resulting in six autoregressive parameters, as
well the autocorrelation coefficient q and variance s2 of the white noise errors. The Bayesian
analysis is based on noninformative prior distributions for these parameters, resulting in
posterior medians very close to the corresponding values used to generate the data.
Next to be considered is the Bayesian analysis of nonlinear regression models with AR(1)
errors, then the moving average class of time series is studied.
A moving average process MA(q) is defined as
where W(t), W(t − 1), :::, W(t − q) is a sequence of independent white noise random variables
with variance s2 and bi , i = 1, 2, :::, q, are unknown real parameters. It is obvious that the
mean value function of the process is zero; the variance is
i=q
!
X
Var½YðtÞ = s2 1+ b2i , (1.53)
i=1
i=q−k i=q
!
X X
r ðk Þ = bi bi+k = b2i : (1.54)
i=0 i=0
[Link](1)
b<-c(.8)
x<-w<-rnorm(1000)
for ( t in 2:1000){
for ( j in 1:1) x[t]<-w[t]+b[j]*w[t-j]}
28 Bayesian Inference for Stochastic Processes
Based on these first 20 values generated by R, the Bayesian analysis will estimate the
parameters of the MA(1) process (Equation 1.55), where the posterior analysis is executed
with 35,000 observations for the simulation and a burn-in of 5,000. Noninformative prior
distributions are used for the parameters: b1 is normal (.8, .01), while s2 is gamma (.001,
.001). Note that it is assumed that the data vector of 20 observations has a multivariate
normal distribution with mean vector zero and a variance–covariance matrix appropriate for
an MA(1) process. Refer to Chapter 9 for the details of the Bayesian analysis, which reveals
that the posterior means are quite close to the corresponding values used to generate the
sample information. In a similar way, Bayesian inferences are developed for the ARMA(1,1)
process and regression models with ARMA(1,1) errors. In each case, observations are gen-
erated for the appropriate model with known parameter values, then based on those
observations, Bayesian inferences are developed for those same parameters.
1.10 R Package
1.10.1 Introduction to R
The following information about R can be downloaded at [Link]
/[Link].
“R is a language and environment for statistical computing and graphics. It is a GNU
project which is similar to the S language and environment which was developed at Bell
Laboratories (formerly AT&T, now Lucent Technologies) by John Chambers and colleagues.
R can be considered as a different implementation of S. There are some important differences,
but much code written for S runs unaltered under R.
R provides a wide variety of statistical (linear and nonlinear modelling, classical statisti-
cal tests, time-series analysis, classification, clustering, …) and graphical techniques, and
is highly extensible. The S language is often the vehicle of choice for research in statistical
methodology, and R provides an Open Source route to participation in that activity.
One of R’s strengths is the ease with which well-designed publication-quality plots can be
produced, including mathematical symbols and formulae where needed. Great care has
been taken over the defaults for the minor design choices in graphics, but the user retains
full control.
R is available as Free Software under the terms of the Free Software Foundation‘s GNU
General Public License in source code form. It compiles and runs on a wide variety of UNIX
platforms and similar systems (including FreeBSD and Linux), Windows and MacOS.”
with autoregressive parameter q = 0:5, moving average parameter b = 0:5, and where
W(t) ∼ normal(0, s2 ) with variance s2 = 1. The following two R statements will gen-
erate 1000 observations from Equation 1.56:
>[Link](1)
>x<-[Link](n=1000,list(ar=.5, ma=0.5))
include the data values and some initial values for the MCMC simulation of the posterior
distribution. The document is given a title and saved as a WinBUGS file, which can be
accessed as needed.
In order to illustrate the essential features of the WinBUGS package, refer to the program
WinBUGS Code 9.15 found in Chapter 9 about estimating the parameters of an ARMA (1,1)
model, with q = 0:5, b = 0:5, and s2 = 1, where the data were generated in Section 1.10.3.
The first 24 observations are as follows:
Y[1,1:25]~dmnorm(mu[],tau[,])
for( i in 1:25){Sigma[i,i]<-v+v*pow(theta+beta,2)/(1-theta*theta)}
list(theta=.5,v=1,beta=.5)
The main body of this program consists of three components, the main statements below
the model and lasting until the first list statement.
Introduction to Bayesian Inference for Stochastic Processes 31
FIGURE 1.1
Specification tool.
32 Bayesian Inference for Stochastic Processes
type theta in the node box and click on Set; lastly, type v then click on Set, and finally, type
an * in the node box. Type 5000 in the beg box, which means the first 5001 observations
generated for the posterior distribution of the beta coefficients. The 5000 observations typed
in beg are referred to as the burn-in. The menu for the monitor tool is depicted in Figure 1.2.
1.11.7 Output
Table 1.1 reports the results of the Bayesian analysis for the ARMA(1,1) process that was
executed by WinBUGS.
Figure 1.4 shows the posterior density of the autoregressive coefficient.
A good reference for learning WinBUGS for Bayesian modeling is Ntzoufras,5 while the
books by Congdon6–8 use WinBUGS to some extent.
FIGURE 1.2
Sample monitor tool.
FIGURE 1.3
Update tool.
Introduction to Bayesian Inference for Stochastic Processes 33
TABLE 1.1
Bayesian Analysis for the ARMA Process
Parameter Value Mean SD Error 2 1/2 Median 97 1/2
β sample: 40001
2.0
P (β)
0.0
FIGURE 1.4
Posterior analysis autoregressive coefficient.
References
1. Albert, J. 2007. Bayesian Computation, New York: Springer-Verlag.
2. Cowpertwait, R. S. P., and Metcalfe, A. V. 2009. Introductory Times Series with R. New York:
Springer-Verlag.
3. Jones, O., Maillardet, R., and Robinson, A. 2014. Introduction to Scientific Programming and Simu-
lation Using R, Second Edition. Boca Raton, FL: CRC Press/Taylor & Francis.
4. Verzani, J. 2005. Using R for Introductory Statistics. Boca Raton, FL: Chapman and Hall/CRC Press.
5. Ntzoufras, I. 2009. Bayesian Modeling with WinBUGS. New York: John Wiley & Sons.
6. Congdon, P. 2001. Bayesian Statistical Modeling. New York: John Wiley & Sons.
7. Congdon, P. 2003. Applied Bayesian Modeling. New York: John Wiley & Sons.
8. Congdon, P. 2005, Bayesian Modeling for Categorical Data. New York: John Wiley & Sons.
[Link]
2
Bayesian Analysis
2.1 Introduction
Bayesian methods will be employed to make inferences for stochastic processes, and this
chapter will introduce the theory that is necessary in order to describe those procedures.
The Bayes theorem, the foundation of the subject, is first introduced and followed by an
explanation of the various components of the Bayes theorem: prior information; informa-
tion from the sample given by the likelihood function; the posterior distribution, which
is the basis of all inferential techniques; and lastly, the Bayesian predictive distribution. A
description of the main three elements of inference, namely, estimation, tests of hypotheses,
and forecasting future observations follows.
The remaining sections refer to the important standard distributions for Bayesian infer-
ence, namely, the Bernoulli, beta, multinomial, Dirichlet, normal, gamma, normal–gamma,
multivariate normal, Wishart, normal–Wishart, and multivariate t-distributions. As will be
seen, the relevance of these standard distributions to inferential techniques is essential for
understanding the statistical analysis of stochastic processes
As will be seen, the multinomial and Dirichlet are the foundation for the Bayesian anal-
ysis of Markov chains and Markov jump processes. For normal stochastic processes such
as the Wiener process and the Brownian motion, the multivariate normal and the normal-
Wishart play a key role in determining Bayesian inferences.
Of course, inferential procedures can only be applied if there is adequate computing
available. If the posterior distribution is known, often, analytical methods are quite suffi-
cient to implement Bayesian inferences and will be demonstrated for the binomial, multi-
nomial, and Poisson populations and several cases of normal populations. For example,
when using a beta prior distribution for the parameter of a binomial population, the
resulting beta posterior density has well-known characteristics, including its moments. In a
similar fashion, when sampling from a normal population with unknown mean and pre-
cision and with a vague improper prior, the resulting posterior t-distribution for the mean
has known moments and percentiles, which can be used for inferences.
Posterior inferences by direct sampling methods are easily done if the relevant random
number generators are available. On the other hand, if the posterior distribution is quite
complicated and not recognized as a standard distribution, other techniques are needed.
To solve this problem, Monte Carlo Markov chain (MCMC) techniques have been devel-
oped and have been a major success in providing Bayesian inferences for quite compli-
cated problems. This has been a great achievement in the field and will be described in later
sections.
Minitab, S-Plus, WinBUGS, and R are packages that provide random number generators
for direct sampling from the posterior distribution for many standard distributions, such as
35
36 Bayesian Inference for Stochastic Processes
binomial, gamma, beta, and t-distributions. On occasion, these will be used; however, my
preferences are WinBUGS and R, because they have been adopted by other Bayesians. This
is also true for indirect sampling, where WinBUGS and R are excellent packages and are
preferred for this book. Many institutions provide special-purpose software for specific
Bayesian routines. For example, at MD Anderson Cancer Center, where Bayesian appli-
cations are routine, several special-purpose programs are available for designing (including
sample size justification) and analyzing clinical trials.
Inferences for stochastic processes consist of testing hypotheses about unknown popu-
lation parameters, estimation of those parameters, and forecasting future observations.
When a sharp null hypothesis is involved, special care is taken in specifying the prior dis-
tribution for the parameters. A formula for the posterior probability of the null hypothesis
is derived, via the Bayes theorem, and illustrated for Bernoulli, Poisson, and normal pop-
ulations. If the main focus is the estimation of parameters, the posterior distribution is
determined, and the mean, median, standard deviation, and credible intervals are found,
either analytically or by computation with WinBUGS. For example, when sampling from a
normal population with unknown parameters and using a conjugate prior density, the
posterior distribution of the mean is a t and will be derived algebraically. On the other hand,
for making Bayesian inferences for Markov chains with finite state space, the posterior
distributions are beta for the individual transition probabilities and are Dirichlet for the
joint distribution of the row transition probabilities. These posterior inferences are provided
both analytically and numerically with WinBUGS. Of course, all analyses should be pre-
ceded by checking to determine if the model is appropriate, and this is where the predictive
distribution comes into play. By comparing the observed results of the experiment with
those predicted, the model assumptions are questioned. The most frequent use of the
Bayesian predictive distribution is for forecasting future observations of stochastic processes
such as for certain Markov chains, Markov jump processes, and time series processes.
where P[A] is the probability of A before one knows the outcome of event B, P[B|A] is the
probability of B assuming what one knows about event A, and P[A|B] is the probability of
A knowing that event B has occurred. P[A] is called the prior probability of A, while P[A|B]
is called the posterior probability of A.
Another version of the Bayes theorem is to suppose X is a continuous observable random
vector, and q ∈ Ω ⊂ Rm is an unknown parameter vector, and suppose the conditional
density of X given q is denoted by f (xjq). If x = (x1 , x2 , :::xn ) represents a random sample of
size n from a population with density f (xjq), and x(q) is the prior density of q, then the Bayes
theorem expresses the posterior density as
Y
i=
xðqjxÞ = c f ðxi jqÞxðqÞ, xi ∈ R and q ∈ Ω, (2.2)
i=1
Bayesian Analysis 37
Y
i=n
where the proportionality constant is c, and the term f (xi jq) is called the likelihood
i=1
function. Density x(q) is the prior density of q and represents the knowledge one possesses
about the parameter before one observes X. Such prior information is most likely available
to the experimenter from other previous related experiments. Note that q is considered a
random variable and that the Bayes theorem transforms one’s prior knowledge of q, rep-
resented by its prior density, to the posterior density and that the transformation is the
combining of the prior information about q with the sample information represented by the
likelihood function.
“An essay toward solving a problem in the doctrine of chances” by the Reverend Thomas
Bayes1 is the beginning of our subject. He considered a binomial experiment with n trials,
assumed that the probability q of success was uniformly distributed (by constructing a
billiard table), and presented a way to calculate Pr (a ≤ q ≤ bjx = p), where x is the number of
successes in n independent trials. This was a first in the sense that Bayes was making
inferences via x(qjx), the conditional density of q given x. Also, by assuming the param-
eter as uniformly distributed, he was assuming vague prior information for q. This type of
prior information, where very little is known about the parameter, is called noninformative
or vague information.
It can well be argued that Laplace2 is the greatest Bayesian because he made many sig-
nificant contributions to inverse probability (he did not know of Bayes), beginning in 1774
with “Memorie sur la probabilite des causes par la evenemens,” with his own version of the
Bayes theorem, and, over a period of some 40 years, culminating in “Theorie analytique des
probabilites.” See Stigler3 and Chapters 9–20 of Hald4 for the history of Laplace’s contri-
butions to inverse probability.
It was in modern times that Bayesian statistics began its resurgence with Lhoste,5
Jeffreys,6 Savage,7 and Lindley.8 According to Broemeling and Broemeling,9 Lhoste was the
first to justify noninformative priors by invariance principals, a tradition carried on by
Jeffreys. Savage’s book was a major contribution in that Bayesian inference and decision
theory was put on a sound theoretical footing as a consequence of certain axioms of prob-
ability and utility, while Lindley’s two volumes showed the relevance of Bayesian inference
to everyday statistical problems and was quite influential and set the tone and style for later
books such as those by Box and Tiao,10 Zellner,11 and Broemeling.12 Books by Box and Tiao
and Broemeling were essentially works that presented Bayesian methods for the usual sta-
tistical problems of the analysis of variance and regression, while Zellner focused Bayesian
methods primarily on certain regression problems in econometrics. During this period,
inferential problems were solved analytically or by numerical integration. Models with many
parameters (such as hierarchical models with many levels) were difficult to use because at
that time, numerical integration methods had limited capability in higher dimensions. For a
good history of inverse probability, see Chapter 3 of Stigler3 and Hald,13 who present a
comprehensive history and are invaluable as references. Dale14 gives a complete and very
interesting account of Bayes’ life.
The last 20 years is characterized by the discovery and development of resampling tech-
niques, where samples are generated from the posterior distribution via MCMC methods,
such as Gibbs sampling. Large samples generated from the posterior make it possible to make
statistical inferences and to employ multilevel hierarchical models to solve complex, but
practical problems. See Leonard and Hsu,15 Gelman et al.,16 Congdon,17–19 Carlin and
Louis,20 and Gilks, Richardson, and Spiegelhalter,21 who demonstrate the utility of MCMC
techniques in Bayesian statistics.
38 Bayesian Inference for Stochastic Processes
xðqÞ = 1, 0 ≤ q ≤ 1,
He used invariance as follows: he reasoned that the prior density of s and the prior den-
sity of 1=s should be the same, which leads to
Noninformative priors where ubiquitous from the 1920s to the 1980s and were included
in all the textbooks of that period. For example, see Box and Tiao,10 Zellner,11 and
Broemeling.12 Looking back, it is somewhat ironic that noninformative priors were almost
always used, even though informative prior information was almost always available.
This limited the utility of the Bayesian approach, and people saw very little advantage
over the conventional way of doing business. The major strength of the Bayesian way
is that it is a convenient, practical, and logical method of utilizing informative prior
Bayesian Analysis 39
information. Surely, the investigator knows informative prior information from previous
related studies.
How does one express informative information with a prior density? For example,
suppose one has informative prior information for the binomial population. Consider
as the prior density for q. The Beta density with parameters a and b has a mean of ½a=(a + b)
and a variance of ½ab=(a + b)2 (a + b + 1) and can express informative prior information in
many ways.
As for prior information for the binomial, consider the analysis of Markov processes,
namely, in estimating the transition probability matrix of a stationary finite-state Markov
chain. Consider the 5 × 5 transition matrix P with components
P = pij , where
0 1
:2, :2, :2, :2, :2
B C
B :2, :2, :2, :2, :2 C
B C
B C
B
P = B :2, :2, :2, :2, :2 C
C: (2.9)
B C
B :2, :2, :2, :2, :2 C
@ A
:2, :2, :2, :2, :2
Note that
where n = 0, 1, 2, ….
That is to say Xn is a discrete-time Markov with state space S = f1, 2, 3, 4, 5g. Note that pij
are the one-step transition probabilities of the Markov chain Xn , where the first row is the
conditional distribution (given X0 = 1) of a discrete random variable with mass points 1, 2,
3, 4, and 5, with probabilities .2, .2, .2, .2, and .2. The second row is the conditional distri-
bution (given X0 = 2) of a discrete random variable with mass points 1, 2, 3, 4, and 5 with
probabilities .2, .2, .2, .2, .2, etc. This is an example of a Markov chain where each state is
recurrent; that is, it is possible to reach any state from any other state, using a multinomial
distribution with probability mass function
i,j=5
Y n
f (njP) ∝ pijij (2.11)
i,j=1
i,j=5
X i,j=5
X
where pij = 1 and nij = n.
i,j=1 i,j=1
40 Bayesian Inference for Stochastic Processes
Ninety-eight nij values are generated from the chain with the following result:
12514153324425553222321453212343342451511451
41344251513124131355414121254442425545243223
212124231442
R Code 2.1 is used to simulate the 98 observations from the Markov chain with transition
matrix P:
R Code 2.1
[Link]<-function(n,P,x1){
sim<-[Link](n)
m<-ncol(P)
if (missing(x1)){
sim[1]<-sample(1:m,1)# random start
} else {sim[1]<-x1}
for ( i in 2:n){
newstate<-sample(1:m,1,prob=P[sim[i-1],])
sim[i]<-newstate
}
sim
}
P<-matrix(c(.2, .2, .2, .2, .2, .2, .2, .2, .2, .2, .2, .2, .2, .2, .2, .2, .2, .2,
.2, .2, .2, .2, .2, .2, .2),nrow=5,ncol=5,byrow=TRUE)
[Link](100,P,1)
0 1
1, 7, 4, 6, 2
B C
B 5, 3, 4, 6, 5 C
B C
B C
N=B
B 3, 6, 2, 3, 1 C
C: (2.12)
B C
B 5, 7, 2, 5, 4 C
@ A
6, 1, 3, 3, 4
Thus, there is one one-step transition from 1 to 1, seven transitions from 1 to 2, and,
lastly, two one-step transitions from 1 to 5. Since the simulation was based on the multi-
nomial distribution, it is known that the marginal distribution of the cell frequency nij is
binomial with parameters pij and n = 98. In order to perform a Bayesian analysis, a prior
distribution is assigned to the unknown cell frequencies: The conjugate distribution to the
multinomial is the Dirichlet, which induces a beta prior to the individual cell frequencies.
This results in a Dirichlet for the posterior distribution of the transition probabilities pij
and, consequently, a beta for the individual transition probabilities. For the Dirichlet, the
density is
Bayesian Analysis 41
i,j=5
Y a −1
f ðp11 , p12 , ::p55 Þ ∝ pij ij , (2.13)
i,j=1
i,j=5
X
where pij = 1 and aij are positive.
i,j=1
Later in this chapter, a posterior analysis for estimating the transition probabilities will be
presented.
h i X
i=m
ð2πÞ−(n−1)=2 s−(n−1) exp − 1=2s2 ðxi − xÞ2 : (2.14)
i−1
This is a conjugate density for the two-parameter normal family and is called the normal-
gamma density. Note that it is the product of two functions, where the first, as a function of μ
and s, is the conditional density of μ given s, with mean x and variance s2 =m, while the
second is a function of s only and is an inverse gamma density. Or equivalently, if the normal
is parameterized with μ and precision t = 1=s2 , the conjugate distribution is as follows: (1) the
conditional distribution of μ given t is normal with mean x and precision mt and (2) the
Xi=m
marginal distribution of t is gamma with parameters (m + 1)/2 and (xi − x)2 =2 =
i=1
(m − 1)S2 =2, where S2 is the sample variance. Thus, if one knows the results of a previous
experiment, the likelihood function for μ and t provides informative prior information for the
normal population.
The normal distribution is very important in describing a normal stochastic process
fX(t), t ≥ 0g, where for each t, X(t) has a normal distribution. The Weiner process (Brownian
motion) is defined as follows:
Consider the time points 0 ≤ t1 < t2 < ::: < tn , where n is a positive integer and suppose
that for each t,
If the process is observed at these n time points, the joint density of the increments
di = X(ti ) − X(ti−1 ) is
where s2 > 0.
Often, it is convenient to parameterize the likelihood in terms of the precision t = 1=s2 ;
thus, the joint density (the likelihood function) is given as
where t > 0.
Of course, the goal of the Bayesian analysis is to estimate the process variance s2 or pre-
cision t > 0. For the Bayesian analysis, a prior distribution must be assigned to t, in which
case, the conjugate distribution, which is a gamma, can be used. The posterior analysis for
the Wiener process will be demonstrated in Section 2.4. Please note that the Wiener process
and the Brownian motion are the same mathematical object.
where nij is the observed transitions from state i to state j and n is the total cell counts for the
5 × 5 cell frequency matrix N. Of course, this is recognized as a Beta (nij + 1, n − nij + 1)
distribution, and the posterior mean is (nij + 1=n + 2). On the other hand, if the Lhoste5 prior
density (Equation 2.4) is used, the posterior distribution of pij is Beta (nij , n − nij ) with mean
of nij =n, which is the usual estimator of pij .
Bayesian Analysis 43
Using the properties of the gamma density, t is eliminated by integrating the joint density
with respect to t to give
xðμ,tjdataÞ
n o ðn−1+1Þ=2 (2.19)
∝ Gðn=2Þn1=2 =ðn − 1Þ1=2 Sπ1=2 Gðn − 10=2Þ = 1 + nðμ − xÞ2 =ðn − 1ÞS2 ,
which is a gamma density with parameters (n − 1)/2 and (n − 1)S2/2. This implies that the
posterior mean is 1/S2 and the posterior variance is 2/(n − 1)S4.
Now consider a Brownian motion example where s2 = 0:01, then R can be used to gen-
erate the following 100 observations:
The vector x contains the 100 simulated values for Brownian motion.
Based on the 100 values generated from the Brownian motion, our goal is to estimate the
variance of Brownian motion using the posterior distribution of t given by Equation 2.16.
Note that
X
i=100
d2i = 1:648375 (2.21)
i=1
and
X
i=100
b= d2i =2 = 0:824187 (2.23)
i=1
respectively. Recall that s2 = 0:01 is the “true” variance of the Brownian motion, which is to be
compared to the estimated value of 0.0166. Is this a reasonable estimate? It should be noted that
that is, the Brownian motion process was sampled at equal time units of length 1.
X
i=n
xi + a − 1
E(qjdata) ∝ q i=1 e−q(n+b) (2.28)
X
i=n
which is identified as a gamma density with parameters a0 = xi + a and b0 = n + b.
i=1
Remember that the posterior mean is a0 =b0 ; median, (a0 − 1)=b0 ; and variance, a0 =(b0 )2 .
One of the most important Markov jump (continuous time and countable state space) is
the Poisson process.
Recall from Chapter 1 that the introduction to the Poisson process N(t) with parameter
l > 0 is defined as follows:
1. N(t) is the number of events occurring over time 0 to t with N(0) = 0, and the
process has independent increments.
2. For all t > 0, 0 < P½N(t) > 0 < 1; that is to say, for all intervals, no matter how
small, there is a positive probability that an event will occur, but it is not certain
that an event will occur.
3. For all t ≥ 0,
where the limit is as h approaches 0. This implies that events cannot occur
simultaneously.
4. The process has stationary independent increments; thus, for all points t > s ≥ 0
and h > 0, the two random variables N(t + h) − N(s + h) and N(t) − N(s) are iden-
tically distributed and are independent.
Based on these four axioms, one may show that for all t > 0, there exists a l > 0 such that
N(t) has a Poisson distribution with mean lt. Thus, the average number of events occurring
over [0,t) is lt, and the average number of events occurring per unit time is l. The Poisson
process is a counting process (it counts the number of events occurring over time) and has
many generalizations that will be introduced in Chapter 7. An interesting feature of the
Poisson process is that the time between the occurrences of two adjacent events has an
exponential distribution. In particular, if N(t), t ≥ 0 is a Poisson process with parameter l,
then the successive interarrival times are independent and have an exponential distribution
46 Bayesian Inference for Stochastic Processes
with mean 1=l; thus, the Poisson process can be simulated via the exponential distribution.
For example, consider a Poisson process with parameter l = 5, and suppose a realization
of 50 using the exponential distribution with mean 1/5 = .2 is to be generated using
WinBUGS Code 2.1
WinBUGS Code 2.1
model {
for (i in 1 : 1000) {
y[i] ~ dexp(.2)
}
}
The 50 corresponding waiting times are the components of the following vector W:
Thus, the first event occurred at time 0.403 time units, and the second, at 11.40 time units,
and the last, at 261.2 units.
Let Tn be the nth interarrival time and Wn be the corresponding waiting time, then
Wn = T1 + T2 + ::: + Tn , (2.29)
Tn ∼ expðlÞ (2.30)
and
That is, the interarrival times have a common exponential distribution with parameter l,
and nth waiting time has a gamma distribution with parameters n and l. In the next section
on inference, based on the preceding interarrival and waiting times, Bayesian inferences for
intensity l will be performed.
Bayesian Analysis 47
2.5 Inference
2.5.1 Introduction
In a statistical context, by inference, one usually means the estimation of parameters, the
testing of hypotheses, and the prediction of future observations. With the Bayesian
approach, all inferences are based on the posterior distribution of the parameters, which in
turn is based on the sample, via the likelihood function and the prior distribution. We have
seen the role of the prior density and likelihood function in determining the posterior
distribution and, presently, will focus on the determination of point and interval estimation
of the model parameters and will later emphasize what is the effect of the posterior dis-
tribution on a test of hypothesis. Lastly, the role of the predictive distribution in testing
hypotheses and in goodness of fit will be explained.
When the model has only one parameter, one would estimate that parameter by listing its
characteristics, such as the posterior mean, media, and standard deviation, and plotting the
posterior density. On the other hand, if there are several parameters, one would determine
the marginal posterior distribution of the relevant parameters and, as mentioned earlier,
calculate its characteristics (e.g., mean, median, mode, standard, and deviation) and plot
the densities. Interval estimates of the parameters are also usually reported and are called
credible intervals.
Suppose we want to estimate
the one-step transition probability of the binomial example of Section 2.4, where the matrix
of cell frequencies
0 1
1, 7, 4, 6, 2
B C
B 5, 3, 4, 6, 5 C
B C
B C
N=B
B 3, 6, 2, 3, 1 C
C (2.32)
B C
B 5, 7, 2, 5, 4 C
@ A
6, 1, 3, 3, 4
Recall that each row is the conditional probability distribution. For example, for the first
row, the conditional probability of a transition from state 1 to states 1, 2, 3, 4, and 5 is .2, .2,
48 Bayesian Inference for Stochastic Processes
.2, .2, and .2. Thus, the number of transitions from state 1 to state 2 is 7. Our objective is to
estimate the transition probabilities fij , based on the cell counts of transitions given by the
matrix N. Note that fij is the one-step conditional (given i) probability of j.
Consider the ith row of the matrix n; then the ith row cell frequencies nij , j = 1, 2, 3, 4, 5,
have a multinomial distribution with parameters fij , where j = 1, 2, 3, 4, 5, and ni : = row total
for row i, where i = 1, 2, 3, 4, 5. Now assuming a uniform prior for the fij , j = 1, 2, 3, 4, 5, the
posterior distribution of the fij is Dirichlet with parameters nij + 1, j = 1, 2, 3, 4, 5. Thus, the
posterior density of fi1 , fi2 , fi3 , fi4 , fi5 is
j=5
Y n
f ðfi1 , fi2 , fi3 , fi4 , fi5 jni1 , ni2 , ni3 , ni4 , ni5 Þ ∝ fijij , (2.34)
j=1
j=5
X j=5
X
where fij = 1 and nij = ni : , j = 1, 2, 3, 4, 5.
j=1 j=1
In order to estimate the fij , consider the posterior mean
j = 1, 2, 3, 4, 5.
Thus, in particular,
j=5
Y
f fi1, fi2 , fi3, fi4 , fi5 ∝ f−1
ij , (2.37)
j=1
j=5
X
where fij = 1 and fij > 0, for j = 1, 2, 3, 4, 5, the posterior distribution of the fij , where j = 1,
j=1
2, 3, 4, 5, is Dirichlet with parameters nij , j = 1, 2, 3, 4, 5; thus, the posterior mean of fij is
is the estimate of f12 = :22. Note that, assuming the improper prior density (Equation 2.37),
the posterior variance of fij is
Thus, in particular,
or
2.5.2 Estimation
What are the 95% credible intervals for the transition probabilities?
Inferences for the normal (μ, t) population are somewhat more demanding, because both
parameters are unknown. Assuming the vague prior density x(μ, t) ∝ 1=t, the marginal
posterior distribution of the population mean μ is a t-distribution with n − 1 degrees of
freedom, mean x, and precision n=S2 ; thus, the mean and the median are the same and
provide a natural estimator of μ, andpbecause
ffiffiffi of the symmetry of the t-density, a (1 − a)
credible interval for μ is x ± ta=2,n−1 S= n, where ta=2,n−1 is the upper 100a=2 percent point
of the t-distribution with n − 1 degrees of freedom. To generate values from the t(n − 1,
x, n=S2 ) distribution, generatepvalues from Student’s t-distribution with n − 1 degrees of
ffiffiffi
freedom, multiply each by S= n, and then add x to each. Suppose n = 30,
X=
(7.8902, 4.8343, 11.0677, 8.7969, 4.0391, 4.0024, 6.6494, 8.4788, 0.7939,
5.0689, 6.9175, 6.1092, 8.2463, 10.3179, 1.8429, 3.0789, 2.8470, 5.1471,
6.3730, 5.2907, 1.5024, 3.8193, 9.9831, 6.2756, 5.3620, 5.3297, 9.3105,
6.5555, 0.8189, 0.4713), then x = 5.57 and S = 2.92.
Using the same dataset, WinBUGS Code 2.2 is used to analyze the problem:
WinBUGS Code 2.2
Model;
{ for( i in 1:30) { x[i]~dnorm(mu,tau) }
mu~dnorm (0.0,.0001)
tau ~dgamma( .0001,.0001) (4.17)
sigma <- 1/tau }
list( x =
c(7.8902, 4.8343, 11.0677, 8.7969, 4.0391, 4.0024, 6.6494, 8.4788,
0.7939, 5.0689, 6.9175, 6.1092, 8.2463, 10.3179, 1.8429, 3.0789, 2.8470,
5.1471, 6.3730, 5.2907, 1.5024, 3.8193, 9.9831, 6.2756, 5.3620, 5.3297,
9.3105, 6.5555, 0.8189, 0.4713))
list( mu = 0, tau = 1)
Note that a somewhat different prior was employed here, compared to the previous one,
in that μ and t are independent and assigned as proper, but noninformative distributions.
The corresponding analysis gives the data found in Table 2.1.
Upper and Lower refer to the upper and lower 2.5 percent points of the posterior distri-
bution. Note that a 95% credible interval for μ is (4.47, 6.65), and the estimation error is
0.003566. See Chapter 1 for the details on executing the WinBUGS statements mentioned
earlier.
50 Bayesian Inference for Stochastic Processes
TABLE 2.1
pffiffiffi
Posterior Distribution of μ and s = 1= t
Parameter Mean Std Dev Markov Chain Error Median Lower Upper
The program generated 30,000 samples from the joint posterior distribution of μ and s
using a Gibbs sampling algorithm and used 29,000 for the posterior moments and graphs,
with a refresh of 100.
and
are required, and on the basis of the two, a decision is made whether or not to reject H in
favor of A or to reject A in favor of H. Of course, also required are the two corresponding
prior probabilities:
π0 = Prðq ∈ Ω0 Þ (2.45)
and
π1 = Prðq ∈ Ω1 Þ: (2.46)
Now consider the prior odds π0 =π1 and posterior odds p0 =p1 . In turn, consider the Bayes
factor B in favor of H0 relative to H1 , namely,
Then, the posterior probabilities p0 and p1 can be expressed in terms of the Bayes factor;
thus,
p0 = 1= 1 + ðπ1 =π1 ÞB−1 , (2.48)
and the Bayes factor is interpreted as the odds in favor of H0 relative to H1 as implied by the
information from the data.
When the hypotheses are simple, that is, Ω0 = fq0 g and Ω1 = fq1 g, the odds ratio can be
expressed as the likelihood ratio.
This interpretation is not valid when Ω0 and Ω1 are composite. Consider the restriction of
the prior density p(q) to Ω0 , namely,
which is the ratio of weighted likelihood functions, weighted by the prior probability
densities restricted to Ω0 and Ω1 .
An important aspect of testing hypotheses is when the null hypothesis is a point null
hypothesis and the alternative is composite; thus, consider
52 Bayesian Inference for Stochastic Processes
H0 : q = q0 (2.55)
versus
H1 : q ≠ q 0 , (2.56)
where q0 is known. How does one assign prior information to this case? A reasonable
approach is to assign a positive probability π0 for the null hypothesis, and for the alter-
native, assign a prior density π1 p1 (q), where
ð
p1 ðqÞdq = 1: (2.57)
q≠q0
Thus, π0 + π1 = 1, and it is seen that the prior probability of the alternative is π1 , and for
values q ≠ q0 , p1 is the density of a continuous random variable that expresses the prior
knowledge one has for the alternative hypothesis.
Let
ð
pðxÞ = π0 pðxjq0 Þ + π1 p1 ðqÞpðxjqÞdq, (2.58)
where x is the vector of observations with conditional density p(xjq) and where p(x) is the
marginal density of the observations.
By letting
ð
p1 ðxÞ = p1 ðqÞpðxjqÞdq, (2.59)
q≠q0
and then the posterior probabilities of the null and alternative hypotheses can be expressed
as
In a similar manner,
p1 = π1 p1 ðxÞ=pðxÞ (2.62)
for the posterior probability of the alternative hypothesis. If one desires to use the Bayes
factor, then one may show
Bayesian Analysis 53
The preceding derivation of the posterior probabilities in the context of hypothesis testing
closely follows Lee.23
In summary, for testing hypotheses via the Bayesian approach, the following is required:
1. The prior probabilities of the null and alternative hypotheses, namely, π0 and π1 .
2. The prior density p1 (q) for values of fq : q ≠ q0 g.
3. The likelihood function, that is, the joint conditional density of the observations
x = (x1 , x2 , :::, xn ) given q, for all values of q in the parameter space.
For the first example in testing hypotheses when the null is simple but the alternative is
composite, consider Section 2.5.2, the example involving a Markov chain with five states, 1,
2, 3, 4, and 5, and an observed transition count matrix
0 1
1, 7, 4, 6, 2
B C
B 5, 3, 4, 6, 5 C
B C
B C
N=B
B 3, 6, 2, 3, 1 C
C: (2.32)
B C
B 5, 7, 6, 5, 4 C
@ A
6, 1, 3, 3, 4
where fij is the one-step transition probability from state i to state j. It is important to
remember that the first row of F is the conditional probability distribution of the five states
given i = 1. That is, given i = 1, f1j is the probability (in one step) of going from state i = 1 to
state j, where j = 1, 2, 3, 4, 5. It is important to note that if f11 > 0, it is possible to remain in
the same state as the initial state i = 1.
The goal is to test the hypothesis that
H0 : f11 = :2 (2.65)
Of course, any fij could have been used to illustrate the Bayesian testing procedure.
54 Bayesian Inference for Stochastic Processes
The posterior probabilities p0 and p1 given by Equations 2.61 and 2.62, respectively, are
required; thus, consider first
where π0 is the prior probability of the null hypothesis and the probability mass function of
n11 (given the null hypothesis) is
!
n1:
pðn11 jf11 = :20Þ = ð:7Þn11 ð:3Þn1:−n11 , (2.68)
n11
and
where 0 ≤ f ≤ 1 and a and b are positive parameters; thus, the prior distribution of f11 is a
beta with parameters a and b. Now it can be shown that the marginal distribution of n11
(Equation 2.69) is
!
n1:
p1 ðn11 Þ = π1 ½Gða + bÞ=GðaÞGðbÞ ½Gðn11 + aÞGðn1: − n11 + bÞ=Gðn1: + a + bÞ, (2.72)
n11
where a and b must be chosen to reflect the prior information about the null hypothesis.
Combining Equations 2.68, 2.70, and 2.72 allows one to evaluate the posterior probability p0
of the null hypothesis. For the problem at hand, let
π1 = π0 = 1=2,
a = 2,
b = 8, (2.73)
n11 = 1, and
n1 = 20,
and one can show that the posterior probability of the null hypothesis is p0 = .552484379,
and for the alternative, p1 = .44751562.
Bayesian Analysis 55
Note that the values used to evaluate the posterior probabilities depend on the values
of Equation 2.73, and these values are somewhat arbitrary. I chose a = 2 and b = 8 for
the parameters of prior beta distribution for values f11 of the alternative hypothesis,
because the prior mean
Eðf11 Þ = a=ða + bÞ = :2 (2.74)
where the integral is with respect to q, and f (xjq) is the density of X = (x1 , x2 :::, xn ), given q.
This assumes that given q, Z and X are independent. Thus, the predictive density is the
posterior average of f (zjq) with respect to the posterior distribution of q.
The posterior predictive density will be derived for the binomial and normal populations.
A beta with parameters a + x and n − x + b and x is the sum of the set of n observations.
The population mass function of a future observation Z is f (zjq) = qz (1 − q)1−z ; thus, the
predictive mass function of Z, called the beta-binomial, is
!
X
i=n
gðzjxÞ = Gða + bÞGðn + 1ÞG a + xi + z Gð1 + n + b − x − zÞ÷
i=1 (2.77)
GðaÞGðbÞGðn − x + 1ÞGðx + 1ÞGðn + 1 + a + bÞ,
where z = 0, 1. Note that this function does not depend on the unknown parameters because
they were averaged with respect to the posterior distribution and that the n past obser-
vations are known, and that if a = b = 1, one is assuming a uniform prior density for q.
As an example, consider the predictive distribution of the binomial distribution; recall
Section 2.4.2 with
0 1
1, 7, 4, 6, 2
B C
B 5, 3, 4, 6, 5 C
B C
B C
N=B
B 3, 6, 2, 3, 1 C
C (2.32)
B C
B 5, 7, 2, 5, 4 C
@ A
6, 1, 3, 3, 4
0 1
f11 , f12 , f13 , f14 , f15
B C
B f21 , f22 , f23 , f24 , f25 C
B C
B C
F=B f , f , f
B 31 32 33 34 35 C, f , f C (2.64)
B C
B f41 , f42 , f43 , f44 , f45 C
@ A
f51 , f52 , f53 , f54 , f55
The relevant quantities of Equation 2.78 are n = 20 and n11 = 1. Also remember that a and
b are the parameters of the prior distribution of f11 , the probability of remaining in state 1,
and that predictive inferences are conditional on n = 20, the total transition counts for the
first row of the one-step transition matrix of the chain.
h i
xðμ, tjdataÞ = tn=2−1 =ð2πÞn=2 exp −ðt=2Þ nðμ − xÞ2 + ðn − 1ÞS2x , (2.80)
where x and S2x are the sample mean and variance, respectively, based on a random sample
of size n, x = (x1 , x2 , :::, xn ). Suppose z is a future sample z = (z1 , z2 , :::, zm ) of size m, then the
predictive density of Z is
ð ðh i
gðzjxÞ = tðn+mÞ=2−1 =ð2πÞðn+mÞ=2 exp −ðt=2Þ
− 2 (2.81)
nðμ − xÞ + ðn −
2
1ÞS2x + m z − μ + ðm − 1ÞS2z ,
ðn+m−3+1Þ
gðzjxÞ ∝ Gððn + m − 1Þ=2Þ= 1 + zðz − xÞ2 =ðn + m − 3Þ , (2.82)
where
− 2
k = ðn − 1ÞS2x + ðm − 1ÞS2z + n2 x =ðn + mÞ: (2.84)
bands for future observations. In the context of stochastic processes, the predictive distri-
bution for future normal observations will be employed to generate future values from
various stochastic processes.
Of interest in the context of the Brownian motion is the predictive distribution of z when
μ = 0, that is, when the posterior density is
" #
h i X
i=n X
i=m
ðn+mÞ=2−1 ðn+mÞ=2
gðzjxÞ ∝ t =ð2πÞ exp −ðt=2Þ x2i + 2
zi : (2.85)
i−1 i=1
For the Wiener process of Section 2.4, the process was sampled at times t1 , t2 , tn with
t1 < t2 <, < tn and with independent increments
di = Xi − Xi−1 (2.87)
zi = xi − xi−1 (2.88)
z = c(
−0.05473,−0.119,0.1056,−0.129,0.05168,
−0.06759,0.07575,0.04806,0.003992,−0.1113,
−0.154,−0.009263,0.09279,−0.06837,−0.07757,
−0.1289,0.03088,0.09818,0.01693,−0.04028,
−0.1602,0.09864,−0.05848,0.002767,−0.1908,
−0.1578,−0.004863,0.04017,−0.05318,0.08215, (2.91)
−0.0231,0.1652,0.01179,0.151,−0.2395,
0.00945,−0.05023,−0.09512,−0.04164,0.09382,
−0.01882,−0.1193,0.03329,0.02761,−0.07163,
−0.05162,0.04595,0.108,0.01209,0.09053,
−0.08401,0.08781,−0.05834,−0.09858,0.1072,
0.1007,0.04107,0.222,0.1023,−0.003405,
−0.002853,0.1584,0.05611,0.05067,0.04823,
0.02001,0.1747,−0.1451,−0.0137,−0.1187,
0.04217,−0.01667,−0.04725,0.00841,0.09915,
−0.05576,0.02669,0.04407,0.03509,0.06624,
0.05622,−0.05857,−0.1255,−0.03296,−0.128,
−0.0193,−0.05927,−0.1122,0.06573,0.06395,
0.044,0.04435,0.04717,−0.1504,0.06941,
−0.03644,−0.04695,−0.1194,−0.003718,−0.08247))
To see the accuracy of the preceding predicted values, the sample mean and variance
should be computed. How close to zero is the sample mean and how close to 0.01 is the
sample variance of the Brownian motion example?
Of course, the prior distribution is an important component of the analysis, and if one is
not sure of the “true” prior, one should perform a sensitivity analysis to determine the
robustness of posterior inferences to various alternative choices of prior information. See
Gelman et al. or Carlin and Louis for details of performing a sensitivity study for prior
information. Our approach is to either use informative or vague prior distributions, where
the former is done when prior relevant experimental evidence determines the prior, or the
latter is taken if there are none or very few germane experimental studies. In scientific
studies, the most likely scenario is that there are relevant experimental studies providing
informative prior information.
X=
(1.9075, 0.7683, 5.8364, 3.0821, 0.0276, 15.0444, 2.3591, 14.9290, 6.3841,
7.6572, 5.9606, 1.5316, 3.1619, 1.5236, 2.5458, 1.6693, 4.2076, 6.7704, 7.0414,
1.0895, 3.7661, 0.0673, 1.3952, 2.8778, 5.8272, 1.5335, 7.2606, 3.1171, 4.2783,
0.2930).
The sample mean and standard deviation are 4.13 and 3.739, respectively. Assume the
sample is from a normal population with unknown mean and variance, with an improper
prior density x(μ, t) = 1=t, μ ∈ R and t > 0; the posterior predictive density is a univariate t
with n − 1 = 29 degrees of freedom, mean x = 3.744, standard deviation of 3.872, and
precision p = 0.645. This is verified from the original observations x and the formula for the
precision. From the predictive distribution, 30 observations are generated:
Z=
(2.76213, 3.46370, 2.88747, 3.13581, 4.50398, 5.09963, 4.39670, 3.24032,
3.58791, 5.60893, 3.76411, 3.15034, 4.15961, 2.83306, 3.64620, 3.48478,
2.24699, 2.44810, 3.39590, 3.56703, 4.04226, 4.00720, 4.33006, 3.44320,
5.03451, 2.07679, 2.30578, 5.99297, 3.88463, 2.52737),
which gives a mean of z = 3:634 and standard deviation S = 975. The histograms for the
original and predicted observations should be computed.
One will see that the histograms obviously are different, where for the original obser-
vations, a right skewness is depicted; however, this is lacking for the histogram of the
predicted observations, which is for a t-distribution. Although the example seems trivial, it
would not be for the first time that exponential observations were analyzed as if they were
generated from a normal population! Of course, we have seen the relevance of the expo-
nential distribution to Markov jump processes such as the Poisson process of Section 2.4.3,
where the interarrival times are independent and identically distributed with a mean that is
the reciprocal of the mean rate of event happenings.
It would be interesting to generate more replicate samples from the predictive distribu-
tion in order to see if these conclusions hold firm.
These 100 observations should be from a normal population with mean 0 and variance 0.01.
What does the histogram of these values indicate about the normal assumption?
The sample mean is x = 0.0204995 and the sample standard deviation is s = 0.1237805 or a
sample variance of s2 = 0.01622. These values are fairly close to the values 0 and 0.01,
respectively, a good indication that the normality distribution of the increments is a rea-
sonable assumption.
62 Bayesian Inference for Stochastic Processes
Y
i=4
f ðn1 , n2 , n3 , n4 , n5 jp1 , p2 , p3 , p4 , p5 Þ ∝ pni i , (2.92)
i=0
X
i=4 X
i=4
where pi = 1 and ni = n with n known and fixed. The vector
i=0 i=0
0 1
n1
B C
B n2 C
B C
B C
n=B C
B n3 C (2.93)
B C
B n4 C
@ A
n5
X
i=4
Note that the constraint ni = n implies that the components of n are correlated, and it
i=0
can be shown that
cov ni , nj = −npi pj : (2.95)
We have seen that the multinomial distribution can be used to generate values from a
Markov chain. Thus, consider the following R Code that allows one to generate observa-
tions from a multinomial:
N<-1000
prob<-c(.2, .2, .2, .2, .2)
rmultinom(1,n,prob) (2.96)
n = 1000 is the sample size and prob is the vector of multinomial probabilities .2, .2, .2, .2, .2
referring to the probabilities of the five categories.
Bayesian Analysis 63
The simulation gives n0 = 215, n1 = 174, n2 = 205, n3 = 204, and n4 = 202, that is, the
number of zeros is 214; the number of ones, 174; the number of twos, 205; the number of
threes, 204; and the number of fours, 202. Based on the multinomial probability vector
prob = (.2, .2, .2, .2, .2), one would expect to have 200 outcomes for each of the five
categories.
Our concern is what is the accuracy of the R Code in generating the five possible values;
that is, does the preceding realization (Equation 2.96) represent a sample from the multi-
nomial distribution?
Note that one could use the chi-square goodness of fit test to test the hypothesis
H : pi = :2 (2.97)
for i = 0, 1, 2, 3, 4.
The test statistic is
X
i=4
c2 = ðni − 200Þ2 =200 = 1:125 + 3:38 + 0:125 + 0:08 + 0:02 = 4:91,
i=0
which when compared to the fifth percentile of the chi-square distribution with 4 degrees of
freedom, c24,:05 = 0:71, implies the simulated values (Equation 2.96) were indeed generated
from a multinomial distribution with probabilities given by Equation 2.97. There is not
enough evidence to reject the null hypothesis.
Thus, in the case of stochastic processes, the best way to determine the validity of the
multinomial model is to know the details of how the study was designed and conducted. It
is often the case that the details of the study are not available. The other important aspect of
a multinomial population is that the probability of a particular outcome is constant over all
cases. One other statistical way to check is to look for runs in the sequence, etc.
2.8 Computing
2.8.1 Introduction
This section introduces the computing algorithms and software that will be used for the
Bayesian analysis of problems encountered in agreement investigations. In the previous
sections of the chapter, direct methods (noniterative) of computing the characteristics of the
posterior distribution were demonstrated with some standard one sample and two sample
problems. An example of this is the posterior analysis of a normal population, where the
posterior distribution of the mean and variance is generated from its posterior distribution
by the t-distribution random number generator in Minitab. In addition to some direct
methods, iterative algorithms are briefly explained.
MCMC methods (an iterative procedure) of generating samples from the posterior dis-
tribution are introduced, where the Metropolis–Hasting algorithm and Gibbs sampling are
64 Bayesian Inference for Stochastic Processes
explained and illustrated with many examples. WinBUGS uses MCMC methods such as the
Metropolis–Hasting and Gibbs sampling techniques, and many examples of a Bayesian
analysis are given. An analysis consists of graphical displays of various plots of the pos-
terior density of the parameters, by portraying the posterior analysis with tables that list the
posterior mean, standard deviation, median, and lower and upper 2 ½ percentiles, and of
other graphics that monitor the convergence of the generated observations.
1. Draw the initial value q0 , where x(q0 jx) > 0, from some approximation to the target
density, say, p0 (qjx).
2. For t = 1, 2, …,
a. Sample a candidate point q∗ from a jumping distribution at time t, Jt (q∗ jqt ).
The jumping distribution is symmetric, that is, Jt (qa jqb ) = Jt (qb jqa ), ∀ qa , qb ,
and t.
Bayesian Analysis 65
Given the current value qt−1 , the Markov transition chain function is a mixture of the
jumping distribution Jt (qt jqt−1 ) and a point mass at qt = qt−1 . One must show that the
sequence generated is a Markov chain with a unique stationary density that converges to
the target distribution. This discussion of the Hasting algorithm is quite brief; thus, the
reader should refer to pages 323–325 of Gelman et al.16 for additional information.
q02 , q01 ; q12 , q11 ; q22 , q21 ; : ::; qk2 , qk1 (2.98)
is generated by first choosing the initial values q02 , q01 while the remaining are obtained
iteratively by alternating values from the two conditional distributions. Under quite
general conditions, for large enough k, the final two values qk2 , qk1 are samples from their
respective marginal distributions. To generate a random sample of size n from the joint
posterior distribution, generate the preceding Gibbs sequence n times. Having gen-
erated values from the marginal distributions with large k and n, the sample mean and
variance will converge to the corresponding mean and variance of the posterior distribution
of (q1 , q2 ).
Gibbs sampling is an example of a MCMC because the generated samples are drawn from
the limiting distribution of a 2 × 2 Markov chain. See Casella and George24 for a proof that
the generated values are indeed values from the appropriate marginal distributions. Of
course, Gibbs sequences can be generated from the joint distribution of three, four, and
more random variables.
The Gibbs sampling scheme is illustrated with the case of three random variables for the
common mean of two normal populations.
The Gibbs sampling approach can best be explained by illustrating the procedure using
two normal populations with a common mean q. Thus, let yij , j = 1,2, … , ni be a random
sample of size ni from a normal population for i = 1, 2.
The likelihood function for q, t1 , and t2 is
Lðq, t1 , t2 jdataÞ ∝
n
1 t n
2 t
t12 exp − 1 ðn1 − 1Þs21 + n1 ðq − y1 Þ2 t22 exp − 2 ðn2 − 1Þs22 + n2 ðq − y2 Þ2 ,
2 2
n1 n2
X X
where, q ∈ ℜ, t1 > 0, t2 > 0, s21 = (y1j − y1 )2 =(n1 − 1), and s22 = (y2j − y2 )2 =(n2 − 1).
j=1 j=1
The prior distribution for parameters q, t1 , and t2 is assumed to be a vague prior defined as
1 1
gðq, t1 , t2 Þ ∝ , ti > 0:
t1 t2
Then, combining the preceding equations gives the posterior density of the parameters as
Y2 ni −1
t
Pðq, t1 , t2 jdataÞ ∝ ti 2 exp − i ðni − 1Þs2i + ni ðq − yi Þ2 :
i=1
2
n1 t1 y1 + n2 t2 y2
qjt1 , t2 ∼ N , ðn1 t1 + n2 t2 Þ−1 : (2.100)
n1 t1 + n2 t2
n1 y1 + n2 y2
Given the starting values t(0) (0) (0) (0) 2 (0) 2 (0)
1 , t2 , and q , where t1 = 1=s1 , t2 = 1=s2 , and q = n1 + n2 ,
draw q(1) from the normal conditional distribution of q, given t1 = t1 and t2 = t(0)
(0)
2 . Then
draw t(1)
1 from the conditional gamma distribution (43), given q = q (1)
. And lastly, draw t(1)
2
from the conditional gamma distribution of t2 given q = q(1) . Then generate
t(2)
1 ∼ t1 =q = q
(2)
t(2)
2 ∼ t2 =q = q
(2)
Continue this process until there are t iterations (q(t) , t(t) (t) (t)
1 , t2 ). For large t, q would be one
sample from the marginal distribution of q, t1 from the marginal distribution of t1 , and t(t)
(t)
2
from the marginal distribution of t2 .
Bayesian Analysis 67
j=∞
X
EðqjdataÞ = qtj =m
j=1
m h
X i2
ðm − 1Þ−1
qtj − q
j=1
[Link] Example
The example is from page 481 of Box and Tiao.10 It is referred to as the weighted mean problem.
It has two sets of normally distributed independent samples with a common mean and
different variances. Samples from the posterior distributions were generated from Gibbs
sequences. The final value of each sequence was used to approximate the marginal pos-
terior distribution of the parameters q, t1 , tk . All Gibbs sequences were generated holding
the value of t equal to 50. Each example has the results of the parameters using four different
Gibbs sampler sizes, where the sample size m is equal to 250, 500, 750, and 1500.
The weighted mean problem has two sets of normally distributed independent obser-
vations with a common mean and different variances. The estimated values of m deter-
mined by the Gibbs sampling method are reported in Table 2.2. The mean value of the
posterior distribution of q generated from the 250 Gibbs sequences is 108.42 with 0.07 as the
standard error of the mean. The mean value of q generated from 500 and 750 Gibbs
sequences have the same value of 108.31, and the standard errors of the mean equal 0.04
and 0.03, respectively. The mean value of q generated from 1500 Gibbs sequences is 108.36
and a standard error of the mean of 0.02. Box and Tiao determined the posterior distribution
of q using the t-distribution as an approximation to the target density. They estimated the
value of q to be 108.43. This is close to the value generated using the Gibbs sampler method.
The exact posterior distribution of q is the poly-t-distribution. The effect of m appears to be
minimal, indicating that 500–750 iterations of the Gibbs sequence are sufficient.
68 Bayesian Inference for Stochastic Processes
TABLE 2.2
Results from Gibbs Sampler for q Box and Tiao’s “The Weighted Mean
Problem”
95% Credible Region
m Mean STD SEM Lower Upper
2.10 Exercises
1. For the Beta density (Equation 2.8) with parameters a and b, show that the mean
is ½a=(a + b) and the variance is ½ab=(a + b)2 (a + b + 1).
Bayesian Analysis 69
2. From Equation 2.14, show the following. If the normal distribution is parame-
terized with μ and the precision t = 1=s2 , the conjugate distribution is as follows:
(a) the conditional distribution of μ given t is normal with mean x and precision nt
and (b) the marginal distribution of t is gamma with parameters (n − 1)/2 and
X
i=n
(xi − x)2 =2 = (n − 1)S2 =2, where S2 is the sample variance.
i=1
3. Verify Table 2.1, which reports the Bayesian analysis for the parameters of a
normal population.
4. Verify the following statement:
To generate values from the t(n − 1, x, n=S2 ) distribution, generate values
from Student’s t-distribution with n − 1 degrees of freedom and multiply
pffiffiffi
each by S= n and then add x to each.
5. Verify Equation 2.82, the predictive density of a future observations Z from a
normal population with both parameters unknown.
6. Suppose x1 , x2 , :::, xn are independent and that xi ∼ Gamma(ai , b) and show that
yi = xi =(x1 + x2 + ::: + xn ) jointly have a Dirichlet distribution with parameter (a1 ,
a2 , :::, an ). Describe how this can be used to generate samples from the Dirichlet
distribution.
7. Suppose (X1 , X2 , :::, Xk ) is multinomial with parameters n and (q1 , q2 , :::, qk ), where
Xi=k X
i=k
Xi = n, 0 < qi < 1, and qi = 1. Show that E(Xi ) = nqi , Var(Xi ) = nqi (1 − qi ),
i=1 i=1
and cov(Xi , Xj ) = −nqi qj . What is the marginal distribution of qi ?
8. Suppose (q1 , q2 , :::, qk ) is Dirichlet with parameters (a1 , a2 , :::, ak ), where ai > 0,
Xi=k
qi > 0, and qi = 1. Find the mean and variance of qi and covariance between
i=1
qi and qj , i ≠ j :
9. Show that the Dirichlet family is conjugate to the multinomial family.
10. Suppose (q1 , q2 , :::, qk ) is Dirichlet with parameters (a1 , a2 , :::, ak ). Show that the
marginal distribution of qi is beta and give the parameters of the beta. What is
the conditional distribution of qi given qj ?
11. For the exponential density
12. Refer to the R Code given by R Code 2.1. Using the function [Link], generate 100
observations from a two-state Markov chain with probability transition matrix
!
:5, :5
P= :
:5, :5
What are the number of transitions from 1 to1? From 1 to 2? From 2 to 1? And
from 2 to 2? Is this Markov chain irreducible?
13. Refer to Section 2.3.2 and define a Wiener process with parameter s2 .
14. Refer to Section 2.4.2. Using R Code 2.2, generate 50 observations from a
Brownian motion process with parameter s2 = 1.
15. Refer to Section 2.4.3. Based on WinBUGS Code 2.1, generate 100 observations
from an exponential distribution with mean 2.
16. Refer to Section 2.5.2 on testing hypotheses. Let q be the parameter of a Bernoulli
distribution and consider a test of the null hypothesis H0 : q = :5 versus the alter-
native H1 : q ≠ :5. Assume that the null hypothesis has prior probability π0 = :5
and assume that under the alternative, the prior density is Beta (3,3) over the
interval [0,1]. If the sample consists of
x = (1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, ),
compute the posterior probability p0 of the null hypothesis. Refer to Equation 2.48.
17. Verify the predictive probability mass function (Equation 2.77) for the binomial.
18. Verify the predictive distribution (Equation 2.89) of m future observations from a
Brownian motion process.
19. Based on Equation 2.89 and WinBUGS Code 2.2, generate 100 observations from
the predictive distribution (Equation 2.89) and compare to the 100 predictive
values labeled by Equation 2.90.
20. Based on the multinomial mass function (Equation 2.91) and the R Code
N<-1000
Prob <- c(.2,.2,.2,.2,.2)
rmultinom(1,n,prob),
References
1. Bayes, T. 1764. An essay towards solving a problem in the doctrine of chances, Philosophical
Transactions of the Royal Society London 53:370.
2. Laplace, P. S. 1778. Memorie des les probabilities. Memories de l’Academie des sciences de Paris,
p. 227.
3. Stigler, M. 1986. The History of Statistics: The Measurement of Uncertainty before 1900. Cambridge,
MA: Belknap Press of Harvard University Press.
4. Hald, A. 1990. A History of Mathematical Statistics from 1750–1930. London: Wiley Interscience.
5. Lhoste, E. 1923. Le calcul des probabilities appliqué a l’artillerie, lois de probabilite a prior. Revu
d’artillerie, Mai, p. 405.
6. Jeffreys, H. 1939. An Introduction to Probability. Oxford: Clarendon Press.
7. Savage, L. J. 1954. The Foundation of Statistics. New York: John Wiley & Sons.
8. Lindley, D. V. 1965. Introduction to Probability and Statistics from a Bayesian Viewpoint, Volumes I and
II. Cambridge, UK: Cambridge University Press.
9. Broemeling, L. D., and Broemeling, A. L. 2003. Studies in the history of probability and statistics
XLVIII: The Bayesian contributions of Ernest Lhoste, Biometrika 90(3):728–731.
10. Box, G. E. P., and Tiao, G. C. 1973. Bayesian Inference in Statistical Analysis. Reading, MA: Addison–
Wesley.
11. Zellner, A. 1971. An Introduction to Bayesian Inference in Econometrics. New York: JohnWiley &
Sons.
12. Broemeling, L. D. 1984. The Bayesian Analysis of Linear Models. New York: Marcel Dekker.
13. Hald, A. A. 1998. History of Mathematical Statistics before 1750. London: Wiley Interscience.
14. Dale, A. I. 1991. A History of Inverse Probability from Thomas Bayes to Karl Pearson. Berlin: Springer-
Verlag.
15. Leonard, T., and Hsu, J. S. J. 1999. Bayesian methods. An Analysis for Statisticians and Interdisci-
plinary Researchers. Cambridge, UK: Cambridge University Press.
16. Gelman, A., Carlin, J. B., Stern, H. S., and Rubin, D. B. 1997. Bayesian Data Analysis, New York:
Chapman and Hall/CRC Press.
17. Congdon, P. 2001. Bayesian Statistical Modeling. London: John Wiley & Sons.
18. Congdon, P. 2003. Applied Bayesian Modeling. New York: John Wiley & Sons.
19. Congdon, P. 2005. Bayesian Models for Categorical Data. New York: John Wiley & Sons.
20. Carlin, B. P., and Louis, T. A. 1996. Bayes and Empirical Bayes for Data Analysis. New York:
Chapman and Hall/CRC Press.
21. Gilks, W. R., Richardson, S., and Spiegelhalter, D. J. 1996. Markov Chain Monte Carlo in Practice.
Boca Raton, FL: Chapman and Hall/CRC Press.
22. Lehmann, E. L. 1959. Testing Statistical Hypotheses. New York: John Wiley & Sons.
23. Lee, P. M. 1997. Bayesian Statistics: An Introduction, Second Edition: London: Edward Arnolds.
24. Casella, G., and George, E. I. 2004. Explaining the Gibbs sampler, The American Statistician
46:167–174.
25. Gregurich, M. A., and Broemeling, L. D. 1997. A Bayesian analysis for estimating the common
mean of independent normal populations using the Gibbs sampler, Communications in Statistics 26
(1):35–51.
26. Ntzoufras, I. 2009. Bayesian Modeling Using WinBUGS. Hoboken, NJ: John Wiley & Sons.
27. Parzen, E. 1962. Stochastic Processes. San Francisco: Holden Day Wilson.
28. Karlin, S., and Taylor, H. M. 1975. A First Course in Stochastic Processes, Second Edition. San
Francisco: Academic Press.
29. Allen, L. J. S. 2011. An Introduction to Stochastic Processes with Applications to Biology, Second Edition.
Boca Raton, FL: CRC Press.
30. Insua, D. R., Ruggeri, F., and Wiper, M. P. 2012. Bayesian Analysis of Stochastic Process Models. New
York: John Wiley & Sons.
[Link]
3
Introduction to Stochastic Processes
3.1 Introduction
The first part of this chapter will review the basic terminology and notation involved with
the presentation of materials about stochastic processes. This is to be followed by the def-
inition of a stochastic process and the various types of stochastic processes. Next, the focus
will be on defining the various types of states of a stochastic process. Lastly, several
examples of discrete and continuous Markov processes will be discussed, while the last
section will be devoted to the explanation of several types of normal processes. Our main
emphasis is on the basic foundation of studying stochastic processes, which is necessary for
implementing Bayesian inference. The Bayesian analysis of such processes will continue
with Chapter 4, but for now, the main objective is to introduce the reader to the foundation
of stochastic processes.
73
74 Bayesian Inference for Stochastic Processes
Also introduced in Chapter 1 were the well-known discrete and continuous distributions.
With regard to the continuous type, the normal exponential, gamma, uniform, and beta
were introduced, while for the discrete type, the binomial, Poisson, negative binomial, and
geometric were defined. With regard to continuous multivariate distributions, the multi-
variate normal, the multivariate t, and Dirichlet were defined, and with respect to the
multivariate discrete type of distributions, the multinomial and hypergeometric were
explained. Of course, such basic concepts of probability and the distributions named earlier
play an important role in the definition of stochastic processes.
where for each t, X(t) is a random variable assuming real values. If the index set T is the set
T = f0, 1, 2, :::g, then the stochastic process in Equation 3.2 represents values like those of a
random walk. Of course, in order to investigate the process, what is required is the joint
probability distribution of the set of random variables
for all n = (1, 2, 3, …) and all time points 0 ≤ t1 < t2 <, :::, < tn .
The values of X(t) can be multidimensional, that is, one, two, or n dimensional. For
example, suppose X(t) represents the outcome of the tth toss of a die with possible outcomes
f1, 2, 3, 4, 5, 6g, then a possible realization of the process for the first 10 time points (tosses)
might be 4, 6, 1, 8, 3, 2, 1, 6, 6, 4; that is, on the first toss, the outcome was a 4, and on the
tenth toss, the outcome was a 4. If the die is fair,
for i = 1, 2, 3, 4, 5, 6, and if the tosses are independent, one would know the joint distribution
of the family X(1), X(2), :::, X(10). Since the random variables of the process are indepen-
dent, this is a very simple case of a stochastic process. Our interest will be mostly centered
on the cases where the random variables of the process are correlated. The possible out-
comes of this process are called the states of the process.
We will also study processes with index set T = ½0, ∞), and for now, be content with a brief
introduction to the basic concepts of stochastic processes using two important examples.
Introduction to Stochastic Processes 75
6.00
5.00
4.00
3.00
X
2.00
1.00
0.00
FIGURE 3.1
Realization of a Poisson process.
76 Bayesian Inference for Stochastic Processes
Let Pm (t) = Pr½N(t) = m be the probability that m events occur over an interval from 0 to t,
where m = 0, 1, 2, …; then from the second assumption,
∞
X
Pm ðhÞ = oðhÞ, (3.6)
m=2
which implies
where p(h) satisfies Equation 3.5. Now let us set up the difference quotient
Then, taking the limit of Equation 3.8 as h ! 0 gives the differential equation
with solution
and taking the limit of Equation 3.10 as h ! 0 results in the differential equation
for m = 0, 1, 2, …, the solution (using the initial conditions Pm (0) = 0, m = 1, 2, :::) of which is
Thus, the distribution of the random variable N(t) is Poisson with parameter at, and the
mean number of events occurring over the interval 0 to t is at. The Poisson process has many
interesting features, including the distribution of interarrival times between events and the
waiting time until the nth event occurs. The Bayesian analysis of the Poisson process
including the analysis of the waiting times (which have a gamma X(t) distribution) was
introduced in Chapter 2.
Introduction to Stochastic Processes 77
1. Let n be a positive integer and let the time points ti , i = 1, 2, :::, n, be ordered as
t1 < t2 < ::: < tn ; then the increments X(ti ) − X(ti−1 ), i = 1, 2, :::, n, are independent,
and the process is characterized as having independent increments.
2. The distribution of X(t) − X(s) depends only on the length t − s and not on s, and
the distribution of X(t) − X(s) is normal with mean of 0 and variance of s2 (t − s).
Thus, assuming X(0) = 0, the first two moments of the process are E½X(t) = 0 and
Var½X(t) = s2 t.
The Bayesian analysis of the Wiener process was performed in Chapter 2 and will be
extended in Chapter 4. Both the Poisson and Wiener processes are examples of Markov
processes.
stochastic process. In the former case, the process is observed over a finite set of times, while
in the latter, the process is observed hypothetically, over an infinitely countable number of
times. Lastly, when T = ½0, ∞), the process is called a continuous-time process. The Poisson
process and the Wiener process are examples of continuous-time processes, where the
Poisson state space is S = f0, 1, 2, :::g and infinitely countable, but for the latter Wiener
process, the state space is S = ½0, ∞), the set of nonnegative reals. Of course, index set T can
be multidimensional, such as the set of all ordered pairs in the plane.
E½XðtÞ = m0 + m1 t, (3.14)
where
Var½Xð0Þ = E ðXð0Þ − m0 Þ2
and
Var½Xð1Þ = E ðXð1Þ − m1 Þ2 − Var½Xð0Þ:
Introduction to Stochastic Processes 79
It is left as an exercise to verify Equation 3.14. See Karlin and Taylor1 for additional
information on how to verify Equation 3.14.
[Link] Martingales
Consider a real-valued stochastic process fX(t) : t ∈ Tg, where T is discrete or continuous,
and suppose that E½jX(t)j < ∞, that is, the moments of each member of the process exits,
then the process is a martingale if for all times such that t1 < t2 < ::: < tn < tn+1 and n is a
positive integer,
for all time points and choices of the conditioning values c1 , c2 , :::, cn . There is an interesting
gambling interpretation of martingales in that the average amount a player will have at
time tn+1 , given the player has an amount cn at time tn , is cn regardless of their fortune
(holdings) at times previous to tn . Another example of a martingale can be expressed as
sums of independent random variables Y(i), namely,
for all choices of times points t1 < t2 < ::: < tn < t and all states x1 < x2 < ::: < xn .
What is the interpretation of such a process? A Markov process has the property that
given the values of previous random variables X(ti ), i = 1, 2, :::, n, the value of X(t) depends
on only the most recent value, namely, that of X(tn ).
Consider the transition probability function
which is a quite useful subject in the study of Markov chains. Note that the Markov prop-
erty can be represented as
where the event A = ft : t ≤ bg, the set of all states that do not exceed b. Note that if the states
of a Markov process can be finite or countable, the process is called a Markov chain, and this
is the subject of Chapter 4.
80 Bayesian Inference for Stochastic Processes
Xðt1 + hÞ, Xðt2 + hÞ, :::, Xðtn + hÞ e Xðt1 Þ, Xðt2 Þ, ::, Xðtn Þ (3.21)
for all choices of n, h > 0, and ordered time points t1 , t2 , :::, tn of the index set T. Thus, for
example, the mean of X(t) is the same for ∀ t ∈ T. Note that the distribution of the set of n
random variables on the left of Equation 3.21 is the same as the set of n random variables on
the right-hand side.
The second case of stationarity, called weak stationarity, assumes that the second
moments of each member of the process exist and that Cov½X(t), X(t + h) depends on h and
only h for all t ∈ T. If a process is strictly stationary and has finite second moments, then the
process is covariance stationary; however, the converse is not true. The preceding
description of stationary processes is taken from Karlin and Taylor1 and is similar to the
description on pages 9–12 of Cox and Miller3 and pages 69–72 of Parzen.4 It may appear
that stationarity is too strong a property to impose on a stochastic process, but it is an
appropriate assumption for many applications, including communication theory, signal
processing, astronomy, biology, and economics. Such applications will be presented in the
following two sections of this chapter.
Recall that a Markov process is said to have stationary transition probabilities if P(x, s; t, A)
as defined by Equation 3.10 is only a function of t − s, but remember that P(x, s; t, A) is a
conditional distribution, given the present state. It can be shown that a Markov process which
has stationary transition probabilities is not necessarily a strictly stationary process. The
Poisson process and the Wiener process are not stationary. This is obvious for the Poisson
process fN(T), t ≥ 0g with parameter r > 0, because the mean value E½N(t) = rt increases
with time. It is left as an exercise to show that the Wiener process is not strictly stationary.
That is, W(n) is the time to the nth failure or, in the context of a survival study, the time of
the nth death. Such processes are relevant to medical studies, to life table analysis in
actuarial work, and to experiments in reliability. Thus, a renewal process is a counting
process that keeps a record of the number of renewals N(t) over time, and it takes on the
value n according to
That is, the nth failure occurs at time t if and only if the waiting time to failure n does not
exceed time t and is less than the waiting time for event n + 1. Thus, there are three processes
associated with a renewal process: (1) the failure times T(n), (2) the waiting times W(n), and
the counting process N(t). Of course, the Poisson process is a renewal process with expo-
nentially distributed interarrival times and gamma-distributed waiting times.
The Bayesian analysis of the Poisson process was introduced in Chapter 2, and renewal
processes will be studied extensively in Chapter 4.
Poisson point processes occur in a large number of scientific fields. For example in
astronomy, where N(A) counts the number of galaxies in a region of space A, and in
ecology, where N(A) represents the number of plant types in the area A. For additional
information about point processes, see the excellent monograph by Cox and Isham.5 These
authors give several examples of point processes, including emissions from a radioactive
source, electrical energy in a nerve fiber, the time of accidents in coal mines in Wales, and
the arrival times of customers in a queue. These examples will be employed to illustrate
Bayesian inferences for stochastic processes.
XðtÞ = 1, U = t,
(3.24)
XðtÞ = 0, U ≠ t,
82 Bayesian Inference for Stochastic Processes
Pr½X(t) ≤ 1=2 = 0
Pr½YðtÞ ≤ 1=2 = 1, 0 ≤ t ≤ 1:
This seeming paradox is due to the continuous nature of the index set, and for further
information about resolving this issue, refer to pages 32 and 33 of Karlin and Taylor.1
If the states i and j are accessible from each other, the states are said to communicate, and
this is designated by i ↔ j. On the other hand, if these two states do not communicate, then
either
Pnij = 0, ∀ n ≥ 0, (3.27)
Pnji = 0, ∀ n ≥ 0, (3.28)
or both Equations 3.27 and 3.28 are true. The idea of communicating classes is an equiva-
lence relation namely,
Introduction to Stochastic Processes 83
1. i ↔ i,
2. If i ↔ j ⇒ j ↔ i (3.29)
3. If i ↔ j and j ↔ k ⇒ i ↔ k
The third relation is called transitivity and is demonstrated as follows: since i ↔ j and
there exist times m and n such that Pm ij > 0,
X
r=∞
Pikm+n = Pm n m n
ir Prk ≥ Pij Pjk > 0 (3.30)
r=0
Of course, it can be shown that there exists a time l such that Plki > 0; then using the same
argument as Equation 3.30, transitivity is declared. Since communication ↔ induces an
equivalence class on the states of a Markov chain, the states of a chain can be partitioned
into a set of communicating states. If all the states consist of one communication class, the
chain is said to be irreducible, a very important concept for us to study. Let C1 and C2 be two
communicating classes, and let i and j belong to the two, respectively, that is, i ∈ C1 and
j ∈ C2 ; then it is possible that i ! j (that is, j is accessible from i), but if that is the case, then it
cannot be true that j ! i (that is, i is accessible from j). As an example, consider the 5 × 5
transition matrix
!
P1 , 0
P= , (3.31)
0, P2
where
!
:5, :5
P1 = (3.32)
:25, :75
and
0 1
0, 1, 0
B C
P2 = B C
@ :5, 0, :5 A: (3.33)
0, 1, 0
Thus, it can be seen that the two states of P1 do not communicate with the three states of
P2 , and vice versa, and each of the two classes can be analyzed by itself.
Thus, if the state of X(0) is in the first class, the state of the chain remains in the first class.
In order to perform a Bayesian analysis, it is important to know the communicating
classes of a chain. Also, in order to generate realizations from a Markov chain, it is
important to know the communicating classes. For example, for the preceding chain
(Equation 3.31), one would generate observations from P1 and P2 separately, then it would
be possible to find Bayesian inferences for all the transition probabilities.
The communicating classes of a chain can be quite complex. Consider the transition
matrix of a random walk with integers for the state space, S = f0, 1, 2, ::::, a − 1, ag,
84 Bayesian Inference for Stochastic Processes
0 1
1, 0, 0, 0, ::::::0, 0, 0
B C
B q, 0, p, 0, :::::0, 0, 0 C
B C
B C
B 0, q, 0, p, , , , , 0, 0, 0 C
B C
B C
P=B
B:
C:
C (3.34)
B C
B: C
B C
B C
B 0, :::::::::::::::q, 0, p C
@ A
0, :::::::::::::::::0, 0, 1
If the initial state is 0, the chain remains in 0, that is, 0 is an absorbing state, while if
the initial state is 1, the process moves one unit to the right with probability p or one unit to
the left with probability q and p + q = 1. There are three communicating classes: C1 = f0g,
C2 = f1, 2, …, a − 1g, and C3 = fag, where a is a positive integer. This chain is similar to the
gambler’s ruin problem, to be presented in Section 3.6. The first and third classes can be
reached from the second, but it is impossible to return to the second, from either the first or
third!
0 1
0, 1, 0, 0, ::::, 0
B C
B 0, 0, 1, 0, :::::, 0 C
B C
B C
B: C
B C
P=B C; (3.35)
B: C
B C
B C
B 0, 0, :::::::::::, 1 C
@ A
1, 0, 0, ::::::::, 0
1. If the states i and j communicate, then they have the same period or
i ↔ j ⇒ d(i) = d(j).
2. Suppose that the period of i is d(i), then there exists an integer N, depending on i
such that for all n ≥ N, Pnd(i)
ii > 0.
Introduction to Stochastic Processes 85
X
k=n
Pnii = fiik Piin−k : (3.37)
k=0
That is to say, the probability that i will occur at time n (given initially that the process is in
state i) is the probability that state i will occur first at time k, multiplied by the probability
that the process will return to state i after n − k time units. Equation 3.37 follows from the
law of total probability. It thus follows that
X
k=n
Pnij = fijk Pjjn−k , (3.38)
k=0
where the first transition from state i to state j occurs at time n and is portrayed by
X
n=∞
fiin = 1: (3.40)
n=1
That is, a state is recurrent if starting from state i, the probability of returning to state i in a
finite time interval is 1, and additional information about recurrence is to follow.
For further information about recurrence, refer to pages 62–67 of Karlin and Taylor.1 This
information includes using probability-generating functions and ideas about Abel’s type
convergence to prove additional assertions about recurrent states, for example,
X
n=∞
Pnii = ∞: (3.41)
n=1
X
n=∞
3. The expected number of returns to a given state i, given X(0) = i, is given by Pnii .
n=0
Note that 1 implies that a state is recurrent if and only if it occurs infinitely often, while 3
implies that a state is recurrent if and only if the expected number of returns to that state is
infinite. Also, it is easy to show that the assertion in Equation 3.41 implies Equation 3.40. If a
X
n=∞ X
n=∞
state i is not recurrent, it is transient, that is, fiin < 1 or equivalently pnii < ∞. In
n=1 n=1
addition, if a state i is recurrent and the mean recurrence time is positive, the state is called
positive recurrent; however, if the mean recurrence time is 0, the state is called null
recurrent.
A simple example of a recurrent Markov chain is the one-dimensional random walk,
where at each transition, the probability of moving to the right by one unit is p and that of
2n n
moving to the left by one unit is 1 − p; thus, P00
2n+1
= 0, n = 0, 1, 2, :::, and P2n
00 = p (1 − p)n ,
n
and the latter is approximated by using the Stirling formula for factorials, namely,
pffiffiffiffiffi
n ! ≃ nn+1=2 e−n 2π: (3.42)
Thus,
n 2n pffiffiffiffiffiffi n pffiffiffiffiffiffi
P2n
00 ≈ ðpð1 − pÞÞ 2 = nπ = ð4pð1 − pÞÞ = πn, (3.43)
X
n=∞
and if p = 1=2, it can be thus shown that P2n
00 = ∞. The conclusion is that state 0 is
n=0
recurrent. If p ≠ 1=2, it will be left to the student to show that 0 is not recurrent.
X
k=∞
Viin = fiik ViiN−1 = ViiN−1 fii∗ , (3.44)
k=1
where
X
k=∞
fii∗ = fiik : (3.45)
k=1
Thus, since lim ViiN = Vii as N ! ∞, therefore Vii is 1 or 0 if and only if fii∗ = 1 or <1, that is,
if and only if state i is recurrent or transient. Thus, if a state is recurrent, that state will occur
Introduction to Stochastic Processes 87
infinitely often with a probability of 1, but on the other hand, if the state is transient, the
probability is less than 1 that the state will be occupied infinitely often. Also, note that if i
and j communicate and the class is recurrent, then
X
n=∞
fij∗ = fijn = 1: (3.46)
n=1
Remember that in a finite-state Markov chain, not all states can be transient; that is, at
least one state must be recurrent. Consider the example on pages 146 and 147 of Ross6 of a
Markov chain with states 0, 1, 2, and 3 and transition probability matrix
0 1
0, 0, :5, :5
B C
B 1, 0, 0, 0 C
B C
P=B C: (3.47)
B 0, 1, 0, 0 C
@ A
0, 1, 0, 0
where there are three classes f0, 1g, f2, 3g, and f4g, with the first two recurrent but the third
transient.
In the long run, what are the possible states of a Markov chain, and how do they depend
on the initial state? Such problems come under the subject of limiting probabilities. The
following shows how to find the limiting probabilities of certain types of Markov processes:
X
i¼∞
πj = πi Pij , j ≥ 0, (3.49)
i¼0
j=∞
X
and satisfying the constraint πj = 1.
j=0
88 Bayesian Inference for Stochastic Processes
This implies that the long-run proportion of times the process is in state j is the limiting
probability πj given by Equation 3.49.
An interesting example on pages 154 and 155 of Ross6 is a problem of interest to soci-
ologists that involves determining the proportion of society that has an upper class-type or
lower class-type occupation. It is assumed that the transitions between the three classes,
lower, middle, and upper classes, follow a Markov chain with matrix
0 1
:45, :45, :07
B C
P=B C
@ :05, :70, :25 A: (3.50)
:01, :50, :49
For example, the child of a middle-class worker has a chance of .7 of remaining middle
class and a 25% chance of being upper class. What are the limiting probabilities for this
example? From Equation 3.49, the three equations are
and subject to the constraint πo + π1 + π2 = 1; it can be shown that the solution is πo = :07,
π1 = :62, π2 = :31. Thus, in the long run, the investigated population has 7% of the workers
in lower class, 62% in the middle class, and 31% in the upper class. Of course, these limiting
probabilities are just estimates because they are based on the estimated transition matrix in
Equation 3.50, which was most likely determined by surveys conducted by the sociologists.
This example will be studied in Chapter 4, where Bayesian inferences for the limiting
probabilities will be developed.
An interesting question left to the student is: is it possible to find limiting probabilities for
Markov chains that are not irreducibly positive recurrent?
the future state of the chain is in state j, given that at the previous time, the state of the
process is in state i, or
where i and j belong to state space S = f0, 1, 2, :::g and time n is a nonnegative integer. Note
the dependence of these transition probabilities not only on the initial and final states but
also on the time n of the transition. If this one-step transition probability is independent of
time variable, the Markov chain is said to have stationary transition probabilities, and this
chapter will mainly emphasize such processes. In this case, Pijn,n+1 does not depend on n and
the one-step transition probability is written as Pij .
Note the probability of going from state i to j is the same for all times n = 0, 1, 2, … . The
transition probability matrix is shown as
0 1
P00 , P01 , P02 , :::::
B C
B P10 , P11 , P12 , ::::: C
B C
B C
B C
B C
P=B C, (3.53)
B Pi0 , Pi1 , Pi2 , ::::: C
B C
B C
B C
@ A
where the first row is the conditional probability of the states 0, 1, 2, …, given that the initial
state is 0, while the second row is the same, but when the initial state of the process is 1, etc.
Thus, each row is a conditional probability; hence, for all i = 0, 1, 2, …,
X
Pij = 1 (3.54)
j≥0
Of course, the number of states can be finite, in which case the transition matrix P is
suitably modified.
The chain is completely specified when one knows the transition probability matrix P and
the probabilities of the initial state X(0). Also, for the process to be completely determined,
one must be able to determine
Can this joint probability be computed using only the one-step transition probabilities?
Consider Equation 3.55 expressed as
and the joint distribution can be expressed as a product of one-step transition probabilities,
as was to be shown.
Pr½h = i = ai , (3.58)
X
i=∞
where ai = 1 and ai ≥ 0, i = 1, 2, :::.
i=1
Consider the process X(i) = hi ; then the one-step transition probability matrix is
0 1
a0 , a1 , a2 , a3 , ::
B C
B a0 , a1 , a2 , a3 , :: C
B C
B C
B a0 , a1 , a2 , a3 , :: C
B C
P=B C, (3.59)
B: C
B C
B C
B: C
@ A
where each row is the same probability distribution, namely, that of the random variable h.
This is a trivial example of a Markov chain since X(i) is independent of X(i + 1). Another
Markov process defined in terms of the random variables h is described in the following
section.
Xi=n
Let X(n) = hi , n = 1,2,…; then this process is Markov with one-step transition
i=1
probability
One would have to modify this matrix if the index set is the set of all integers or if the
index set is f0, 1, 2, :::, mg.
where
d ðxÞ = 1, x = 1, (3.63)
and d(0) = 0.
Equation 3.62 is interpreted as follows: The number of persons waiting for service when
person n + 1 leaves depends on whether that person was in line when the nth customer depar-
ted service. When d(X(n)) = 0, X(n + 1) = (n + 1); otherwise, X(n + 1) = W(n + 1) + X(n) − 1.
Since W(n + 1) is independent of X(1), X(2), :::, X(n), the implication is that given the value
of X(n), the values of the previous n − 1 values of the process are not involved in deter-
mining the conditional distribution of X(n + 1). This chain is an example of an embedded
chain in that it corresponds to the stochastic process fN(t), t ≥ 0g, where N(t) is the number
of customers in line at time t and where the times ftn g are the corresponding arrival times,
and the embedded chain can be written as X(n) = N(tn ). See pages 190 and 191 of Parzen4
for additional information about this queuing example.
state space {0, 1, 2, …} with boundary at 0. In such a model, the states are positions which
are denoted by X(n), where n is time. Let p be the probability of moving one unit to the right
and 1 − p be the probability of one unit to the left; thus, the one-step transition probability is
Pr½X(n + 1) = jjX(n) = i = p, j = i + 1,
(3.64)
= 1 − p, j=i−1
P00 = 1 − p (3.65)
and
P01 = p, (3.66)
P12 = p,
P11 = sq,
p10 = ð1 − sÞq, (3.67)
p + q = 1, P00 = 1,
0 < p, s<1
where is 0 < p < 1 and where i = 1, 2, :::, N − 1. The two boundaries 0 and N are absorbing,
that is, P00 = 1 and PNN = 1.
Introduction to Stochastic Processes 93
and q = 1 − p. There are three communicating classes f0g, f1, 2, :::, N − 1g, and fNg; that is,
0 communicates only with 0, N communicates only with N, and the remaining N − 1 states
communicate only with each other, but not with 0 or N.
There are many interesting aspects of the dynamics of the gambler’s ruin problem,
including (1) the probability the gambler either wins or loses all capital and (2) the average
length of time in order to win or lose all capital. Suppose the gambler has to begin with total
capital k; then the average duration of the game is
where μko is the average duration of the game until ruin, starting with capital k, and μkN is
the average duration of the game until the gambler wins.
Let
be the probability of the gambler’s loss of all capital given that initially, the capital of the
gambler is k. In a similar fashion, let
be the probability the gambler wins the game, given that they have initial capital k. Recall
that if the state is 0, the gambler loses, but if the state is N, the gambler wins.
Note that the sequence akn + bkn n = 0, 1, 2, ::: is the probability of absorption at trial n;
hence,
X
n=∞
ðakn + bkn Þ = 1 (3.73)
n=0
for 1 ≤ k ≤ N − 1.
The generating function technique is used to find the average duration until the gambler’s
worth is 0 or if the gambler wins. For further information about the generating function
technique, see pages 6–9 of Bailey.7
94 Bayesian Inference for Stochastic Processes
Consider the two functions for the sequences akn and bkn , n = 0, 1, 2, :::, namely,
X
n=∞
Ak ðtÞ = akn tn (3.74)
n=0
and
X
n=∞
B k ðt Þ = bkn tn , (3.75)
n=0
X
n=∞
Ak ðtÞ + Bk ðtÞ = ðakn + bkn Þtn (3.76)
n=0
is the probability-generating function for the sequence akn + bkn , n = 0, 1, 2, :::. Note that the
nth term of this sequence is the probability of absorption at time n.
Let
a k = A k ð1 Þ (3.77)
and
bk = Bk ð1Þ; (3.78)
then ak is the probability of the gambler’s ruin with beginning capital k, while bk is the
probability of winning all the pot, beginning with k as the capital.
Finally, let
X
n=∞
zk = A01 ðtÞ + A02 ðtÞ = nðakn + bkN Þ (3.79)
n=0
be the mean duration of the games beginning with capital k, and let Tk be the random
variable denoting the mean time to absorption; then obviously
zk = EðTk Þ (3.80)
for 1 ≤ k ≤ N − 1. The primes in Equation 3.79 denote the derivatives with respect to t.
The main concern at this point is to determine the probability of absorption, and two
approaches will be presented. The first is via a linear difference equation that relates ak−1 ,
ak , and ak+1 , and the second is a numerical approach based on the transition matrix.
Initially, consider the difference equation for the probability of ruin when the gambler has
capital k; they either win or lose the next game with probabilities p and q, respectively.
When the gambler wins the next game, the capital is k + 1 with probability ak+1 , while if they
Introduction to Stochastic Processes 95
lose, the resulting capital is k − 1 with probability ak−1 ; hence, it follows that the fundamental
difference equation is
In order to solve this equation, the boundary conditions are a0 = 1 and aN = 0, thus if the
capital is zero, the probability of ruin is 1, but if the gambler’s capital is N, the probability of
ruin is 0.
The method of characteristic equations is used to solve the difference equation in
Equation 3.81, thus, let
ak = g k ≠ 0 (3.82)
and substitute this value into Equation 3.81, which results in the characteristic equation
pg 2 − g + q = 0, (3.83)
Two cases are considered: (1) p ≠ q and (2) p = q = 1=2. In the first case, the roots of
Equation 3.83 are g = 1 and g = q=p, and the general solution to the difference equation is
ak = d1 + d2 ðq=pÞk , (3.85)
where d1 and d2 are determined by imposing the boundary conditions; then it can be shown
that the general solution is
h i
ak = ðq=pÞN − ðq=pÞk = ðq=pÞN − 1 , p ≠ q: (3.86)
It also follows that the general solution for the probability of winning with capital k is
h i
bk = ðq=pÞk − 1 = ðq=pÞN − 1 , p ≠ q: (3.87)
Finally, for the case p = q = 1=2, note that the characteristic equation in Equation 3.83 has
one root 1 of order 2; thus, the solution to the difference equation for the probability of ruin
(with initial capital k) is
TABLE 3.1
Gambler’s Ruin with Capital k = 50 and Total Capital N = 100
Probability a50 b50 z50 A0 50 (1) B0 50 (1)
Q = .50 0.5 0.5 2500 1250 1250
q = .51 .880825 .119175 1904 1677 227
q = .55 .999956 .000044 500 499.93 .07
q = .60 1.000 .0000 250 250 0
Source: Allen, L. J. S., An Introduction to Stochastic Processes with Applications to Biology, Second Edition, CRC Press,
Boca Raton, FL, 2011, p. 113.
Consider the probability of ruin when the total capital is N and the initial capital is k, and
suppose N = $100 and k = $40; then the probability of ruin is ½, which is the same as the
probability of winning.
Refer to Equation 3.80 for the mean duration zk = E(Tk ); then we use the difference
equation technique to compute the mean duration time. The difference equation is
Table 3.1 portrays the probability of ruin, the probability of winning, and the average
duration of the game. Refer to Equations 3.86 and 3.87 for computing a50 , while for b50 , refer
to Equations 3.45 and 3.48. For the average duration z50 , refer to Equations 3.51 and 3.52.
The last two columns are the additive components of z50 given by Equations 3.35 and 3.36.
Of course, the statistical problem is to observe the gambler playing a game and estimating
the probability p of winning a particular game. This will be presented in Chapter 4.
represents the number of arrivals at time t recorded over the interval ½0, t and evolves from
state n to state n + 1, for n ≥ 0 and N(0) = 0. This is an example of a pure birth process since
the state of the system increases from n by one unit. This is a special case of the general birth
and death process, which can either increase from n to n + 1 or decrease from n to n − 1,
where the change from n to n + 1 is a birth and the transition from n to n − 1 is interpreted as
a death. In what is to follow, continuous-time Markov processes are defined and the
relation to discrete-type Markov chains is explained. This is followed by an illustration of
general birth and death processes, and then continuous chains are determined by a system
of differential equations that indeed characterize the probabilistic properties of a continuous
stochastic process with the Markov property. As with discrete Markov chains, limiting
long-run probabilities of the states of the system are described, and the section is finalized
with some queuing examples.
Let fX(t), t ≥ 0g be a continuous-time stochastic process; then the process is said to be a
continuous-time Markov chain (CTMC) if
for all s and t ≥ 0 and nonnegative integers i, j, x(v), 0 ≤ v < s. How is Equation 3.94
interpreted? A stochastic process has a Markovian property if the conditional probability
of the future state X(t + s) given the present state X(s) and past states X(v), 0 ≤ v < s
depends only on the present state (and not on the past). Our study of these Markov chains
will be confined to stationary processes, namely, those where Pr½X(t + s) = jjX(s) = i is
independent of s.
Associated with the continuous-time process is the random time between events thus,
suppose at time 0, the process is observed for 15 minutes, at which time the first event i
occurs. But since this is a Markov process, what is the probability that it remains in that state
for the next 26 minutes before the next event occurs? Thus, let T1 denote the amount of time
the process stays in state i then
Therefore, in general,
and the interarrival time is said to be memoryless, and in fact, it can be shown that T1 has an
exponential distribution. Another way to define a CTMC is to specify the probabilistic
properties of the process at which time it enters state i:
1. The amount of time it spends in state i before making a transition into a different
state is exponentially distributed with parameter li (with mean 1=li ).
2. When the process leaves state i, it enters the next state j with some probability Pij ,
X
where Pii = 0 and Pij = 1.
j
That is to say, a CTMC is a stochastic process that moves from state to state in the manner
of a DTMC; however, the time it spends in each state before entering the next state has an
98 Bayesian Inference for Stochastic Processes
exponential distribution. Also, it can be seen that the interarrival times between events are
independent random variables.
v0 = g 0 ,
vi = g i + d i , i > 0,
P01 = 1,
(3.97)
Pi,i+1 = g i =ðg i + d i Þ, i > 0,
and
Pi,i−1 = d i =ðg i + di Þ, i>0
This follows because if there are i items in the system, then the next state is i + 1 if a
birth occurs before a death; and the probability that an exponential random variable
with rate g i will happen earlier than an exponentially distributed random variable with
rate d i is di =(gi + di ), and the time until one or the other occurs is vi = gi + di . Of course, a
special case of the birth and death process is the Poisson process with exponential rates
g n = 0, n ≥ 0, and dn = 0, n ≥ 0, which is the case where there are only arrivals but no
departures. The Poisson process is also referred to as a pure birth process.
Another special case of a birth and death process is a pure birth process with a linear birth
rate (sometimes called the Yule process) with gn = ng. Still another example of the same
time of process is a linear growth model with immigration. The following description is
from pages 259 and 260 of Ross.6 For such a situation, the immigration model is defined as a
birth and death process where g n = ng and dn = nd + f, n ≥ 0. Such processes are employed
to describe biological reproduction and population growth, where each individual in the
population gives birth at an exponential rate d, and in addition, there is an additive con-
tribution due to immigration occurring at an exponential rate f; thus, the total birth rate is
nd + f. Departures occur at an exponential rate g for each item in the population. It is
interesting to derive the average size at time t; thus, let the mean be
where X(t) is the population size at time t. A differential equation will be developed to
derive an expression for μ(t) that obviously depends on g, d, and f. To do this, let h > 0 and
consider
where the outer expectation is with respect to the distribution of X(t) and the inner is with
respect to the conditional distribution of X(t + h) given X(t). Given the population size at
time t, the population at time t + h will either increase by one item if an arrival occurs or an
immigration occurs in (t, t + h). Also, if a death happens, the population will decrease by one
in the interval (t, t + h). Also, the population size does not change if neither of the two
preceding possibilities occurs. To describe this in symbols, it is stated as
Xðt + hÞ
= X ðt Þ + 1 with probability ½f + XðtÞg h + oðhÞ,
(3.100)
= X ðt Þ − 1 with probability XðtÞdh + oðhÞ,
= X ðt Þ with probability ½1 − f + XðtÞg + XðtÞd h + oðhÞ:
μðtÞ = ft + i: (3.104)
100 Bayesian Inference for Stochastic Processes
is the rate of the process when making the transition from i to j and is called the instan-
taneous transition rate. Our goal is to express the probabilistic properties of the process in
terms of the instantaneous transition rates and the transition probabilities.
Consider the probability that a chain presently in state i will be in the future in state j,
namely,
then the main question is, how does one express Equation 3.106 in terms of the quantities
involving Equation 3.105? To answer this question, consider the following three conditions
about the transition probabilities:
These limits are needed to set up the differential equations that will evolve into the
Kolmogorov differential equations. For the proof of Equation 3.107, see pages 266 and 267 of
Ross.6 The set of equations found in part 3 of Equation 3.107 are called the Chapman–
Kolmogorov equations, and from them, it follows that
X
k=∞
Pij ðt + hÞ − Pij ðtÞ = Pik ðhÞPkj ðtÞ − Pij ðtÞ
k=0
X
k=∞
= Pik ðhÞPkj ðtÞ − ½1 − Pii ðhÞPij ðtÞ;
k=0
h i
lim Pij ðt + hÞ − Pij ðtÞ =h
( )
X
= lim ½Pik ðhÞ=h Pkj (t) − ½½1 − Pik (h)=hPij ðtÞ,
k≠i
Introduction to Stochastic Processes 101
and taking the limit as h ! 0 results in the differential equations (which holds for all states i
and j and times ≥ 0) called the Kolmogorov backward equations:
X
(d=dt)Pij (t) = qik Pkj (t) − wi Pij (t): (3.108)
k≠j
What are the Kolmogorov equations for the pure birth process and the birth and death
process?
For a birth and death process, the Kolmogorov equations in Equation 3.108 reduce to
and
ðd=dtÞPij ðtÞ
h i
= ðg i + d i Þ g i =ðg i + d i ÞPi+1,j ðtÞ + d i =ðg i + d i ÞPi−1,j ðtÞ − ðg i + d i ÞPij ðtÞ,
h i
ðd=dtÞPoj ðtÞ = g 0 P1j ðtÞ − P0j ðtÞ
and (3.109)
for i > 0.
These equations will be applied to a special case of the birth and death process with two
states.
Consider a continuous-time birth and death process with two states. A machine works for
an exponential time with mean 1=g before failing; then, it takes a random amount of time,
with an exponential distribution with mean of 1=d, to be repaired. If the machine is
working, what is the chance the machine will be working at time t = 20? Let the two states
be 0 and 1, where if it is in state 0, it is working, while if the state is 1, the machine is being
repaired. That is, we want to determine P00 (20). The relevant parameters are g 0 = g, d 1 = d,
g i = 0 (i ≠ 0), and d i = 0 (i ≠ 1). Using the differential equations in Equation 3.109 for the
general birth and death process, an expression for P00 (20) will be derived.
It follows that
Using the initial condition P00 (0) = 1, one may show that the solutions to the Kolmogorov
equations (Equation 3.110) are
Thus, to find P00 (20), one must have value for the rates of the machine working and the
repair times of the machine. Of course, from a statistical point of view, by observing the
working and repair times of the machine, one can estimate the rates and the probabilities of
Equation 3.111.
assuming the limit exists and is independent of the state i. Similar to the discrete-time
process, we are interested in determining the solutions Pj to a set of equations. The
appropriate set of equations will be based on the Chapman–Kolmogorov equations of the
previous section. These equations are
X
ðd=dtÞPij ðtÞ = qkj Pik ðtÞ − wj Pij ðtÞ, (3.112)
k≠j
The limits in Equation 3.113 exist because the transition probabilities are Pij (t) and are
bounded over [0,1].
Thus, the relevant set of equations is
X
wj Pj = qkj Pk , ∀ j (3.113)
k≠j
X
and are solved for the limiting probabilities Pj , subject to the constraint Pj = 1.
j
Consider the limiting probabilities of the birth and death process of Section 3.7.2
and the defining quantities given by Equation 3.97. We consider the special case by
Introduction to Stochastic Processes 103
TABLE 3.2
Birth and Death Process: Limiting Probabilities
State Rate of Leaving = Entering Rate
0 g 0 P0 = d1 P1
1 (g 1 + d 1 )P1 = d 2 P2 + g 0 P0
2 (g 2 + d 2 )P2 = d 3 P3 + g 1 P1
n≥1 (g n + d n )Pn = dn+1 Pn+1 + g n−1 Pn−1
equating the rate at which the chain leaves a state with the rate at which it enters a
state (Table 3.2).
Add to each equation of Table 3.2 the preceding equation, which yields the system
g 0 P0 = d 1 P1 ,
g 1 P1 = d 2 P2 ,
(3.114)
⋮
g n Pn = dn+1 Pn+1 , n ≥ 0:
P1 = ðg 0 =d0 ÞP0 ,
and, in general,
j=∞
X
and using the constraint Pj = 1 implies that the solution is
j=0
" " ##
X
n=∞
P0 = 1= 1 + ðg 0 g 1 :::g n−1 Þ=ðd 0 d 1 :::dn−1 Þ ,
n=1
Thus, if the entry and departure rates are known, the preceding equations determine the
limiting probabilities.
104 Bayesian Inference for Stochastic Processes
ð∞
pðx, tjxo Þdx = 1: (3.116)
−∞
It will be shown that the transition probabilities in going from one state to the other are
stationary. Also, we will assume that for small h, X(h + t0 ) is close to X(t0 ) = x, that is,
It was demonstrated by Einstein that the density p(x, tjxo ) is a solution to the partial
differential equation
ð∂ = ∂ tÞp = D ∂2 =∂2 x2 p, (3.118)
D = 2RT=Nf , (3.119)
where R is the gas constant, T is the temperature, N is Avogadro’s number, and f is the
coefficient of friction. It can be shown that D = 1/2, if the proper units are chosen for the
terms in the diffusion equation (Equation 3.119). According to pages 341–343 of Karlin and
Taylor,1 the solution to the partial differential equation (Equation 3.118) is
Introduction to Stochastic Processes 105
pffiffiffiffiffi
pðx, tjx0 Þ = 1= 2π exp −ð1=2tÞðx − x0 Þ, (3.120)
1. Every increment X(t + s) − X(s) has a normal distribution with mean 0 and variance
s2 t.
2. For each pair of disjoint intervals ½t1 , t2 and ½t3 , t4 , the increments X(t2 ) − X(t1 ) and
X(t4 ) − X(t3 ) are independent.
3. X(0) = 0 and X(t) are continuous.
From this, one may show that for n and time points satisfying t > t0 > t1 > ::: > tn ,
Thus, the three postulates of the definition of the Brownian motion imply that the pro-
cess fX(t), t ≥ 0g satisfies the Markov property in Equation 3.121. Under the condition that
X(t) = 0, the variance of X(t) is s2 t, and s2 is called the variance parameter of the process.
Note that the joint distribution of X(t1 ), X(t2 ), :::, X(tn ) can be found via transformation of the
n increments
But we know that the distribution of each increment is normal with mean 0 and vari-
ance s(ti − tn−1 ) , and X(t) = 0, which is enough information to find the joint distribution of
X(ti ), i = 1, 2, :::, n. When s2 = 1, the process is referred to as the standard Brownian motion.
There are several interesting generalizations of the Brownian motion, including the
Brownian motion with drift, defined as follows:
Obviously, the Brownian motion with drift satisfies the Markov property. From a sta-
tistical viewpoint, realizations of this process would be used to make inferences about the
mean μ and s2 . For our purposes, Bayesian estimates and tests of hypotheses about these
parameters are the subjects of Chapter 6. Another interesting generalization of Brownian
motion is the geometric Brownian motion. Let fX(t), t ≥ 0g be the Brownian motion with
drift μ and diffusion coefficient s2 ; then the process
106 Bayesian Inference for Stochastic Processes
is referred to as the geometric Brownian motion with state space (0, ∞). It can be shown that
the mean and variance of Z(t) = Z(0)eX(t)−X(0) are
E½ZðtÞjZð0Þ = zo = z0 exp t μ + s2 =2
and (3.123)
Var½ZðtÞjZðt0 Þ = z0 = z20 exp 2t μ + s2 =2 exp ts2 − 1 ,
respectively.
An interesting version of the Brownian motion is the Ornstein–Uhlenbeck10 process,
given by a normal process with mean 0 and covariance
where X(t) is the position of a body in motion, with X0 and V representing the initial
position and velocity, respectively. What are the mean value function and covariance kernel
of this process? They are
and
Recall for the Brownian motion that the mean of X(t) is 0 and the variance is s2 t; but what
is its covariance kernel? It can be shown to be
For a Poisson process fN(t), t ≥ 0g with parameter l, the mean value function and vari-
ance are m(t) = lt and Var½X(t) = lt, respectively. What is the covariance kernel? It can be
shown that
Xðt1 Þ, Xðt2 Þ, :::, Xðtm Þ e Xðt1 + hÞ, Xðt2 + hÞ, :::, Xðtm + hÞ: (3.130)
Thus, the joint distribution of the m random variables remains the same when the time is
shifted by an amount h for all h.
If for all m = 1, 2, … the process is stationary of order m, then the process is said to be
strictly stationary. Often, it is difficult to verify that a given process is strictly stationary,
because stationarity has to be verified for all positive integers.
A weaker type of stationarity is called covariance stationarity and is described as follows:
It is assumed that the process has finite second moments; then it is called covariance sta-
tionary if the covariance kernel K(s,t) is a function only of js − tj, s, t ∈ T, where T is a linear
index set. It thus follows that there exists a function R (called the covariance function) such
that for all s and t, K(s,t) = R(s − t) or, equivalently,
where s and h belong to the index set T of the process. The idea of stationarity is important
because for such processes, ergodic theorems were first proved. Ergodic theorems show
108 Bayesian Inference for Stochastic Processes
that the sample means of realizations from stationary processes have desirable frequency
properties and, hence, properties that imply good sampling properties for Bayesian esti-
mates of certain unknown parameters of a stationary stochastic process.
Suppose fX(t), t ≥ 0g is a stochastic process with mean value function m(t) = E½X(t)
and covariance function K(s, t) = Cov½X(s), X(t), and suppose ½X(t), 0 ≤ t ≤ c is a finite
record or realization. Under what conditions do these observations provide optimal
properties for estimating, say, the mean value function m(t)? Birkhoff11 and Von Neumann12
were among the first to provide satisfactory proofs for ergodic theorems (about ensemble
averages). In the proof by Birkhoff, it was assumed that the process fX(t), t = 1, 2, :::g is
strictly stationary; then for any function g where the ensemble average
E½ gðXðtÞÞ (3.132)
X
i=T
ð1=T Þ g½XðiÞ, (3.133)
i=1
X
i=T
MT = ð1=T Þ X ði Þ (3.134)
i=1
How is this version of ergodic interpreted? Equation 3.136 implies that the successive
sample means in Equation 3.134, formed from a sample function of the process, have
variances which tend to be 0 as the sample size T becomes larger. In a sense, this implies that
the sample mean is approximately the same as the ensemble mean. The following theorem
from pages 74 and 75 of Parzen4 provides necessary and sufficient conditions for the sample
means to be ergodic:
Let fX(t), t = 1, 2, :::g be a stochastic process with covariance kernel K(s,t) where
and let
cðtÞ = Cov½XðtÞ, Mt
be the covariance between the sample mean and the tth observation; then in order for
lim Var½MT = 0, T ! ∞,
lim cðtÞ = 0, t ! ∞:
Thus, the sample means are ergodic if and only if the correlation between the sample
mean and the last observation becomes smaller and smaller as the sample size increases. For
additional details about this ergodic theorem, see pages 74 and 75 of Parzen.4
ðT
MT = ð1=T Þ XðtÞdt: (3.137)
0
However, this integral needs to be defined! Similar to the definition of the ordinary
ðb
Riemann integral, a natural way of defining X(t)dt as a limit of approximating sums
a
X
i=n
X(ti )(ti − ti−1 ), where the limit is taken over partitions of the interval (a, b into
i=1
subintervals by the points a = t0 < t1 < ::: < tn = b in such a way that the maximum length
among the intervals (ti − ti−1 ), i = 1, 2, :::, n. For the purpose of this book, the type of con-
vergence is taken to be convergence in mean square, which is defined as follows:
A sequence of random variables Yi , i = 1, 2, ::: is said to converge in mean square to the
random variable Y if
lim E jYn − Yj2 = 0, n ! ∞: (3.138)
110 Bayesian Inference for Stochastic Processes
A necessary and sufficient condition for convergence in mean square is based on the pro-
duct moment E½X(s), X(t) considered as a function of s and t over the region S = ½a, bx½a, b.
If the product moment has a Riemann integral over S, then it can be shown that the
ðb
stochastic integral X(t)dt exists in the sense of convergence in mean square of the
a
approximating sums described earlier. Suppose that the process has a mean value function
m(t) and covariance kernel K(s,t); then it can be shown that
2b 3 b
ð ð
4 5
1. E X(t)dt = m(t)dt
a a
2 3
ðb 2 ðb ðb
2. E4 X(t)dt 5 = E½X(s)X(t)ds dt (3.139)
a a a
2 3
ðb ðb ðb
3. Var4 X(t)dt5= K(s, t)ds dt
a a a
2b 3 b d
ð ðd ð ð
4 5
4. Cov X(s)ds, X(t)dt = ds dtK(s, t).
a c a c
Thus, the moments of stochastic integrals are Riemann integrals of the appropriate
function. Of course, the mean value function and covariance kernel of the process have to
exist and be known. In order to illustrate the stochastic integrals of Equation 3.139, an
example with the displacement of a particle in free Brownian motion is considered.
Suppose a body is moving in a straight line (a simplification) because the body is colliding
with other bodies and suppose N(t) is the number of hits on the body and that N(t) is
Poisson with parameter k; that is, the average number of hits per unit time is k. As a result of
each hit, the body reverses velocity either from d to −d or from −d to d; thus, the velocity of
the body is given by the stochastic process
Thus, the process fv(t), t ≥ 0g has mean value function E½v(t) = 0 and covariance function
E½v(s)v(t) = d2 e−2djs−tj .
The displacement of the body is given by
ðt
XðtÞ = vðxÞdx; (3.140)
0
Introduction to Stochastic Processes 111
thus,
2 2
3 2 3
ðt ðt ðt
6 7
E4 v(x)dx 5 = E4 vðx1 Þvðx2 Þdx1 dx2 5,
0 0 0
(3.141)
ðt ðt
= E½vðx1 Þvðx2 Þdx1 dx2 :
0 0
Since = E½v(s)v(t) is continuous in s and t, the integral in Equation 3.140 exists; therefore,
the mean square displacement is
E½jXðtÞj2 = 2d2 =b2 e−bt − 1 + bt , (3.142)
where b = 2d.
The stochastic integral and stochastic derivatives are equally important, and the deriv-
ative process of the stochastic process fX(t), t ≥ 0g is defined as
where the limit is mean square convergence. Under what conditions does the limit exist? It
can be shown that a necessary and sufficient condition for the limit to exist is that the fol-
lowing two limits exist as h ! ∞ and k ! ∞:
Of main importance is the mean value function and covariance kernel of the derivative
process fX0 (t), t ≥ 0g given by the stochastic derivative in Equation 3.143. It can be shown
that
112 Bayesian Inference for Stochastic Processes
E X0 ðtÞ = E½ðd=dtÞXðtÞ = ðd=dtÞmðtÞ (3.145)
and
Cov X0 ðsÞ, X0 ðtÞ = d2 =ds dt Kðs, tÞ: (3.146)
Let fX(t), t ≥ 0g be a covariance stationary process, and let fX0 (t), t ≥ 0g be the corre-
sponding derivative process. Then, is the derivative process also covariance stationary? The
answer is yes, and the student should verify the assertion.
3.10 Exercises
!
P1 , 0
P=
0, P2
where
!
:5, :5
P1 =
:25, :75
and
0 1
0, 1, 0
B C
P2 = B C
@ :5, 0, :5 A:
0, 1, 0
Show that all the states communicate and all are recurrent.
Introduction to Stochastic Processes 115
14. For a different situation with states 0, 1, 2, 3, and 4, consider a process with
transition matrix
0 1
1=2, 1=2, 0, 0, 0
B C
B 1=2, 1=2, 0, 0, 0 C
B C
B C
P=B
B 0, 0, 1=2, 1=2, 0 C,
C
B C
B 0, 0, 1=2, 1=2, 0 C
@ A
1=4, 1=4, 0, 0, 1=2
where there are three classes f0, 1g, f2, 3g, and f4g. Show that the first two are
recurrent but the third is transient.
15. Suppose X(i), i = 1, 2, :::, n, is a random sample of size n from a discrete pop-
ulation with probability mass function Pr½X = i = ai , i = 1, 2, :::, and consider the
stochastic process fX(i), i = 1, 2, :::g. What is the transition probability matrix for
Xi=n
this process? See Equation 3.59. Now consider the process fY(n) = X(i),
i=1
i = 1, 2, :::g; thus, Pr½Y(n + 1) = kjY(n) = j = ak−j . What is the transition probability
matrix of this process? See Equation 3.61.
16. This example is taken from pages 108 and 109 of Allen2 and involves a process
with state space f0, 1, 2, ::, Ng, in which case there are two boundaries or with
infinite and countable state space {0, 1, 2, …} with boundary at 0. In such a model,
the states are positions which are denoted by X(n), where n is time. Let p be the
probability of moving one unit to the right and 1 − p be the probability of moving
one unit to the left; thus, the one-step transition probability is
Pr½Xðn + 1Þ = jjXðnÞ = i = p, j = i + 1,
= 1 − p, j=i−1
ðb
22. Define the stochastic integral X(t)dt as the limit of a sequence of partial sums
a
where convergence is in the sense of mean square, and verify the four equations of
Equation 3.139 involving the first and second moments of stochastic integrals.
23. Suppose that the body is colliding with other bodies and suppose that N(t) is the
number of hits on the body and that N(t) is Poisson with parameter k; that is, the
average number of hits per unit time is k. As a result of each hit, the body reverses
velocity either from d to −d or from −d to d; thus, the velocity of the body is given
by the stochastic process
Show that the process fv(t), t ≥ 0g has mean value function E½v(t) = 0 and
covariance function E½v(s)v(t) = d2 e−2djs−tj .
The displacement of the body is given by
ðt
X(t) = v(x) dx;
0
thus,
2 2
3
2t t 3
ðt ðð
6 7
E4 v(x)dx 5 = E4 v(x1 )v(x2 ) dx1 dx2 5
0 0 0
ðt ðt
= E½v(x1 )v(x2 ) dx1 dx2 :
0 0
where b = 2d.
24. Suppose f(d=dt)X(t), t ≥ 0g is the derivative process of the process fX(t), t ≥ 0g,
which has mean value function m(t) and covariance kernel K(s, t). Show
E X0 ðtÞ = E½ðd=dtÞXðtÞ = ðd=dtÞmðtÞ
and
Cov X0 ðsÞ, X0 ðtÞ = d2 =ds dt Kðs, tÞ:
Introduction to Stochastic Processes 117
References
1. Karlin, S., and Taylor H. M. 1975. A First Course in Stochastic Processes, Second Edition. San Fran-
cisco: Academic Press.
2. Allen, L. J. S. 2011. An Introduction to Stochastic Processes with Applications to Biology, Second Edition.
Boca Raton, FL: CRC Press.
3. Cox, D. R., and Miller, H. D. 1965. The Theory of Stochastic Processes. London: Chapman and Hall.
4. Parzen, E. 1962. Stochastic Processes. San Francisco: Holden Day Wilson.
5. Cox, D. R., and Isham, V. 1980. Point Processes. New York: Chapman and Hall.
6. Ross, S. M. 1972. Probability Models, Fifth Edition. San Diego, CA: Academic Press.
7. Bailey, N. T. J. 1964. The Elements of Stochastic Processes. New York: John Wiley & Sons.
8. Chiang, C. L. 1968. Introduction to Stochastic Processes in Biostatistics. New York: John Wiley & Sons.
9. Wiener, N. 1923. Differential space. Journal of Mathematics and Physics/Massachusetts Institute of
Technology 2:131–174.
10. Uhlenbeck, G. E., and Ornstein, L. S. 1930. On the theory of Brownian motion. Physical Review
36:823–841.
11. Birkhoff, G. D. 1931. Proof of the Ergodic theorem. Proceedings of the National Academy of Sciences of
the United States of America 17:656–660.
12. Von Neumann, J. 1932. Proof of the quasi-ergodic hypothesis. Proceedings of the National Academy
of Sciences of the United States of America 18:70.
[Link]
4
Bayesian Inference for Discrete Markov Chains
4.1 Introduction
This chapter begins the formal approach to using Bayesian methods of making inferences
for stochastic processes, in particular, those processes with a countable number of states and
an index over the set of nonnegative integers. Bayesian methods of inference consist of
estimation, testing hypotheses, and making predictions (of future observations), and these
methods were introduced in Chapter 2 for several well-known processes.
In general, Bayesian inferences will be provided for each case of a Markov chain intro-
duced in the following sections of the chapter. The chapter begins with a brief review of the
definition of a Markov chain, followed by the presentation of many examples, including the
example given by Andreyevich Markov,1 the gambler’s ruin problem, the Wright–Fisher
model in genetics, a random walk on a graph, cycle and complete graphs, a birth and death
process with a countable number of states, the idea of weighted directed graph with
associated examples and transition matrices, and an interesting example by Dobrow2 about
cancer metastasis.
This is followed by an explanation of how to compute the n-step transition probabilities
illustrated by examples including the gambler’s ruin problem and an example involving a
chain that explains the status of the weather. In order to determine the long-term behavior
of a chain, the integer powers of the one-step transition matrix P are needed, and it is at this
point the R Code for computing such powers of P is presented. The long-term behavior
using R to compute the powers of P is illustrated with several examples, including the risk
of fire in Ontario, example from Diaconis.3 Another interesting and an example by Dobrow2
of long-term behavior is given by a random walk on a cycle with 26 states, and another
example (a random walk on a cycle graph with six vertices) of where the long-term behavior
exhibits an alternating sequence of distributions, depending on the initial state of the chain,
is also described. For each example, Bayesian inferences are provided by simulating the
states of the chain, estimating the associated transition matrix P, testing hypotheses about
the entries of the transition matrix, and generating future observations from the chain based
on the estimated transition matrix P.
Next to be considered is the limiting behavior of a Markov chain; thus, the idea of a
limiting distribution and a stationary distribution are explained. It is shown that the long-
term probability of a particular state is the same as the proportion of the time the chain is in
that state. Both analytical and computation methods using R illustrate ways of determining
the limiting probabilities for some interesting cases of Markov chains, including the general
two-state chain. Closely associated with the liming distribution of a chain is the stationary
119
120 Bayesian Inference for Stochastic Processes
distribution of the chain. The stationary distribution of a chain is defined, and it is dem-
onstrated that the limiting distribution of a chain in a stationary distribution π is one that
satisfies
π = πP, (4.1)
Absorbing chains is the last topic to be discussed in this chapter. A state is called
absorbing if the probability of remaining in the state over one time period is 1. Of course, a
good example is the gambler’s ruin chain with transition matrix
0 1
0, :6, 0, 0, :4, 0
B C
B :4, 0, :6, 0, 0, 0 C
B C
B C
B 0, :4, 0, :6, 0, 0 C
B C
P=B C: (4.2)
B 0, 0, :4, 0, 0, :6 C
B C
B C
B 0, 0, 0, 0, 1, 0 C
@ A
0, 0, 0, 0, 0, 1
Assuming the gambler starts with $2 with a chance of winning $1 on each round of .6 and
either gains $5 or loses, and then the absorbing states are 0 and 5. When P is arranged into
the canonical form, one is able to compute the probability of the eventual ruin using R. From
a Bayesian approach, I will generate realizations from the chain with transition matrix P and
then test the hypotheses that the probability of winning one dollar is .6.
Lastly, Chapter 6 is concluded with a section for comments and conclusions, which will
summarize the Bayesian inferences presented in the chapter.
The states are assumed to be nonnegative integers, and the first example is taken from
Diaconis,3 who studied the results of a large number of coin tosses resulting in the one-step
transition matrix
!
:51, :49
P= : (4.4)
:49, :51
This shows evidence of a slight bias, where if the previous toss results in heads, the
current toss results in heads with probability .51, and if the previous toss resulted in a head,
the current toss occurs with a tail with probability .49. Also, if the previous toss resulted in a
122 Bayesian Inference for Stochastic Processes
tail, the current toss results in a head with probability .49. Suppose we generate a realization
from this chain with transition matrix P using the following R Code given by Dobrow.2
Note that this is a Markov chain where X(n) = 1 denotes a head and X(n) = 2 signifies a tail.
R Code 4.1
Markov is a function with inputs init P and n. init is initial distribution where c(1,0)
denotes the initial toss is head, while c(0,1) denotes the initial toss is a tail.
The following realization was based on the following inputs for the Markov function
given by R Code 4.1: init=c(1,0), P given by 4.3, and n=100:
1212122221112122222221211122222211121
2122122111221212211211221221211221112
2 1 1 2 1 2 1 1 2 2 2 2 2 2 1 1 2 2 2 2 2 1 1 1 1 1 2.
Thus, the usual estimated values of the transition probabilities for P11 and P12 are .4545
and .5454, respectively and are .4363 and .5636 for P21 and P22, respectively. Consider the
Bayesian approach to estimating P11, then one must place a prior distribution on this
parameter, which, in turn, depends on the count n11, which has a binomial distribution with
parameters P11 and n1 = n11 + n12. I am assuming noninformative prior information about
P11 with the improper prior density
πðP11 Þ ∝ P−1 −1
11 ð1 − P11 Þ , 0 < P11 < 1: (4.5)
n11 −1
πðP11 jn1 Þ ∝ P11 ð1 − P11 Þn12 −1 , 0 < P11 < 1, (4.6)
which is a beta distribution with parameters n11 and n12. If one employs the posterior mean
to estimate P11, then the estimator is E(P11|n1.) = n11 / (n11 + n12) = 20 / (20 + 24) = .4545, which is
the usual maximum likelihood estimator of P11. It should be noted that if one uses the uniform
prior for P11, the posterior mean of this parameter is E(P11|n1.) = (n11 + 1) / (n11 + n12 + 2) = .4565,
which is not much different from the estimate based on the prior distribution (Equation 4.6).
Of course, it is of interest to know the 95% credible interval for P11, which is left as an
exercise for the reader.
Bayesian Inference for Discrete Markov Chains 123
Let us now generate a realization from this process using R Code 4.1., presented in the
previous section. Assuming the initial state is 1 (it rained both today and yesterday), 100
generated values are as follows:
1134444421113234442111321342344234444
4444421344423444444211111344444442344
4 4 4 4 2 1 3 4 4 4 4 4 4 4 4 4 2 3 4 4 4 4 4 4 4 4 4.
Conditioning on the initial state of 1, state 1 was visited nine times; and state 3, six times;
and of course, states 2 and 4 were visited zero times. Thus, as in the previous example,
the distribution of n11 is binomial with parameters P11 and n11 + n13 = 15. And, using
the uniform prior for this parameter, the posterior distribution of P11 is beta with param-
eters n11 + 1 = 10 and n13 + 1 = 7, yielding a posterior mean of E(P11 jn11 = 9, n13 = 6) =
10=17 = :5882.
I will use a completely different method of performing the posterior analysis by
employing WinBUGS to generate observations for the transitions based on the transition
matrix P given by Equation 4.7. Note that given P11 , the distribution of the count n11
is binomial with distribution P11 and n11 + n13 = n1: = 50. Using WinBUGS Monte Carlo
Markov chain (MCMC) techniques allows one to construct credible intervals for the tran-
sition probabilities. I begin with the first row of P which conditions on the first state of the
process where P11 = :7 and P13 = :3, and the other two transition probabilities of the first
row are zero; that is, it is impossible to go from state 1 to either states 2 or 4. It is also
assumed that the initial state is 1, that it rained both today and yesterday. I am also
124 Bayesian Inference for Stochastic Processes
assuming 50 transitions with initial state 1. The following code was used to perform the
Bayesian analysis where the data are given in the list statement.
model {
p11~dbeta(1,1)
for (i in 1 : 50) {
n11[i] ~ dbin(p11,50) }
}
list(
n11 = c(
37.0,34.0,39.0,27.0,32.0,
36.0,35.0,37.0,42.0,28.0,
29.0,35.0,32.0,34.0,33.0,
34.0,38.0,33.0,43.0,37.0,
31.0,37.0,30.0,36.0,27.0,
37.0,29.0,34.0,33.0,38.0,
36.0,39.0,34.0,33.0,36.0,
35.0,38.0,38.0,36.0,37.0,
36.0,36.0,31.0,36.0,33.0,
45.0,34.0,32.0,39.0,30.0))
The Bayesian analysis assumes a binomial distribution for n11 , which can vary from 0 to
50 and where P11 is given a uniform prior distribution.
The 50 observations given in the list statement where generated from a binomial distri-
bution with q = .7 using the following code:
model {
for (i in 1 : 100) {
n11[i] ~ dbin(.7,50)
}
}
When executed with 35,000 observations with a burn-in of 5,000, the result of the pos-
terior analysis is presented in Table 4.1.
Thus, the posterior mean of P11 is .6963 with a 95% credible interval of (.6783, .7142), and
Figure 4.1 portrays the posterior density. The posterior mean of .6963 differs very little from
the P11 = .7 used to generate the observations used for the posterior analysis; thus, a Bayesian
test of the null hypothesis H: P11 = :7 versus the alternative A: P11 ≠ :70 will be performed.
The reader is referred to Section 2.5.3 to review the fundamental aspects of testing
hypotheses from a Bayesian perspective.
The posterior probabilities of the null and alternative hypotheses p0 and p1 are required
where that of p0 is given by Equation 4.9; thus, it follows that
TABLE 4.1
Posterior Analysis for P11
Parameter Mean SD Error 2 1/2 Median 97 1/2
P11 .6963 .009167 .0000521 .6783 .6964 .7142
FIGURE 4.1
Posterior density of P11 .
where
π0 is the prior probability of the null hypothesis, and the probability mass function of n11
(given the null hypothesis) is
!
n1:
xðn11 jP11 = :70Þ = ð:7Þn11 ð:3Þn1:−n11 , (4.10)
n11
and
Note that in the marginal mass function of n11 given by Equation 4.10 that x1 (P11 ) is the
prior density of P11 over interval [0,1], that is, over the values specified by the alternative
hypothesis. It is convenient to choose
where 0 ≤ P11 ≤ 1 with a and b as positive parameters; thus, the prior distribution of P11 is a
beta with parameters a and b. Now it can be shown that the marginal distribution of n11 is
given by
!
n1:
x1 ðn11 Þ = ½Gða + bÞ=GðaÞGðbÞ ½Gðn11 + aÞGðn1: − n11 + bÞ=Gðn1: + a + bÞ, (4.14)
n11
where a and b must be chosen to reflect the prior information about the null hypothesis.
Combining Equations 4.8 through 4.14 allows one to evaluate the posterior probability p0 of
the null hypothesis. For the problem at hand, let
π1 = π0 = 1=2;
a = 7; (4.15)
b = 3; :
n11 = 37, the first value generated from the appropriate binomial (see WinBUGS Code 3.1);
and n1: = 50 (the total number of transitions with an initial state of 1).
One can show that the posterior probability of the null hypothesis is p0 =.99513. Note
that these posterior probabilities can vary according to the values of the number of
transitions n11 as well as to the specifications of the prior distributions of the null and
alternative hypotheses. For example, if the observed transition is 27, then one can show
that p0 = :9998, but if n11 = 45, then it can be demonstrated that p0 = :01800. The latter
calculation shows that there is little evidence indicating that the null hypothesis is true,
but when n11 = 37, there is strong evidence that the null hypothesis is true as indicated by
p0 = .99513.
The next phase for Bayesian inference for the rainy day example is forecasting future
observations. The reader is referred to Section 2.6.2, which presents the essentials for pre-
dicting future observations from a binomial population.
Suppose the binomial case is again considered, where the posterior density of the bino-
mial parameter P11 is
xðP11 jxÞ = ½Gða + bÞGðn + 1Þ=GðaÞGðbÞGðx + 1ÞGðn − x + 1ÞP11 a+x−1 ð1 − P11 Þb+n−x , (4.16)
a beta with parameters a + x and n − x + b, and x is the sum of the set of n observations. The
population mass function of a future observation Z is f (zjq) = qz (1 − q)1−z ; thus, the pre-
dictive mass function of Z, called the beta-binomial, is
!
X
i=n
gðzjxÞ = Gða + bÞGðn + 1ÞG a + xi + z Gð1 + n + b − x − zÞ
i=1
model;
{
# the parameters of the beta
# α þ n11 ¼ 1 þ 37 ¼ 38
# b þ n−n11 ¼ 1 þ 50−37 ¼ 14
theta~dbeta(38,14)
for (i in 1:50){
y[i]~dbern(theta)
}}
list(
theta = 0.7682,
y = c(
1.0,1.0,1.0,1.0,0.0,
0.0,1.0,1.0,1.0,1.0,
1.0,1.0,0.0,1.0,1.0,
0.0,1.0,1.0,1.0,1.0,
1.0,1.0,1.0,1.0,0.0,
1.0,1.0,1.0,1.0,1.0,
1.0,1.0,1.0,1.0,0.0,
1.0,1.0,0.0,0.0,1.0,
0.0,1.0,1.0,1.0,0.0,
1.0,1.0,0.0,0.0,1.0))
The total number of ones in the preceding list statement is the predicted number of tran-
sitions from state 1 to state 1, while the total number of zeroes is the number of transitions
from state 1 to state 3. There are 38 out of 50 predicted transitions from state 1 to state 1. Recall
that the ratio 38/50 = .768 should be compared to the transition probability P11 = .70 in the
rainy day example.
distribution of the process at a given time point. Also presented are the R routines that will
be used to compute the n-step transition probabilities and the associated Bayesian inference
procedures. For example, the estimation of the n-step transition probabilities of a Markov
process is a primary goal, but other inference procedures such as testing hypotheses and
prediction procedures will also be described. This will entail the simulation of realizations
for interesting examples from biology.
Let us now consider the n-step transition matrix with ij-th element:
where P0ij = P½X(0) = jjX(0) = i = 1 if i = j and 0 if otherwise. We now show that the n-step
transition matrix is the nth power of the one-step transition matrix P. Note in Equation 4.18
that Pnij is not the nth power of Pij , and that the nth power of P is denoted by (Pij )n .
Consider
X
P½X(n) = jjX(0) = i = P½XðnÞ = jjXðn − 1Þ = k, Xð0Þ = iP½X(n − 1) = kjX(0) = i
k
X
= P½XðnÞ = jjXðn − 1Þ = kP½Xðn − 1Þ = kjXð0Þ = i (4.19)
k
X
= Pkj P½Xðn − 1Þ = kjXð0Þ = i,
k
which is valid because of the Markov property and the fact that the process is time
homogenous; thus, for n = 3,
X X
P½Xð3Þ = jjXð0Þ = i = Pkj P½Xð2Þ = kjXð0Þ = i = Pkj P2ik = P3 ij , (4.20)
k k
which is the ijth element of the third power of the first step transition matrix P, as was to be
shown.
Consider the following example of a random walk on a cycle graph consisting of five
vertices labeled 0, 1, 2, 3, and 4, then the one-step transition matrix is
0 1
0, :5, 0, 0, :5
B C
B :5, 0, :5, 0, 0 C
B C
B C
P=B
B 0, :5, 0, :5, 0 C:
C (4.21)
B C
B 0, 0, :5, 0, :5 C
@ A
:5, 0, 0, :5, 0
That is, starting at vertex zero (the initial state), the probability of remaining in that state is
0, but is ½ of moving to the right is ½. Note that the probability of remaining in the initial
state is always 0. What is the transition matrix after six moves? It can be shown to be
Bayesian Inference for Discrete Markov Chains 129
0 1
:312500 :109375 :234375 :234375 :109375
B C
B :109375 :312500 :109375 :234375 :234375 C
B C
B C
P6 = B
B :234375 :109375 :312500 :109375 :234375 C
C: (4.22)
B C
B :234375 :234375 :109375 :312500 :109375 C
@ A
:109375 :234375 :234375 :109375 :312500
Note the pattern of the six-step transitions is as follows: the probability of a return to the
initial position is .312500 and the probability of moving one vertex to the right is .109375 as
is the probability of moving one vertex to the left, etc. Also, the probability of moving two
units to the right or left is .234375.
The following code is used to generate the n-step transition probabilities, where the function
matrixpower has two arguments, the matrix labeled “mat” of one-step transition proba-
bilities given by Equation 4.20 and the desired power k, which refers to the k-step tran-
sition probabilities, where k = 6. This example is from Dobrow.2 See the following R Code 4.2:
R Code 4.2
Of interest to the Bayesian is to estimate the probabilities of the one-step transition matrix
(Equation 4.22), and then use those estimates to estimate the six-step transition probabilities
(Equation 4.23) and compare them to the entries of the matrix in Equation 4.23. Consider the
first row of Equation 4.22, which is the conditional distribution of the five states (vertex
number) given the initial state 0, then I will assume that the distribution of the number of
transitions is multinomial with probabilities 0, .5, 0, 0, .5, and 0 and will generate four
realizations assuming a total of 50 transitions with the following R statement for generating
observations from the multinomial distribution.
> rmultinom(4,50,prob)
[1] [2] [3] [4]
[0] 0 0 0 0
[1] 22 32 23 18
[2] 0 0 0 0
[3] 0 0 0 0
[4] 28 18 27 32
Thus, the first realization generates 22 transitions from state 0 to state 1 and 28 one-step
transitions from state 0 to state 4, while there are zero transitions from 0 to the other three
states 0, 2, and 3. The obvious estimates for the transition probabilities are 22/50 = .44 and
28/50 = .56 for P01 and P04 , respectively. Based on the first realization, what are the Bayesian
estimates for these two transition probabilities? To perform the Bayesian analysis, I assumed
that there were 50 transitions that the conditional distribution of observed transitions had
130 Bayesian Inference for Stochastic Processes
a Bernoulli distribution with probability P01 = :5. Fifty observations were generated using
WinBUGS, then using those fifty simulated observations, P01 was estimated based on
WinBUGS Code 4.4. Note that the 50 simulated observations are included in the list statement
and that the prior distribution of P01 is uniform. The Bayesian analysis is executed with 35,000
observations generated from the posterior distribution and initially with 5,000 observations.
WinBUGS 4.4
model {
p01~dbeta(1,1)
for (i in 1 : 50) {
y[i] ~ dbern(p01)
}
}
list(
y = c(
1.0,0.0,0.0,1.0,1.0,
0.0,0.0,1.0,1.0,1.0,
1.0,1.0,1.0,0.0,0.0,
1.0,0.0,1.0,0.0,1.0,
1.0,1.0,1.0,0.0,1.0,
1.0,0.0,0.0,1.0,0.0,
0.0,0.0,1.0,0.0,0.0,
0.0,1.0,1.0,1.0,0.0,
1.0,0.0,1.0,1.0,1.0,
1.0,1.0,0.0,0.0,1.0))
TABLE 4.2
Posterior Distribution of P01
Parameter Mean SD Error 2 1/2 Median 97 1/2
P01 .5769 .06797 .000385 .4423 .5766 .7066
Bayesian Inference for Discrete Markov Chains 131
Note that I used P^01 = P^10 = P^21 = P^32 = P^40 = :5769 for estimates of the one-step transition
probabilities in the matrix in (Equation 4.23). As a consequence of using R Code 4.2, the
estimated six-step transition probabilities are given by
0 1
:40965410 :1149245 :2626511 :1819211 :08607882
B C
B :09515764 :4294210 :1058457 :1819211 :24288429 C
B C
B C
^
P =B
6
:1058457 :16215428 C
B :35066753 :1149245 :3216377 C: (4.24)
B C
B :24288429 :3242767 :1149245 :2409077 :13223654 C
@ A
:14131536 :3242767 :2164934 :1058457 :26729857
One should compare the estimated six-step transition probabilities given by Equation
4.24 with the corresponding entries of the matrix in Equation 4.21, the matrix of “actual” six-
step transition probabilities.
A computation of interest in this section is that of the marginal distribution of X(n). It is
easy to show that the marginal distribution is
namely, the jth component of the vector aPn , where a is the row vector denoting the initial
distribution of the process; that is, the jth component of a is P½X(0) = j and Pn is the
nth power of the one-step transition matrix P. In order to explain this idea, suppose that
P½X(6) = 1 is to be estimated assuming that a = (1, 0, 0, 0, 0); that is, that the initial state is 0.
Note that the estimated value of P6 is given by Equation (4.24;, thus, P½X(6) = 1 is esti-
mated by the first component of the 1 × 5 vector:
0 1
:40965410 :1149245 :2626511 :1819211 :08607882
B C
B :09515764 :4294210 :1058457 :1819211 :24288429 C
B C
B C
^ ½Xð6Þ = 0 = ð1, 0, 0, 0, 0ÞB :35066753 :1149245 :3216377
P :1058457 :16215428 C
B C,
B C
B :24288429 :3242767 :1149245 :2409077 :13223654 C
@ A
:14131536 :3242767 :2164934 :1058457 :26729857
which is the first component of (.4096, .1149, .2626, .1819, .0860), namely, .4096. Thus, at
time 6, the estimated probability that the process returns to the first state (the starting
vertex of the cycle graph) is .4096. The student will be asked to estimate P½X(6) = 0 given
other initial distributions a. Refer to the exercises at the end of the chapter.
Last to be considered is the Bayesian estimation of the joint distribution of the process at
an arbitrary number of time points, but for now, I consider the following example based on
the cycle graph with estimated one-step transition matrix (Equation 4.25). For example, it
can be shown that
P½Xð5Þ = i, Xð6Þ = j, Xð9Þ = k, Xð17Þ = l = P8kl P3jk Pij aP5 i (4.26)
for states i, j, k, and l = 0, 1, 2, 3, 4. How does one estimate this joint probability from a
Bayesian viewpoint? Note that this probability depends on the one-step transition matrix P
and its powers of order 8, 3, and 5. This probability will be estimated by
132 Bayesian Inference for Stochastic Processes
^ ½Xð5Þ = i, Xð6Þ = j, Xð9Þ = k, Xð17Þ = l = P
P ^ 8kl P
^ 3jk P
^ ij aP
^5 (4.27)
i
that is, the probability that the process begins at vertex 0 and is at 0 at time 5, moves to the
right at the next step, at time 9, is at vertex 2, and, at time 17, is at vertex 3. Suppose it is
assumed that the initial state is at vertex 0; thus, let a = (1, 0, 0, 0, 0). Using the matrix power
function of R, it can be shown that Bayesian estimates of the powers of P ^ are
0 1
: 0000000, : 4796177, : 1077132, : 1077132, : 33219956
B C
B : 4796177, : 0000000, : 3592352, : 1077132, : 08067757 C
B C
B C
^ 3 = B : 1077132, : 4796177,
P : 0000000, : 2961040, : 14380876 C
B C, (4.29)
B C
B : 1920002, : 1438088, : 3953308, : 0000000, : 29610404 C
@ A
: 4435222, : 1438088, : 1438088, : 2961040, : 00000000
0 1
: 06269902, : 42559064, : 13651139, : 13651139, : 28450488
B C
B : 42559064, : 06269902, : 31876879, : 13651139, : 10224748 C
B C
B C
^
P =B
5
: 42559064, : 06269902, : 23875887, : 18225740 C
B : 13651139, C, (4.30)
B C
B : 24333324, : 18225740, : 31876879, : 06269902, : 23875887 C
@ A
: 37984463, : 18225740, : 18225740, : 23875887, : 06269902
and
0 1
:3712193, :1560907, :2545221, :1772599, :1152173
B C
B :1359664, :3913436, :1370367, :1772599, :2327027 C
B C
B C
^ 8 = B :3375513, :1560907, :2881902, :1330784, :1593988 C
P B C: (4.31)
B C
B :2396826, :3129464, :1508060, :2109279, :1599465 C
@ A
:1806956, :3129464, :2097930, :1330784, :2377960
This is sufficient information to estimate the desired probability (Equation 4.27), namely,
P ^ 312 P
^ 823 P ^ 5 = ð:2387Þð:3592Þð:5769Þð:0626Þ = :00309
^ 01 aP (4.32)
0
Thus, the joint probability of the three events (going from the initial vertex 0 to the final
vertex 3, at times 5, 6, 7, and 19) is .00309.
Bayesian Inference for Discrete Markov Chains 133
Of course, different initial distributions a could have been used, resulting in different
probabilities of the event. Referring to the exercises at the end of the chapter, the student is
invited to explore the use of various initial distributions and their effect on the primary
event of interest described earlier. Also, left as an exercise is to develop a Bayesian test of the
hypothesis that P01 = :5 versus the alternative using the information in Section 2.5.3, and in
addition, to be left as an exercise is the prediction of future transitions from the cycle graph
process using information from Section 2.6.2.
Thus, the probability of going from nil risk to low risk (in a one-day period) is .118, and
the probability of remaining at a nil risk (over one day) is .575, etc. On the other hand, the
probability of a daily change from a nil risk to an extreme risk is only .026. It is interesting to
note that the probability of a daily change from an extreme risk to a nil risk is essentially 0,
to three decimal places. Of interest to the forest service is the long-term behavior of the
daily risk index; that is, what is the long-term chance of risk on a typical day in late
summer?
This will be answered by using R Code 4.2 to compute powers of the one-step transition
matrix P (Equation 4.33). Thus, consider powers 3, 10, 17, and 18:
0 1
:3317973 :1762260 :2353411 :2111096 :04552595
B C
B :3263579 :1753868 :2352439 :2160688 :04694271 C
B C
B C
P =B
3
B :2830784 :1922351 :2466504 :2293466 :04868947 C
C, (4.34)
B C
B :1579034 :1832159 :2798370 :3123858 :06665790 C
@ A
:1177433 :1654309 :2858074 :3532858 :07773251
134 Bayesian Inference for Stochastic Processes
0 1
:2643504 :1812413 :2518115 :2491008 :05349592
B C
B :2642635 :1812455 :2518332 :2491513 :05350655 C
B C
B C
P10 =B
B :2640283 :1812567 :2518919 :2492878 :05353532 C
C, (4.35)
B C
B :2625915 :1813257 :2522504 :2501214 :05371100 C
@ A
:2618765 :1813600 :2524288 :2505362 :05379840
0 1
:2636889 :1812730 :2519766 :2494847 :05357682
B C
B :2636880 :1812731 :2519768 :2494852 :05357692 C
B C
B C
P17 =B
B :2636856 :1812732 :2519774 :2494866 :05357722 C
C, (4.36)
B C
B :2636711 :1812739 :2519810 :2494950 :05357899 C
@ A
:2636639 :1812742 :2519828 :2494992 :05357987
and
0 1
:2636856 :1812732 :2519774 :2494866 :05357721
B C
B :2636852 :1812732 :2519775 :2494869 :05357727 C
B C
B C
P18 =B
B :2636839 :1812733 :2519778 :2494876 :05357742 C
C: (4.37)
B C
B :2636764 :1812736 :2519797 :2494919 :05357834 C
@ A
:2636727 :1812738 :2519806 :2494941 :05357880
This demonstrates that the day 17 and day 18 probabilities of a change agree to at least
four decimal places and implies that the long-run probability of risk in late summer is as
follows: nil, .2636; low, .18127; moderate, .25197; high, .24984; and extreme, .05257.
Of course, the three long-run probabilities of Table 4.3 are somewhat misleading because
the one-step transition matrix P (Equation 4.34) gives only an estimate of the transi-
tion probabilities. What should be remembered is that these probabilities are based on
the number of observed transitions from one state to the other, which is not available.
Thus, I will generate transition counts corresponding to the transition probabilities of
Equation 4.33 with the R command:
> rmultinom(5,100,prob)
where prob = (.575., 118, .172, .109, .026) is the first row of the one-step transition matrix P
(Table 4.4).
TABLE 4.3
Long-Term Behavior of Risk of Forest Fire
Nil Low Moderate High Extreme
.2636 .1812 .2519 .2494 .0535
Bayesian Inference for Discrete Markov Chains 135
TABLE 4.4
Five Realizations of Forest Fire Index Risk
Transition R1 R2 R3 R4 R5
n11 60 64 65 61 57
n12 9 12 7 6 17
n13 16 12 11 20 17
n14 12 10 15 9 8
n15 3 2 2 4 1
Thus, for the first realization, there were 60 transitions over one day from a nil to a nil risk,
9 daily changes from a nil to a low risk, 16 daily changes from a nil to a moderate risk,
12 from a nil to a high risk, and 3 from a low to an extreme risk. One can see that the transition
counts do indeed follow the transition probabilities given by the first row of Equation 4.33.
The multinomial mass function for the transition counts is
2 3
j=5
Y Yj=5
n
f n11 , n12, n13, n14 , n15 p11 , p12 , p13, p14 , p15 Þ = 4n ! = n1j !5 p1j1j , (4.38)
j=1 j=1
j=5
X
where n = n1j is the total number of transition counts with initial fire index nil; the
j=1
j=5
X
transition probabilities are unknown; and p1j = 1. Assuming the improper prior density
j=1
h Yj=5 i
xðp11 , p12 , p13 , p14 , p15 Þ ∝ 1= j=1 p1j (4.39)
j=5
X
for 0 < p1j < 1, j = 1, 2, 3, 4, 5 and p1j = 1, it is seen that the posterior distribution of the
j=1
five transition probabilities is Dirichlet(n11 , n12 , n13 , n14 , n15 ) = Dirichlet(60,9,16,12,3).
Thus, the various posterior means are
and
Table 4.3. It is seen that the agreement is quite good. How do we construct credible intervals
for these parameters?
For P11 , it can be shown that (5027, .6934) is a 95% credible interval, where .5049 is the
2½ percentile and .694 is the 97½ percentile. In a similar manner (.04241, .15327) is a 95%
credible interval for P12 . The exercises at the end of this chapter will involve finding
credible intervals for the other transition probabilities for the evolution of the forest fire
index.
The following R command was used to compute the pth 100 percentile of the beta dis-
tribution with parameters alpha=shape1 and beta=shape2:
In particular for the posterior distribution of P11 , the following command was employed
to find the 97½ percentile, which gives an answer of .6934.
Also, one needs the posterior variance of the transition probabilities; thus, recall that if a
random variable has a beta distribution with parameters a and b, then its variance is ab=
½(a + b)2 (a + b + 1). Therefore,
VARðP11 jdataÞ = ð60Þð40Þ= ð60 + 40Þ2 ð60 + 40 + 1Þ = :002376237: (4.41)
We now develop a Bayesian method of predicting future transitions for the forest fire
index model with transition matrix P given by Equation 4.34. The Bayesian predictive
density is defined as follows:
Let m1j , j = 1, 2, 3, 4, 5, be the future transitions counts corresponding to the first row the
transition matrix P of Equation 4.33 and assume that the transition counts follow a multi-
nomial distribution with density
Yj=5 m
f ðm11 , m12 , m13 , m14 , m15 jpÞ = ½m ! =m11 , ! m12 , ! m13 , ! m14 , ! m15 ! j= p1j1j : (4.42)
That is, a multinomial mass function with parameters p = (p11 , p12 , p13 , p14, p15 ) and
Xj=5
m= m1j . Therefore, the posterior density of the transition probabilities P1j , j = 1, 2, 3, 4, 5,
j−1
is Dirichlet (n11 , n12 , n13 , n14 , n15 ) with density
h Yj=5 iYj=5 n1j −1
xðpjnÞ = GðnÞ= j=1 G n1j p
j=1 1j
, (4.43)
j=5
X j=5
X
where n = n1j and 1 = p1j .
j=1 j=1
The Bayesian predictive mass function of the m1j , j = 1, 2, 3, 4, 5, is
j=5
X
where m = m1j is the total number of transitions, m1j is the number of transitions from
j−1
state 1 to state j, and j = 1, 2, 3, 4, 5.
Here, E of Equation 4.44 denotes the expectation of the conditional mass function
(Equation 4.43) of the future transitions (given the transition probabilities) with respect to
the posterior distribution of the transition probabilities with density (Equation 4.43). It can
be shown that the predictive mass function (Equation 4.44) reduces to
gðm11 , m12 , m13 , m14 , m15 jn11 , n12 , n13 , n14 , n15 Þ =
h Yj=5 i hYj=5 Yj=5 i (4.45)
m ! GðnÞ j=1 G n1j + m1j = m
j=1 1j
! j=1
G n 1j G ð m + nÞ ,
j=5
X
where m = m1j is the total number of transitions, m1j is the number of transitions from
j−1
state 1 to state j, and j = 1, 2, 3, 4, 5.
Note that Equation 4.45 is the conditional mass function of the future transition counts
given the past transition counts. WinBUGS Code 4.5 generates 1000 observations from the
predictive mass function (Equation 4.45), where the posterior distribution of the transition
probabilities is the Dirichlet with parameters (60,9,16,12,3). This assumes that the prior
density of the transition probabilities is the improper prior given by Equation 4.39. The 100
transition counts are given by the list statement with matrix y. Note that the first vector of
predicted transition counts is (59,16,9,14,2), that is, the number of transitions from state 1
(nil) to state 1(nil) is 59, the number of predicted transitions from state 1(nil) to state 5
(extreme) is 2, etc. Also note the variation across the 100 prediction vectors of the counts of
the fire index.
alpha[1]<-60
alpha[2]<-9
alpha[3]<-16
alpha[4]<-12
alpha[5]<-3
for( i in 1:100){
y[i,1:5]~dmulti(p[i,1:5],100)
p[i,1:5]~ddirch(alpha[1:5])
}}
List(y = structure(.Data = c(
58.0,16.0,9.0,14.0,3.0,
69.0,8.0,7.0,15.0,1.0,
60.0,3.0,22.0,13.0,2.0,
138 Bayesian Inference for Stochastic Processes
77.0,4.0,9.0,8.0,2.0,
53.0,8.0,18.0,17.0,4.0,
48.0,8.0,26.0,16.0,2.0,
63.0,5.0,11.0,16.0,5.0,
64.0,8.0,21.0,7.0,0.0,
62.0,8.0,7.0,22.0,1.0,
70.0,6.0,9.0,13.0,2.0,
56.0,10.0,16.0,13.0,5.0,
52.0,13.0,17.0,15.0,3.0,
63.0,12.0,16.0,9.0,0.0,
58.0,3.0,20.0,15.0,4.0,
64.0,6.0,14.0,16.0,0.0,
64.0,9.0,19.0,7.0,1.0,
59.0,5.0,20.0,14.0,2.0,
64.0,7.0,14.0,13.0,2.0,
70.0,12.0,11.0,6.0,1.0,
59.0,7.0,3.0,27.0,4.0,
61.0,9.0,14.0,16.0,0.0,
72.0,7.0,15.0,6.0,0.0,
53.0,11.0,13.0,20.0,3.0,
63.0,8.0,14.0,11.0,4.0,
57.0,9.0,18.0,13.0,3.0,
68.0,13.0,11.0,6.0,2.0,
70.0,7.0,14.0,7.0,2.0,
47.0,18.0,12.0,14.0,9.0,
60.0,12.0,16.0,12.0,0.0,
58.0,8.0,12.0,14.0,8.0,
57.0,6.0,26.0,10.0,1.0,
71.0,10.0,6.0,11.0,2.0,
44.0,21.0,24.0,5.0,6.0,
63.0,10.0,16.0,4.0,7.0,
60.0,8.0,17.0,9.0,6.0,
65.0,6.0,12.0,15.0,2.0,
63.0,6.0,20.0,9.0,2.0,
52.0,12.0,28.0,7.0,1.0,
65.0,5.0,20.0,9.0,1.0,
47.0,11.0,25.0,15.0,2.0,
50.0,13.0,21.0,14.0,2.0,
61.0,2.0,16.0,15.0,6.0,
61.0,9.0,12.0,12.0,6.0,
71.0,2.0,15.0,9.0,3.0,
66.0,2.0,9.0,16.0,7.0,
69.0,10.0,13.0,6.0,2.0,
55.0,2.0,16.0,24.0,3.0,
61.0,14.0,14.0,11.0,0.0,
65.0,7.0,14.0,13.0,1.0,
53.0,2.0,27.0,9.0,9.0,
74.0,8.0,5.0,12.0,1.0,
63.0,10.0,13.0,14.0,0.0,
Bayesian Inference for Discrete Markov Chains 139
49.0,8.0,15.0,23.0,5.0,
80.0,5.0,4.0,6.0,5.0,
55.0,5.0,28.0,7.0,5.0,
58.0,10.0,16.0,14.0,2.0,
53.0,10.0,19.0,16.0,2.0,
69.0,7.0,13.0,7.0,4.0,
62.0,9.0,14.0,15.0,0.0,
67.0,5.0,16.0,11.0,1.0,
55.0,20.0,14.0,10.0,1.0,
58.0,6.0,19.0,16.0,1.0,
60.0,5.0,15.0,15.0,5.0,
61.0,10.0,16.0,10.0,3.0,
68.0,11.0,6.0,14.0,1.0,
57.0,10.0,21.0,9.0,3.0,
71.0,6.0,11.0,10.0,2.0,
55.0,15.0,14.0,8.0,8.0,
43.0,12.0,21.0,21.0,3.0,
70.0,3.0,13.0,14.0,0.0,
60.0,10.0,12.0,11.0,7.0,
45.0,14.0,10.0,21.0,10.0,
49.0,10.0,28.0,13.0,0.0,
51.0,8.0,22.0,15.0,4.0,
38.0,8.0,28.0,22.0,4.0,
68.0,5.0,14.0,12.0,1.0,
51.0,8.0,30.0,8.0,3.0,
62.0,8.0,21.0,9.0,0.0,
46.0,9.0,30.0,14.0,1.0,
63.0,9.0,19.0,8.0,1.0,
67.0,11.0,10.0,9.0,3.0,
67.0,8.0,12.0,11.0,2.0,
45.0,23.0,17.0,12.0,3.0,
54.0,18.0,12.0,9.0,7.0,
56.0,18.0,14.0,9.0,3.0,
63.0,7.0,14.0,10.0,6.0,
52.0,14.0,16.0,14.0,4.0,
55.0,8.0,10.0,19.0,8.0,
65.0,12.0,14.0,8.0,1.0,
67.0,3.0,12.0,15.0,3.0,
62.0,8.0,16.0,12.0,2.0,
60.0,12.0,20.0,7.0,1.0,
70.0,8.0,8.0,13.0,1.0,
54.0,8.0,19.0,14.0,5.0,
70.0,4.0,12.0,10.0,4.0,
50.0,9.0,15.0,23.0,3.0,
58.0,19.0,10.0,12.0,1.0,
54.0,8.0,8.0,27.0,3.0,
49.0,13.0,18.0,14.0,6.0,
56.0,6.0,17.0,18.0,3.0),
.Dim = c(100,5)))
140 Bayesian Inference for Stochastic Processes
The student will be asked to verify the list of predicted transition counts given by matrix y
of the preceding list statement in WinBUGS Code 4.5.
Consider the following test of hypotheses concerning the first row of the transition matrix
of the fire index sample:
H0 : P11 = :575, P12 = :118, P13 = :172, P14 = :109, P15 = :026 (4.46)
versus
How does one assign prior information to this case? A reasonable approach is to assign a
positive probability π0 for the null hypothesis and, for the alternative assign, a prior density
π1 z1 (P), where
∫ z1 ðPÞdP = 1: (4.48)
P : H1
Thus, π0 + π1 = 1, and it is seen that the prior probability of the alternative is π1 , and for
values of the alternative, z1 is the density of the continuous random vector P that expresses
the prior knowledge one has for the alternative hypothesis. Note that P = (P11 , P12, P13 , P14 ,
P15 ) is the first row of the transition matrix and P0 = (:575, :118, :172, :109, :026) is the
hypothesized value under the null hypothesis.
Let
where nobs = (n11 , n12 , n13 , n14 , n15 ) is the vector of observations with conditional mass
function z(nobs jP) and where z(nobs ) is the marginal mass function of the observations.
By letting
z1 ðnobs Þ = ∫ z1 ðPÞzðnobs jPÞdP, (4.50)
P≠P0
and the posterior probabilities of the null and alternative hypotheses can be expressed as
In order to compute the probability of the null and alternative hypotheses, the following
distributions are relevant.
Bayesian Inference for Discrete Markov Chains 141
First, the probability mass function of the observations given the unknown parameters is
multinomial
h Yj=5 iYj=5 n
zðnobs jPÞ = n ! = j=1 n1j ! P 1j ,
j=1 1j
(4.54)
j=5
X j=5
X
where P1j = 1 and n1j = n. Also, the prior density of unknown parameters under the
j=1 j=1
alternative is Dirichlet, namely,
2 0 1 3
j=5
X Yj=5 Yj=5 a1j −1
z1 ðPÞ = 4G@ a1j A= j=1 G a1j 5 j=1 P1j , (4.55)
j=1
j=5
X
where P1j = 1. To compute the posterior probability (Equation 4.52) of the null
j=1
hypothesis, relevant information required is nobs = (60,9,16,12,3), and for the parameters of
the prior I used a = (23,4:72,6:88,4:36,1:04). Now one can show that
and
z1 ðnobs Þ = :001114:
p0 = :184599; (4.57)
thus, the evidence suggests the null hypothesis is not true. The hypothesized values were
those used to generate various realizations (depicted in Table 4.4) from the fire index
example with transition matrix (Equation 4.33). The student will be asked to repeat this
hypothesis testing example using the second realization of Table 4.4; consequently, one
would expect a different (different from .18459) posterior probability of the null hypothesis.
Of course, the limiting probabilities of a stochastic process are related to the stationary
distribution of the process, and this will be explored in the next section.
where 0 < p < 1 and 0 < q < 1, then, it can be shown that the limiting distribution is given
by the vector
Also, it can be shown that the distribution of X(1) is given by qP = q. A vector π that
satisfied the set of equations πP = π sets the stage for the concept of a stationary distribution
of a Markov chain. The definition of a stationary distribution is as follows:
For a Markov chain with transition matrix P, the stationary distribution of the chain is
given by the vector π that satisfies
π = πP,
Bayesian inferences for the stationary probability vector π will be the principal topic of
this section. Consider the following example of a Markov chain with transition matrix
0 1
:45, :48, :07
B C
P=B C
@ :05, :70, :25 A, (4.61)
:01, :50, :49
where the three states represent the social class of a person, namely, 1 denotes lower class, 2
signifies middle class, 3 represents the upper class. The transition probabilities denote the
class mobility of a family member. Thus .48 is the probability a person with lower-class
parents will be a member of the middle class, while the probability is .07 that the person will
have a higher class occupation. See page 154 of Ross5 for additional details. The stationary
distribution π satisfies the following system of equations:
It can be shown that the solution is π1 = :07, π2 = :62, and π3 = :31; thus, in the long term,
7% will be in the lower class, 62% in the middle, and 31% in higher-class occupations. The
following R Code computes the stationary distribution of a Markov chain with a given
transition matrix mat:
Bayesian Inference for Discrete Markov Chains 143
R Code 4.3
mat<-matrix(c(.45,.48,.07,.05,.70,.25,.01,.50,.49),
nrow=3,ncol=3,byrow=TRUE)
Remember that in practice, what one knows are the transition counts of the chain, from
which the transition probabilities are computed; thus, in reality, the transition probabilities
(Equation 4.61) are only estimates.
In order to make Bayesian inferences, I will generate several realizations from the chain
which will provide one with transition counts, then using those counts as the sample
information, Bayesian inferences are possible. Table 4.5 portrays five realizations from a
multinomial distribution with three classes and probabilities (.05, .70, .25) for a total of
n = 200 outcomes. The following R Code was used to generate the five realizations from the
second row of the transition matrix (Equation 4.61) of the social mobility example. Note that
this routine generates samples from the appropriate multinomial distribution.
< rmultinom(5,100,prob)
where prob = (.05, .70, .250) is the second row of the one-step transition matrix P
(Equation 4.62).
Consider the second row of the transition matrix, then using the first realization, there are
14 transitions from a middle to a lower-class occupation, 139 people with middle-class
occupations and whose parents have middle-class occupations, and 47 people with higher-
class occupations and whose parents are middle class (Table 4.5).
Thus, for the first realization, there are 14 transitions from a middle- to a lower-class
occupation, 139 people with middle-class occupations and with parents that had middle-
class occupations, and 47 people with higher-class occupations and whose parents are
TABLE 4.5
Five Realizations for Social Mobility Study
Transition Count 1 2 3 4 5
n21 14 11 10 12 8
n22 139 128 148 141 157
n23 47 61 42 47 4
n11 98 82 86 86 81
n12 84 105 106 99 107
n13 18 13 8 15 13
n31 4 3 6 3 3
n32 99 102 101 99 109
n33 97 95 93 98 88
144 Bayesian Inference for Stochastic Processes
middle class. Notice the similarity from realization to realization as well as the variation.
For the first realization, one would estimate P21 by 14/200 = .07, P22 by 139/200 = .695, and
P23 by 47/200 = .235. I arbitrarily set n = 200, which should be a large enough sample size to
efficiently estimate the transition probabilities. How should the Bayesian estimate the sta-
tionary distribution of the social mobility example? Obviously, one needs estimates for all
the nine transition probabilities. Two sources of information are needed for the Bayesian
analysis, the information prior to the study (the prior density for the transition probabilities)
and the information from the sample, the transition counts of Table 4.5, expressed as a
multinomial mass function for the transition counts given the vector of transition proba-
bilities. Using an improper prior for the transition probabilities for the first row of P, the
prior density is
j=3
Y
xðP11 , P12 , P13 Þ ∝ P−1
1j , (4.63)
j=1
j=3
X
where for the first row of transition probabilities, P1j = 1.
j=1
Assume that the transition counts for the first row follow a multinomial distribution with
mass function
gðn11 , n12 , n13 jP11 , P12 , P13 Þ = ½200 ! =98 ! 84 ! 18 !P98 84 18
11 P12 P13 , (4.64)
j=3
X
where P1j = 1. Thus, by Bayes theorem, the posterior distribution of the transition
j=1
probabilities of the first row is Dirichlet(98,84,18). In a similar manner, the posterior dis-
tribution of the transition probabilities of the second row is Dirichlet(14,139,47), and for the
third is Dirichlet(4,99,97). This is sufficient information to provide estimates of the transition
probabilities. See page 91 of Degroot6 for the formulas for the moments of the Dirichlet
distribution.
Consider first estimating the transition probabilities and stationary distribution via Bayes
theorem. Based on the first realization for the social mobility example, I will generate
samples from the posterior distribution of the nine transition probabilities as well as the
posterior distribution of the stationary distribution. Refer to Equation 4.62, and then in
general, the solution (π1 , π2 , π3 ) is the stationary distribution of the mobility example.
The constraint is imposed by solving an associated system of equations:
x2 = ½P32 ð1 − P11 Þ + P12 P31 =½P32 P21 − P31 ðP22 − 1Þ, (4.66)
WinBUGS Code 4.6 generates the posterior distribution of the transition probabilities,
and the stationary distribution and the code statements are similar to those expressed by
Equations 4.66 and 4.67. Thirty-five thousand observations are generated from the posterior
distribution with a burn-in of 500.
model;
{
# transition probabilities social mobility
p11~dbeta(98,102)
p12~dbeta(84,116)
p13~dbeta(18,182)
p21~dbeta(14,186)
p22~dbeta(139,61)
p23~dbeta(47,153)
p31~dbeta(4,196)
p32~dbeta(99,101)
p33~dbeta(97,103)
x2<-(p32*(1-p11)+p12*p31)/(p32*p21-p31*(p22-1))
x3<-(1-p11-p21*x2)/p31
tot<-1+x2+x3
# stationary distribution
pi1<-(1/tot)
pi2<-x2*(1/tot)
pi3<-x3*(1/tot)
TABLE 4.6
Posterior Distributions for the Social Mobility Example
Parameter Mean SD Error 2 1/2 Median 97 1/2
P11 .4903 .0353 .0002103 .4219 .4901 .5589
P12 .4199 .0347 .0002319 .353 .4194 .4886
P13 .0897 .0201 .000127 .0544 .0883 .1329
P21 .0699 .0179 .0001153 .0386 .0684 .1089
P22 .6953 .0326 .0001996 .6296 .6958 .7577
P23 .2349 .0299 .000188 .1788 .2342 .2956
P31 .0200 .0098 .0000624 .0055 .0184 .0134
P32 .4947 .0353 .000249 .4254 .495 .5636
P33 .4885 .0355 .000211 .4162 .4854 .5555
π1 .0955 .0224 .000144 .0565 .0939 .1446
π2 .6103 .0282 .000180 .5557 .6102 .6661
π3 .2942 .0368 .000237 .2212 .295 .3645
π2 sample: 24501
10.0
P(π2)
0.0
FIGURE 4.2
Posterior density of π2 .
0 1
1=6, 1=3, 0, 0, 1=2, 0
B C
B 0, 1, 0, 0, 0, 0, C
B C
B C
B 0, 0, 0, 0, 3=4, 1=4 C
B C
P=B C: (4.68)
B 1, 0, 0, 0, 0, 0, C
B C
B C
B 4=5, 0, 0, 1=5, 0, 0 C
@ A
0, 0, 1=2, 0, 1=2
Thus, the probability that state 1 communicates with itself is 1/6, while the probability of
going from state 3 to state 5 is 3/4, etc.
The R Code 4.4 develops a transition graph that shows the partitioning of the six states
into three communication classes (Figure 4.3).
R Code 4.4
library(igraph)
P<-matrix(c(1/6,1/3,0,0,1/2,0,
++ 0,1,0,0,0,0,
++ 0,0,0,0,3/4,1/4,
++ 1,0,0,0,0,0,
++ 4/5,0,0,1/5,0,0,
++ 0,0,1/2,0,1/2,0),nrow=6,ncol=6,byrow=TRUE)
> g<-[Link](P,weighted=TRUE)
> plot(g)
2
1
FIGURE 4.3
Transitions into three classes.
148 Bayesian Inference for Stochastic Processes
For example, for this chain, the probability of a transition from state 1 to state 2 is 1/3, but
once the state is in state 2, it stays there; thus, 2 is an absorbing state. When all the states of a
chain form one communicating class, the chain is called irreducible. A communicating class
is closed if it is impossible to transition to a state outside of the communicating class.
where one can easily show that each state communicates with each of the other two. The
corresponding transition graph is represented by Figure 4.4 and demonstrates that the
chain is irreducible. The graph was executed using a suitable modification of R Code 4.4.
One thousand observations were generated from the chain with transition matrix P
(Equation 4.80). Using only those simulations starting with the 3 state, I found the following
number of transitions from the conditional distribution of the third row of P. There were 0
transitions from 3 to 1, 76 transitions from 3 to 2, and 175 transitions from 3 to state 3; thus,
the fraction of 3 to 2 transitions is 76/251 = .302, and for 3 to 3, the fraction is 175/251 = .697.
Note that based on the third row of P, P32 = 1=3 (compared to .302) and P33 = 2=3 (com-
pared to .697), and it appears that the Markov chain simulation is believable. Another way
to generate observations from the conditional distribution is to assume a multinomial
distribution with parameters 0, 1/3, 2/3 and use the R Code
FIGURE 4.4
Transitions for irreducible chain.
Bayesian Inference for Discrete Markov Chains 149
prob<-c(0,1/3,2/3)
> rmultinom(3,100,prob)
which produces three multinomial realizations with parameter vector (P31 , P32 , P33 ) (Table
4.7).
Bayesian inferences are made the usual way: (1) assume that the distribution of the
transition counts of Table 4.7 is a multinomial with unknown parameter vector (P31 , P32 , P33 ),
(2) assign a uniform prior distribution to these three unknown parameters, and (3) deter-
mine the parameters of the posterior Dirichelt distribution of (P31 , P32 , P33 ). Using the first
realization of Table 4.7 and assigning the uniform prior to the unknown parameters result
in a Dirichlet posterior with parameter vector (1, 31,71). Thus, the marginal posterior mean
vector of (P31 , P32 , P33 ) is (1/103, 31/103, 71/103) = (.0097, .3009, .6893). Are these reasonable
estimates? The following WinBUGS Code pertains to estimating the transition probabilities
for the third row of the transition probability matrix and is executed with 35,000 observa-
tions for the simulation and 5,000 for the burn-in.
model;
The posterior distributions of P32 and P33 appear to be symmetric about the posterior
mean and the MCMC errors imply the simulation was successful for estimating the pos-
terior means (Table 4.8). Note that estimation of P31 could have been ignored because it is
TABLE 4.7
Three Multinomial Realizations
R1 R2 R3
P31 0 0 0
P32 30 27 28
P33 70 70 72
TABLE 4.8
Posterior Distribution of Transition Probabilities of Irreducible Chain
Probability Mean SD Error 2 1/2 Median 97 1/2
P31 .00972 .009502 .00004776 .000251 .006879 .006879
P32 .3012 .04501 .0002719 .2176 .2998 .3932
P33 .6895 .04561 .000249 .5955 .691 .7745
150 Bayesian Inference for Stochastic Processes
known to be zero. Was the information in the first realization sufficient to accurately esti-
mate the transition probabilities P32 and P33 ? It will be left as an exercise to execute the
Bayesian estimation of these two transition probabilities based on the other two realizations
of Table 4.7.
As a last example, consider the random walk with state space {1, 2, …, N} and transition
matrix
0 1
1, 0, 0, 0:::::::::0
B C
B q, 0, p, 0, ::::::0 C
B C
B C
B 0, q, 0, p, 0, ::::0 C
B C
B C
B: C
B C
B C
B
P = B: C, (4.70)
C
B C
B: C
B C
B C
B 0, 0, 0, ::::::0, p, 0 C
B C
B C
B 0, 0, 0, :::::q, 0, p C
@ A
0, 0, 0, ::::::0, 0, 1
where 0 ≤ p ≤ 1, 0 ≤ q ≤ 1, p + q = 1.
Notice that the walker starts at state x, where x = 2, 3, 4, 5, 6, 7, or 8, and the walker stops
walking when x = 1 or when x = 9.
The probability of moving to the right one step is p = .5, and the probability of moving to
the left is also .5. The states of 1 and 9 represent absorbing states, that is, the walker stops
moving when x = 1 or x = 9. It is seen from the graph and the transition matrix that there are
three communicating classes: {1}, {2,3,4,5,6,7,8}, and {9}.
where from 1, the chain either returns to state 1 in one step, or first moves to 2 and then
returns to 1 at the second step. From 1, the chain revisits 1 with certainty.
On the other hand, for the chain that begins with 2, the chain first moves to 1, and it may
continue to revisit 1 for many steps, but finally will return to 2, because the probability that
it will remain at 1 forever is the chance that it repeatedly transitions from 1 to 1, which is the
probability of the limit as n ! ∞,
Now consider the case where the process starts in state 3; then the chain may revisit 3 in
successive steps but with positive probability will eventually be in state 1 or 2; thus, from
state 3, there is a positive chance that the chain that starts in 3 will never revisit 3, and this
probability is ¾ = 1 − (1/4).
It is easily seen that 1 is a recurrent state; that is, it will occur an infinite number of times
with certainty. For example, consider a simulation of 200 transitions, starting with state 1
(Table 4.9).
How well does the simulation follow the first row of the transition matrix, where one
would expect 1/3 of 200 transitions to be from state 1 to state 1, 2/3 from state 1 to state 2,
and 0 from state 1 to state 3? How many times does the chain revisit state 1? It is revisited
120 times out of 200. Of course, we know that 1 is a recurrent state. Also, of course, states 1
and 2 form a communicating class. A similar situation exists with state 2, which is also
recurrent; on the other hand, state 3 is transient; thus, of interest is a simulation of 200
transitions starting with state 3 (Table 4.10).
It is seen that state 3 is revisited only once, since once the transition to the state 2 occurs, it
is impossible the chain will return to state 3. Recall that a state is transient if there is a
positive probability the chain that starts with state 3, never returns to 3.
For the Bayesian, it would be of interest to test the hypothesis H: P31 = 1=4, P32 = 1=2,
P33 = 1=4 versus the alternative that H is not true.
The data will be based on simulating realizations from the multinomial with parameter
vector (1/4, 1/2, 1/4); thus, one is interested in determining if the generated values actually
came from the appropriate transition probabilities for the third row of P (Equation 4.72).
This corresponds to the conditional distribution of the chain with initial value X(0) = 3. This
is left as an exercise for the student. Refer to Section 2.5.3 for relevant information on testing
hypotheses from a Bayesian viewpoint.
One last topic to consider is a Bayesian estimator of the average return time (to a par-
ticular state) of an irreducible Markov chain. The analysis is based on the relationship
TABLE 4.9
Initial Value 1 with 200 Transitions
1212112121212121211211212121212121121
1121212111111112111212111212121211212
1212112121212121121211121121212112121
2111212121121111212112121212121212112
1212121212112112121211211211121211212
1112121212112121
TABLE 4.10
Initial Value 3:200 Transitions
3321211212121211112111212111121112121
2121121121212121121112121212112121212
1212121212121121212111121121212112121
2111212121112121212121212111211212121
2112121211212121212121212112121121211
2121112111112112
152 Bayesian Inference for Stochastic Processes
between the stationary probability πj (of the stationary distribution π of the chain) to the
average number of steps between visits to state j. To be more precise, let
and let
μj = E Tj Xð0Þ = jÞ (4.73)
be the expected return time to state j, and then it can be shown that μj is finite and that
πj = 1=μj (4.74)
and
X
m=n−1
πj = limð1=nÞ Pm
ij : (4.75)
m=0
Recall that the stationary distribution of the chain is determined by solving a linear
system of equations involving the transition probabilities Pij of the chain; thus, the Bayesian
analysis is easily executed once one knows the posterior distribution of these transition
probabilities. See page 103 of Dobrow2 for the details on the verification of Equation 4.84.
Recall the example of determining the stationary distribution of an irreducible chain
involving the transition matrix
0 1
:45, :48, :07
B C
P=B C
@ :05, :70, :25 A, (4.61)
:01, :50, :49
with three states 1, 2, and 3, where state 1 denotes lower class; 2, middle class; and 3, upper
class. This is an example of social mobility, where .48 is the probability of moving from the
lower to the middle class in one generation. The Bayesian estimation of the stationary
distribution was based on Equations 4.66 and 4.67, which expressed the stationary prob-
abilities in terms of the one-step transition matrix (Equation 4.61). Data for this example
were generated via the multinomial distribution (see Table 5.4) and WinBUGS Code 4.6,
which is used to execute the Bayesian analysis reported in Table 5.5. In order to estimate the
first return times of the three states of the example of social mobility, the following code was
amended to WinBUGS Code 4.6:
mui1<-1/pi1
mui2<-1/pi2
mui3<-1/pi3
with Table 4.11 reporting the Bayesian estimation of the first return times. An improper
prior was used for the prior distribution of the transition probabilities. See Equation 4.61.
Bayesian Inference for Discrete Markov Chains 153
TABLE 4.11
First Return Times for Social Mobility Example
Parameter Mean SD Error 2 1/2 Median 97 1/2
μ1 11.1 2.766 0.01619 6.91 10.68 17.69
μ2 1.642 0.0762 0.0004363 1.501 1.639 1.799
μ3 3.454 0.4639 0.00269 2.744 3.387 4.518
Therefore, the posterior mean for the average return time to the lower class is 11.1 gen-
erations, 1.642 for the middle class, and 3.454 generations for the upper class. This appears
plausible and is reflected in the transition matrix (Equation 4.61). It should be remembered
that for each row of the transition matrix, the data were generated assuming a multinomial
distribution, and then assuming an improper prior, the posterior distribution was Dirichlet
for each row and, hence, for each cell a beta posterior density.
The average first return times are estimated with the following R program:
R Code 4.5
And the average return time to state 1 is computed as 11.85714, which is the usual average
based on a run of 10,000 simulations. Note how much more informative the Bayesian
analysis is as reported in Table 4.11. For example, in addition to the posterior mean (one’s
estimate of the return time), the posterior standard deviation, posterior median, and the
95% credible interval are given. See page 106 of Dobrow2 for additional information about
using R to estimate the average return times of the states of a Markov chain.
This section is concluded noting that recurrence and transience are class properties; that
is, for a communicating class, all the states are recurrent or all are transient. For additional
154 Bayesian Inference for Stochastic Processes
information about recurrence, see Section 3.5.4. Also, it is important to remember that for
an irreducible finite chain, all the states are recurrent.
where Pnii is the n-step transition probability that the chain will return to state i in n time
units. Thus, it is possible for the chain to return to state i in multiples of d(i). Consider the
chain with states 1, 2, 3, and 4 and transition matrix
0 1
0, :5, 0, :5
B C
B :5, 0, :5, 0 C
B C
P=B C, (4.77)
B 0, :5, 0, :5 C
@ A
:5, 0, :5, 0
then each state has period 2. Consider state 1, then the chain can return to 1 by first going to
state 2, then returning to 1, or it can first go to 2, then 3, then 4, and then return to 1, for a
total of four transitions. The greatest common divisor of 2 and 4 is 2. Of course, there are
other paths of returning to state 1, but they are multiples of 2. The following R statements
generate the graph in Figure 4.5. Using the R matrix power code, it can be shown that all
powers of P (Equation 4.61) are P, that is,
Pn = P, n = 1, 2, 3, :::
FIGURE 4.5
Transition graph of chain with period 2.
Bayesian Inference for Discrete Markov Chains 155
Therefore, in particular
This further confirms that the period of state 1 is 2, and of course, the period of the other
three states is also 2.
R Code 4.6
P<-matrix(c(0,.5,0,.5,
.5,0,.5,0,
0,.5,0,.5,
.5,0,.5,0),nrow=4,ncol=4,byrow=TRUE)
g<-[Link](P,weighted=TRUE)
plot(g)
0 1
0, 48, 0, 52
B C
B 48, 0, 52, 0 C
B C
Q=B C, (4.79)
B 0, 52, 0, 48 C
@ A
47, 0, 53, 0
and from this, one can verify that the corresponding estimated transition matrix is
0 1
0, :48, 0, :52
B C
B :48, 0, :52, 0 C
^B C
P=B C:
B 0, :52, 0, :48 C
(4.80)
@ A
:47, 0, :53, 0
156 Bayesian Inference for Stochastic Processes
0 1
:4748, 0, :5252, 0
B C
B 0, :5008, 0, :4992 C
^2 B C
P =B C,
B :4752, 0, :5248, 0 C
(4.81)
@ A
0, :5012, 0, :4985
0 1
:47501, 0, :5249899, 0
B C
B 0, :50009978, 0, :4990003 C
^4 B C
P =B
B :4750090, :5249901, 0
C,
C
(4.82)
@ A
0, :50000995, 0, :499005
and it can be shown that higher even powers of P ^ are essentially the same as P
^ 2 ; thus, since
^ 2
all the even powers of P are the same, it is sufficient to estimate only P11 .
Estimation will be done via the Bayesian approach, which is to estimate the probability
that the chain returns to state 1 in two transitions.
Consider the first row of P211 , and then generate 100 observations to complete these four
cell counts. Assuming the transition counts follow a multinomial distribution with mass
function
j=4
Y
f ðn11 , n12 , n13 , n14 j P211 , P212 , P213 , P214 Þ = ½100 ! =n11 !, n12 !, n13 !, n14 ! P21j , (4.83)
j=1
j=4
X j=4
X
where P21j = 100 and n1j = 100, the 100 cell counts were generated using the R
j=1 j=1
function rmultinom(1,100,prob) with prob=c(.53,0,.47,0), and the resulting realization is
n11 = 54, n12 = 0, n13 = 46, n14 = 0. This implies that the marginal distribution of n11 is
binomial (100, P211 ) with mass function
!
100 n11 100−n11
f ðn11 jP211 Þ = P211 1 − P211 , (4.84)
n11
Using WinBUGS to execute the Bayesian analysis, I generated 35,000 observations for the
MCMC simulation, with a burn-in of 5,000 observations and a refresh of 100 with the results
shown in Table 4.12.
Thus, the posterior mean is .5351, and the 95% credible interval is (.5254, .5449), which
implies that state 1 has period 2. That is to say, the credible interval indicates that P211 > 0.
Because higher even powers of the matrix P^2 do not change, one would expect the Bayesian
analysis for Pn11 , n = 4, 6, ::: to be the same as that portrayed in Table 4.12; thus, one is
confident that state 1 has period 2. Also, shown in the table are the posterior mean and
median which implies a symmetric posterior density for P211 .
WinBUGS Code 4.7 generates the Bayesian analysis:
WinBUGS Code 4.7
model;
{
for ( i in 1:100){
p[i]~dbin(p11,100)}
p11~dbeta(1,1)
}
list(
p = c(
56.0,53.0,48.0,55.0,50.0,
50.0,60.0,47.0,61.0,57.0,
56.0,49.0,48.0,55.0,54.0,
56.0,58.0,59.0,61.0,51.0,
50.0,48.0,43.0,52.0,51.0,
57.0,55.0,57.0,47.0,56.0,
56.0,54.0,60.0,50.0,53.0,
59.0,53.0,50.0,53.0,55.0,
50.0,58.0,47.0,61.0,56.0,
54.0,60.0,43.0,50.0,52.0,
57.0,57.0,60.0,53.0,63.0,
49.0,46.0,52.0,56.0,59.0,
58.0,54.0,46.0,51.0,49.0,
61.0,48.0,50.0,57.0,55.0,
57.0,59.0,51.0,43.0,58.0,
58.0,55.0,53.0,56.0,58.0,
46.0,56.0,54.0,52.0,53.0,
46.0,44.0,50.0,56.0,59.0,
49.0,50.0,57.0,57.0,53.0,
60.0,44.0,56.0,53.0,53.0))
TABLE 4.12
Posterior Analysis for the Period of State 1
Parameter Mean SD Error 2 1/2 Median 97 1/2
The list statement contains the data of 100 values generated from a binomial distribution
with parameters (.54, 100), and the code shows a beta uniform prior placed on the unknown
parameter P211 .
where (π1 , π2 , :::, πk ) is the stationary distribution, and Pij is the one-step transition proba-
bility. Such processes have no directional bias, such as a random walk where the chain
moves one unit to the right with probability q and one unit to the left with probability 1 − q
with q = 1/2. If q > 1/2, the chain exhibits a bias that propels the process to the right, and the
process has a directional bias. Time reversibility, as defined by Equation 4.85, implies a
process such that its behavior in the future is the same as the process moving backwards;
one cannot tell the difference.
Such processes invite many inferential challenges. For example, given the data from a
finite, irreducible, and aperiodic Markov chain, is the process time reversible? In practice,
the data would consist of transition counts of the chain, from which one can estimate the
one-step transition probabilities and stationary distribution. For the Bayesian, our main
interest will be in determining if the chain is time reversible, where inferences will be either
the posterior estimation of the parameters
Two examples are described, where the first involves a chain which is known to be not
time reversible, while the other will be a chain which is time reversible. Consider the
example of social mobility described in Section 4.4 with the transition matrix
0 1
:45, :48, :07
B C
P=B C
@ :05, :70, :25 A : (4.61)
:01, :50, :49
In this example, the posterior distribution of the stationary transition was determined
using the data from Table 4.5, WinBUGS Code 4.6, and the results appearing in Table 4.6.
Bayesian Inference for Discrete Markov Chains 159
TABLE 4.13
Bayesian Analysis for Time Reversibility of Social Mobility
Parameter Mean SD Error 2 1/2 Median 97 1/2
z12 −.00253 .005433 .0000322 −.01347 −.00249 .00817
z13 .02171 .00522 .0000324 .01181 .02161 .03218
z23 −.00173 .0282 .000167 −.05476 −.00261 .05587
The data consist of realizations generated from the multinomial distribution with 200
observations for each row of Equation 4.61. An improper prior distribution (Equation 4.64)
induces a Dirichlet posterior distribution for each row and a beta posterior for each tran-
sition probability. WinBUGS Code 4.6 contains Equations 4.66 and 4.68 for determining
the stationary distribution of the chain. In order to specify the posterior distribution of the
relevant parameters zij , a slight modification of the WinBUGS Code is necessary. The
modified code appears as WinBUGS Code 4.8. I used 35,000 observations for the simula-
tion, with a burn-in of 5,000. The relevant parameters are denoted by d11,d12, and d13, and
the posterior analysis is reported in Table 4.13.
model;
{
p11~dbeta(98,102)
p12~dbeta(84,116)
p13~dbeta(18,182)
p21~dbeta(14,186)
p22~dbeta(139,61)
p23~dbeta(47,153)
p31~dbeta(4,196)
p32~dbeta(99,101)
p33~dbeta(97,103)
x2<-(p32*(1-p11)+p12*p31)/(p32*p21-p31*(p22-1))
x3<-(1-p11-p21*x2)/p31
tot<-1+x2+x3
pi1<-(1/tot)
pi2<-x2*(1/tot)
pi3<-x3*(1/tot)
d12<-pi1*p12-pi2*p21
d13<-pi1*pi3-pi3*p31
d23<-pi2*p23-pi3*p32
}
For the most part, the posterior distributions appear symmetric about the posterior mean.
It is interesting to note that the 95% credible interval for z13 excludes zero. Is this chain time
reversible?
160 Bayesian Inference for Stochastic Processes
TABLE 4.14
Posterior Analysis for a Time-Reversible Chain
Parameter Mean SD Error 2 1/2 Median 97 1/2
z12 −.00369 .01212 .000067 −.02767 −.00360 .01987
z13 −.04937 .00967 .0000578 −.06842 −.04941 −.03036
z23 −.00362 .01228 .0000649 −.02744 −.00362 .00694
P12 .4602 .03516 .0002931 .3921 .4599 .5285
P13 .5403 .03513 .0000235 .4707 .5402 .6088
P21 .5747 .03479 .000185 .5066 .5748 .6429
P22 .2046 .02857 .000164 .1515 .204 .2631
P23 .2198 .02933 .000157 .1647 .219 .2798
P31 .4752 .03545 .0002102 .4053 .4751 .5448
P32 .175 .02685 .0001583 .1255 .1738 .2309
P33 .3496 .03368 .0001988 .2856 .3488 .4174
π1 .3432 .01183 .000063 .3195 .3434 .3658
π2 .2812 .01903 .0001176 .2443 .2809 .3185
π3 .3757 .02516 .0001478 .3265 .3758 .4249
The second example involves a transition matrix of a chain which is time reversible. See
example 3.22 on page 115 of Dobrow,2 where the transition matrix is
0 1
0, 2=5, 3=5
B C
P=B C
@ 1=2, 1=4, 1=4 A : (4.86)
1=2, 1=6, 1=3
It can be verified the chain is time reversible. In order to perform the Bayesian analysis,
multinomial observations will be generated for each row of Equation 4.86, then based on
these realizations, the estimated transition probabilities and estimated stationary distri-
bution will be determined using WinBUGS Code 4.8. Using the improper prior the posterior
distribution of the transition probabilities, stationary distribution, and the time-reversible
parameters zij will be available and reported in a way similar to Table 4.13.
Two hundred multinomial observations are generated for each row of Equation 4.87 to
give the transition count matrix Q, where
0 1
0, 92, 108
B C
Q=B C
@ 115, 41, 44 A : (4.87)
95, 35, 70
The Bayesian analysis is executed with WinBUGS Code 4.9 with 5,000 observations for
the simulation, a burn-in of 5,000, and a refresh of 100. The posterior analysis is reported in
Table 4.14.
p12~dbeta(92,108)
p13~dbeta(108,92)
p21~dbeta(115,85)
p22~dbeta(41,159)
p23~dbeta(44,156)
p31~dbeta(95,105)
p32~dbeta(35,165)
p33~dbeta(70,130)
x2<-(p32*(1-p11)+p12*p31)/(p32*p21-p31*(p22-1))
x3<-(1-p11-p21*x2)/p31
tot<-1+x2+x3
pi1<-(1/tot)
pi2<-x2*(1/tot)
pi3<-x3*(1/tot)
d12<-pi1*p12-pi2*p21
d13<-pi1*pi3-pi3*p31
d23<-pi2*p23-pi3*p32
and the main parameters of interest, the zij , i < j, are estimated with the posterior median as
−.00360, −.04941, and −.00362, respectively. Also, the posterior distribution of these
parameters is evidently symmetric about the posterior mean, and their 95% credible
intervals imply that the chain is time reversible. In order to show the uncertainty when
using a smaller sample size for the multinomial realization, the example is repeated with a
much smaller sample size of 50 (smaller than 200) for each row of Equation 4.86. The
multinomial realizations for the three rows of the transition matrix (Equation 4.86) is por-
trayed in matrix
0 1
0, 21, 29
B C
R=B C
@ 28, 10, 12 A: (4.89)
23, 11, 16
TABLE 4.15
Posterior Analysis for a Time-Reversed Chain: Size 50 Multinomial Realizations
Parameter Mean SD Error 2 1/2 Median 97 1/2
z12 −.01573 .0244 .000116 −.01538 .03106 .03106
z13 −.0456 .0192 .0000892 −.08319 −.04577 −.00811
z23 −.0145 .02565 .000119 −.06306 −.01498 .03805
π1 .3382 .02407 .000106 .2886 .3391 .383
π2 .2818 .03643 .000182 .2125 .2812 .3548
π3 .3801 .04833 .000232 .2854 .3798 .4742
162 Bayesian Inference for Stochastic Processes
The Bayesian analysis is reported in Table 4.15 and should be compared to the results in
Table 4.14. The latter analysis is based on realizations of size 50, whereas the results of the
former posterior analysis is based on realizations of size 200.
Comparing Tables 4.14 and 4.15, one sees that the posterior means are approximately the
same, but that the posterior standard deviations are much smaller for Table 4.14, and as a
consequence, the 95% credible intervals are wider for Table 4.15. Overall, the conclusion
about time reversibility based on Table 4.15 would be about the same to those based on
Table 4.14. The student will be asked as an exercise to repeat the analysis with multinomial
simulations of size 20 and compare those results to those in Table 4.15. Will the Bayesian
analysis imply time reversibility?
Our next phase of inference for time reversibility is to test the null hypothesis H0 : zij = 0
versus H1 : zij ≠ 0, where zij = πi Pij − πj Pji , i, j = 1, 2, :::, k.
First, consider z12 = π1 P12 − π2 P21 and a test of
H0 : z12 = 0 versus H1 : z12 ≠ 0, (4.90)
where the test is based on the data generated with 200 multinomial observations for each
row of the transition matrix (Equation 4.87), and the Bayesian analysis is recorded in
Table 4.13. Note that the posterior mean and standard deviation are
Eðz12 jdataÞ = −:00253
and
sðz12 jdataÞ = :005433, respectively
Therefore, I will assume that z12 e normal(μ, s2 ), where μ = −:00253 and s2 = :000029517.
Using WinBUGS Code 4.8, one can show that the density of z12 appears to be in the shape of
a normal density; thus, for the purpose of testing H0 versus H1 , it is assumed that z12 is
indeed normally distributed.
For reviewing the Bayesian approach to testing hypotheses, the reader is referred to
Section 2.5.3. For the Bayesian approach, it is assumed that z e normal(μ, s2 ), where μ e
normal(0, n2 ), and n2 is known; thus, the test will be described as
H0 : μ = 0 versus H0 : μ ≠ 0 (4.91)
The Bayesian test is implemented by computing the posterior probability of the null and
alternative hypotheses. The test is based on the predictive density of z = π1 P12 − π2 P21 ,
where z e normal(μ, s2 ) and μ e normal(0, n2 ); therefore, the predictive density is
where r0 is the prior probability of the null hypothesis, r1 is the prior probability of the
alternative hypothesis, and r0 + r1 = 1. In addition, the prior density of μ under the alter-
native is
h pffiffiffiffiffiffiffiffii
f ðμÞ = 1= 2πn exp − 1=2n2 μ2 , (4.93)
and
h pffiffiffiffiffi i
f ðzjμÞ = 1= 2πs exp 1=2s2 ðz − μÞ2 , (4.94)
Bayesian Inference for Discrete Markov Chains 163
TABLE 4.16
Posterior Probability of Time Reversibility
n w0
1 .9991
3 .99801
5 ?
10 ?
100 .9979
.0024 .9931
is the conditional density of g given μ. Thus, it can be shown that the predictive density is
h pffiffiffiffiffi i qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi 2
f ðzÞ = r0 1= 2πs exp −1=2s2 z2 + r1 ns= 2πðs2 + n2 Þ exp −1= 2 s2 + n2 z (4.95)
h pffiffiffiffiffi i
w0 = r0 1= 2πs exp 1=2s2 z2 ÷ f ðzÞ : (4.96)
Using the information from Table 4.15, z = −:01573 and letting r0 = r1 = :5, the posterior
probability w0 of the null hypothesis is computed for various values of n, the standard
deviation of the prior distribution for μ, and is reported in Table 4.16. I am assuming that s
and n are known. For example, when n = 3, the probability of null hypothesis (time
reversibility) is .99801. This is not surprising since the observed value of the parameter that
measures time reversibility is −.01573 with a standard deviation of 0.0244. It is seen that the
evidence is very strong for the conclusion that the chain is time reversible, regardless of
what is used for the prior distribution of μ (Equation 4.93) under the alternative. The reader
is invited to verify the values of w0 in Table 4.16 and to complete the entries designated by
“?” I used Equation 4.96.
The effect of n on w0 is negligible!
0 1
1, 0, 0, 0, ::::0, 0, 0
B C
B q, 0, p, 0, :::0, 0, 0 C
B C
B C
B 0, q, 0, p, 0, :::, 0 C
B C
B C
P=B
B:
C
C (3.69)
B C
B 0, 0, 0, 0, :, 0, p, 0 C
B C
B C
B 0, 0, 0, 0, :, q, 0, p C
@ A
0, 0, 0, 0, ::::, 0, 1
where the gambler begins with capital k dollars (the process is at state k) and wins $1 with
probability p and loses $1 with probability q = 1 − p. When the gambler’s stake is 0 (the
process is at state 0), the gambler has lost all, or the gambler can win the total pot of N
dollars (the process is in state N). There are three communicating classes f0g, f1, 2, :::, N − 1g
and fNg; that is, 0 communicates only with 0, N communicates only with N, and the
remaining N − 1 states communicate only with each other, but not with 0 or N. The states 0
and N are called absorbing states.
There are many interesting aspects of the dynamics of the gambler’s ruin problem,
including (1) the probability the gambler either wins total capital of N or loses all capital and
(2) the average length of time in order to win or lose all capital. For the Bayesian, the
objective is to find the posterior distribution of the probability that the gambler wins the
total pot of N or the posterior distribution that the gambler loses all. Also of interest is
estimating the average time to win the total pot of N dollars.
For the first objective, it will be assumed that p has a particular value, then using the
multinomial distribution, the transition counts will be generated for the second row of the
transition matrix; thus, the cell count for cell (1,2) will have a binomial distribution with
parameters n = 200 and p. Assuming an improper prior for p induces a beta posterior 3 the
gambler is ruined is given by
h i
ak = ðq=pÞN − ðq=pÞk = ðq=pÞN − 1 , p ≠ q : (3.86)
Thus, our objective is to determine the posterior distribution of ak , which is the probability
that the gambler is ruined, given the gambler began with a stake of k dollars. Since this
probability is a function of p, N, and k, the posterior distribution of p induces the posterior
distribution of ak .
Assuming N = 5, k = 2, and p = .6, 200 multinomial observations were generated from the
second row of Equation 3.69 with the following vector of cell counts (94, 0, 106, 0, 0, 0); thus,
assuming an improper prior for p, the posterior distribution of p is beta(106, 94). Using
WinBUGS Code 4.10, the posterior analysis is executed with 35,000 observations and a
burn-in of 5,000, and the results are reported in Table 4.17.
TABLE 4.17
Bayesian Analysis for Gambler’s Ruin
Parameter Mean SD Error 2 1/2 Median 97 1/2
ak .527 .0843 .000434 .3653 .5268 .6906
P .5298 .0350 .000129 .4611 .53 .5979
Bayesian Inference for Discrete Markov Chains 165
Thus, the probability of the gambler’s ruin is estimated as .527 with the posterior mean, a
posterior standard deviation of 0.0843, and a 95% credible interval of (.3653, .6906). The
multinomial observation vector (94, 0, 106, 0, 0, 0) was generated assuming p = .6; thus, the
posterior mean of .5298 somewhat underestimates the value of p used to generate the cell
counts. The right end point of .5979 of the 95% credible interval is barely less than p = .6. Of
course, with another realization, one would expect somewhat different results for the
posterior analysis.
Consider the five realizations for the second row of the transition matrix using 200
observations and p = .6 (Table 4.18).
These five realizations would result in different posterior analyses compared to the one
reported in Table 4.17, and the student will be asked to execute those analyses as exercises at
the end of the chapter.
One remaining topic to be presented is to estimate the average duration of play for the
gambler. Pages 24–30 of Bailey7 present important information about the gambler’s ruin
problem which includes the derivation of the following formula for expected duration of
the gambler’s play. Suppose the gambler begins with capital k and that N is the total pot,
then the average duration of play (until a total loss of capital or winning the total pot N) is
given by
h i
dk = k=ðq − pÞ − N=ðq − pÞ 1 − ðq=pÞk = 1 − ðq=pÞN : (4.97)
The Bayesian analysis is based on the realization (94, 0, 106, 0, 0, 0) of the second row of
the transition matrix and executed with WinBUGS Code 4.10 (refer to the line in the code
starting with dk) assuming N = 5 and k = 2. The posterior analysis generated 35,000
TABLE 4.18
Five Multinomial Realizations for Gambler’s Ruin
1 2 3 4 5
P10 76 78 72 78 84
P11 0 0 0 0 0
P12 124 122 128 122 116
P13 0 0 0 0 0
P14 0 0 0 0 0
P15 0 0 0 0 0
166 Bayesian Inference for Stochastic Processes
TABLE 4.19
Bayesian Analysis for Average Duration of Gambler’s Ruin
Parameter Mean SD Error 2 1/2 Median 97 1/2
ak .5274 .0838 .000405 .3647 .5275 .6897
dk 6.033 0.0875 0.000452 5.784 6.067 6.098
P .5297 .0350 .000169 .4613 .5298 .598
TABLE 4.20
Posterior Distribution of the Gambler’s Ruin
Parameter Mean SD Error 2 1/2 Median 97 1/2
P .6099 .03427 .000189 .5415 .6104 .676
q24 .00729 .001492 .0000082 .004593 .007221 .01044
observations for the simulation with a burn-in of 5,000, and the results are reported in
Table 4.19.
Therefore, the average duration of play for the gambler is 6.033 moves, with a posterior
standard deviation of 0.0875, and a 95% credible interval of (.5784, 6.098). It appears that the
posterior distribution of dk is symmetric about the posterior mean. Exercises at the end of
the chapter will ask the student to repeat the Bayesian analysis with several realizations
from Table 4.18 and various values of N and k.
One last topic to be presented is that of estimating the probability distribution of the
gambler’s ruin at trial n. Let qkn be the probability that the gambler will lose their stake at
trial n beginning with capital k at the start of the gamble, then it can be shown that
!
n
qkn = ðk=nÞ pðn−kÞ=2 qðn+kÞ=2 , 1 < k < N − 1, n > 1, (4.98)
ðn − kÞ=2
where q0n = qNn = 0 for n ≥ 1, while for n = 0, q00 = 1 and qk0 = 0. Also, (n − k)/2 must be an
integer in the interval [0,n]. Equation 4.98 was derived by Bailey (pages 31–34).7
I executed the Bayesian analysis with 35,000 observations for the simulation and a burn-in
of 5,000. Assuming n = 4 and k = 2, the posterior distribution for p and q24 is reported in
Table 4.20. The prior distribution for p is assumed to be improper, and I used the second
realization from Table 4.18, implying that the posterior distribution of p is beta(122, 78).
Thus, when the gambler is at the fourth bet (has a $4 stake), the probability of the
gambler’s ruin is estimated as .007221 with the posterior median of .0729, a posterior
standard deviation of 0.001492, and a 95% credible interval of (.004593, .01044).
it will rain tomorrow, etc.? The transition matrix (Equation 4.7) is used to generate future
realizations using the R function Markov. Bayesian inferences consist of testing the
hypothesis P11 = :7, which is the actual value used to generate samples from the chain.
Assuming an improper prior for P11 , the posterior distribution of P11 is beta, and it is shown
that the posterior probability of the null hypothesis is P0 = :98. The Bayesian predictive
mass function was derived and used to forecast future observations for the transition counts
of the chain. WinBUGS Code 4.3 was used to generate the future observations.
Next to be considered is how to compute the n-step transition probabilities from the one-
step transition matrix. This computation was illustrated with the random walk and
implemented with the R function matrixpower, which computes the nth power of the one-
step transition matrix P. Multinomial simulations are used to generate transition counts for
the one-step transition matrix, which in turn provides estimates of the one-step transition
matrix of the random walk. The function matrix power then computes the sixth step
transition matrix with entries that estimate the sixth step transition matrix. Assuming an
improper prior for the one-step transition matrix, and assuming multinomial distributions
for the cell counts of each row of P, it is known that the distribution of each row of P is
Dirichlet. The challenge for the Bayesian is to determine the posterior distribution of the
entries of the sixth power of P. Section 4.3 is concluded with a specification of the Bayesian
estimate of a joint probability of several random variables of the chain involving times 5, 6,
9, and 17 of the process.
Section 4.4 emphasizes the limiting distribution of a chain and is illustrated with the forest
fire index example. The R function matrix power computes the limiting distribution of the
chain by computing higher and higher powers of the one-step transition matrix P. If the
limiting distribution exists, the entries of higher powers of P will stabilize. Bayesian
inferences consist of testing hypotheses about the fire index transition matrix and predicting
future observations with the Bayesian predictive density.
If a chain has a stationary distribution, it is of interest to be able to estimate it from sample
data. If one knows the one-step transition matrix P, and if a stationary solution exists, it is
known to be the solution of a system of linear equations. The primary goal of this section
was to provide estimates of the stationary distribution, and this was illustrated with the
social mobility example. For information from the data, multinomial realizations were
generated for each row of the chain, then assuming an improper prior, the marginal pos-
terior distribution of each transition probability is determined to be a beta. The system of
equations in Equation 4.61 determines the stationary distribution as a function of the nine
cell entries of P. WinBUGS Code implements the Bayesian estimation of the stationary
distribution, and the results are reported in Table 4.6. Also, an R program was used to
compute the stationary distribution of the chain and compared to the Bayesian results.
Section 4.6 introduces the idea of a transfer graph which is a representation of a Markov
chain. The R package igraph is employed to implement such graphs and provides one with
additional information about the behavior of the process. The section includes a discussion
of Bayesian inferences for irreducible chains; that is, those where all the states communicate,
that is, there is only one class. Bayesian inferences are demonstrated with the 3 × 3 irre-
ducible chain with transition matrix (Equation 4.70). Specifically, the entries of the third row
of the chain are estimated with the Bayesian paradigm in the usual way with multinomial
observations generated for the third row, and the results are reported in Table 4.8.
It is well known that there are two types of states in a Markov chain, transient and recurrent;
such states are defined in Section 4.6.3. Example of a chain with both states is the one with
three states and transition matrix (Equation 4.71). It is easy to show that 1 and 2 are recurrent,
but that 3 is transient. Realizations generated via the R function Markov illustrate that 3 is
168 Bayesian Inference for Stochastic Processes
transient and that 1 is recurrent. For the Bayesian analysis, tests of hypotheses about the third
row of the transition matrix are carried out. The social class example (Equation 4.61) with
three states is irreducible and employed to illustrate the average return time to a particular
state. The goal for the Bayesian is to estimate those average return times, and WinBUGS Code
4.6 is executed for the posterior analysis with the results reported in Table 4.11.
Section 4.7 explains the Bayesian approach to making inferences about the period of state
of a Markov chain. The example has transition matrix (Equation 4.7) where it is known that
each state has period 2. The problem for the investigator is to test the hypothesis that the
period of, say, state 1 is period 2. This is a very interesting example of Bayesian inference!
The posterior analysis is reported in Table 4.12.
Time reversibility is the subject of Section 4.8 and is an interesting property of those
chains that exhibit it. Such chains demonstrate the same behavior whether looking into the
future or going backward to the past. The concept is defined, and two examples are
explored: one where it is known that there is no time reversibility and the other where there
is time reversibility. When time reversibility is present for a three-state chain, there are three
conditions that must be satisfied. Therefore, the Bayesian approach is to test the hypothesis
that the chain is time reversible. One assumes that the chain is irreducible and uses the
Bayesian approach to testing hypotheses, see Section 2.5.3. Using the stationary distribution
of the chain is essential, and WinBUGS Code 4.9 implements the analysis, and the posterior
analysis is reported in Table 4.16.
Lastly, the chapter concludes with the Bayesian approach to estimating the absorbing
states of a Markov chain. The basic idea of absorbing states is well illustrated with the
gambler’s ruin problem, where there are three communicating classes: {1}, the gambler has
lost all; {N}, the gambler has won the pot; and the rest is {2, 3, …, N − 1}. The two absorbing
states are 1 and N, where N = 5 and k = 2 (the initial capital), and the Bayesian analysis
consists of estimating the probability that the gambler will lose and estimate the average
duration of the game. See Tables 4.19 and 4.20 for reports of the posterior analysis.
Bayesian inference for Markov chains is an active area of interest, and what follows are
several references that are applicable to the presentation given here. When using Jeffrey’s
prior for the inference of a Markov chain, Assodou and Essebbar8 provide an interest-
ing perspective. With regard to time-reversible chains, see Diaconis and Rolles,9 and if you
are interested in a general account of Bayesian inference for Markov chains, refer to
Eichelsbacher and Ganesh10 as well as the book by Insua, Ruggeri, and Wiper.11 Also of
interest is the relation between Markov chains and associated decision problems, and
Martin12 details the relationship. The empirical Bayes approach to inference is not taken in
this book; however, it is adopted by Meshkani and Billard,13 who explain the subtleties of
that method. Lastly, Welton and Ades14 deal with the important topic of using partially
observed data to estimate the transition probabilities of a Markov chain. For a more com-
plete list of Bayesian inference for Markov chains, see pages 78–81 of Insua, Ruggeri, and
Wiper.11
Bayesian Inference for Discrete Markov Chains 169
4.11 Exercises
8. Duplicate the five multinomial realizations appearing in Table 4.4 of the first row
of the transition matrix in Equation 4.33 using a total count of 100.
9. For the forest fire index example, consider the test of the hypothesis H0 : P11 =
:755, P12 = :118, P13 = :172, P14 = :109, P15 = :026; based on Equations 4.49 through
4.58, show that the posterior probability of the null hypothesis is P0 = :1845.
10. Refer to the probability transition matrix in Equation 4.61, the social mobility
example, and using R Code 4.3, verify the stationary distribution as π =
(:0623, :6234, :3141). In the long term, what is the probability that a person will be
in the middle class?
11. a. Using the first realization for the social mobility example (Table 4.5) and
assuming the improper prior distribution in Equation 4.63 for the first row
of the transition probability matrix P in Equation 4.61, show that the pos-
terior distribution of the first row is Dirichlet(98, 84, 18).
b. Based on the third realization reported in Table 4.5, show that the posterior
distribution of the first row is Dirichlet(86, 106, 8).
c. What are the implications for having two different Dirichlet distributions for
the posterior distribution of the first row of P?
12. Refer to the social mobility example with transition matrix P in Equation 4.61.
Based on WinBUGS Code 4.6 and generating 40,000 observations for the simu-
lation with a burn-in of 5,000, execute a Bayesian analysis for the stationary dis-
tribution of the chain. Refer to Table 4.6. Your results should be similar.
13. Using R Code 4.4, verify the transition graph in Figure 4.3. You will need to
download the package “igraph” to the R platform.
14. Based on the transition graph in Figure 4.4, explain why the chain in Equation 4.69
is irreducible.
15. Based on the first multinomial realization (Table 4.7) of the third row of the chain
in Equation 4.69 and assuming an improper prior distribution for the third row of
Equation 4.70, do the following:
a. Show that the posterior distribution probabilities of the third row are as
follows:
16. Refer to the Markov chain with transition probability matrix in Equation 4.72.
a. Show that states 1 and 2 are recurrent.
b. Show that state 3 is transient.
c. Using the R function Markov, generate 200 observations from the chain with
matrix in Equation 4.73 and initial value of 1.
d. How does the simulation of item c compare to that appearing in Table 4.9?
17. Verify Equation 4.74 for the average return time to a particular state.
18. Refer to the chain with transition matrix in Equation 4.61, the irreducible chain of
the social mobility example.
a. Execute the Bayesian analysis with WinBUGS Code 4.6 using the informa-
tion reported in Table 5.4. Perform the Bayesian analysis with 35,000
observations and a burn-in of 5,000.
b. Verify the results of Table 4.11, which reports the Bayesian analysis for the
first return times for each of the three states (in lower, middle, and higher
social classes).
c. Are the results of Table 4.11 reasonable? Explain in detail and justify your
answer.
d. Explain why R Code 4.5 computes the average return time to the states of a
Markov chain.
e. Compare the Bayesian estimate of the average return time (reported in Table
4.11) to that computed by WinBUGS Code 4.8.
19. Refer to the transition probability matrix in Equation 4.77.
a. Show that state 1 has period 2.
b. Using the igraph package with R Code 4.6, generate the transition graph of
the chain in Equation 4.77. Your results should look like Figure 4.5.
c. Does the graph show that each state has period 2? Why?
20. Based on the entries of the estimated transition matrices of P in Equation 4.80,
namely, P^2 (Equation 4.81) and P^4 (Equation 4.82), is the period of each state of P of
period 2?
21. Verify the Bayesian analysis reported in Table 4.12 of the 1-1 element of the two-
step transition matrix P2 . Do the results imply that each state of the chain in
Equation 4.17 is of period 2? Explain your answer in detail.
22. The time reversibility of a Markov chain is defined by Equation 4.85. Does the
Bayesian analysis reported in Table 4.13 support the conjecture that the chain is
time reversible?
23. Explain how the posterior probability w0 of the null hypothesis in Equation 4.91 of
time reversibility is computed. In your answer, refer to Equations 4.92 through
4.96.
172 Bayesian Inference for Stochastic Processes
References
1. Markov, A. A. 1906. Rasprostranenie zakona bol’shih chisel na velichiny, zavisyaschie drug ot
druga. Izvestiya Fiziko-matematicheskogo obschestva pri Kazanskom universitete, 2-ya seriya 15:135–156.
2. Dobrow, R. P. 2016. Introduction to Stochastic Processes with R. New York: John Wiley & Sons.
3. Diaconis, P. 2007. Dynamical bias in coin tossing. SIAM Review 49(2):211–235.
4. Martell, D. L. 1999. A Markov chain model of day to day changes in the Canadian Forest Fire
Weather Index. International Journal of Wildland Fire 9(4):265–273.
5. Ross, S. 1996. Stochastic Processes. New York: John Wiley & Sons.
6. DeGroot, M. H. 1970. Optimal Statistical Decisions. New York: McGraw-Hill.
7. Bailey, N. T. J. 1964. The Elements of Stochastic Processes. New York: John Wiley & Sons.
8. Assodou, S., and Essebbar, B. 2003. A Bayesian model for Markov Chains via Jeffrey’s prior.
Communications in Statistics: Theory and Methods 32:2163–2184.
9. Diaconis, P., and Rolles, S. 2006. Bayesian analysis for reversible Markov chains. Annals of Statistics
34:1270–1292.
10. Eichelsbacher, P., and Ganesh, A. 2002. Bayesian inference for Markov chains. Journal of Applied
Probability 39:91–99.
11. Insua, D. R., Ruggeri, F., and Wiper, M. P. 2012. Bayesian analysis of Stochastic Process Models. New
York: John Wiley & Sons.
12. Martin, J. J. 1967. Bayesian Decision Problems and Markov Chain. New York: John Wiley & Sons.
13. Meshkani, M. R. and Billard, L. 1992. Empirical Bayes estimators for a finite Markov chain.
Biometrika 79:185–193.
14. Welton, N. J., and Ades, A. E. 2005. Estimation of Markov chain transition probabilities and rates
from fully and partially observed data: Uncertainty propogation, evidence synthesis and model
calibration. Medical Decision Making 25:633–645.
5
Examples of Markov Chains in Biology
5.1 Introduction
Bayesian inferential techniques will be employed to gain a deeper understanding of the
mechanism of various biological phenomena. Several examples will illustrate the Bayesian
approach to making inferences: (1) an example of inbreeding in genetics; (2) the general
birth and death process; (3) the logistic growth process; (4) a simple model for an epidemic;
(5) the chain binomial model and Greenwood and the Reed–Frost versions of the epidemic
models; (6) several genetic models, including the Wright model; and (7) the Ehrenfest model
for diffusion through a membrane.
Bayesian inferences will include determining the posterior distribution of the relevant
parameters, testing hypotheses about those parameters, and determining the Bayesian
predictive distribution of future observations. Such Bayesian procedures will closely follow
those presented in Chapter 4 and will comprise generating simulations from the chain,
displaying the associated transition graph for the chain of each example, and employing the
appropriate R Code and WinBUGS Code for the analysis.
173
174 Bayesian Inference for Stochastic Processes
crossing of brother and sister will be of one type. (b) Now suppose the parents are type 2,
namely, AA × Aa, and the offspring will occur in the following proportions: 1/2 AA and
1/2 Aa; therefore, the crossing of brother and sister will be 1/4 type {AA × AA}, 1/2 type
{AA × Aa}, and 1/4 type {Aa × Aa}. (c) Lastly, if the parents are of type Aa × Aa, the off-
spring are in the proportion of 1/4 type AA, 1/2 type Aa, and 1/4 type aa; thus, brother
and sister mating will give 1/16 type {AA × AA}, 1/4 type {AA × Aa}, 1/4 type {Aa × Aa},
1/4 type { Aa × aa}, 1/8 type {AA × aa}, and 1/16 type {aa × aa}. It can be shown that the
transition matrix is
0 1
1, 0:0, 0:0, 0:0, 0:0, 0:0
B C
B 1=4, 1=2, 1=4, 0, 0, 0:0 C
B C
B C
B 1=16, 1=4, 1=4, 1=4, 1=8, 1=16 C
B C
P=B C: (5.1)
B 0:0, 0:0, 1=4, 1=2, 0:0, 1=4 C
B C
B C
B 0:0, 0:0, 1:0, 0:0, 0:0, 0:0 C
@ A
0:0, 0:0, 0:0, 0:0, 0:0, 1:0
R Code 4.1
> markov <- function(init,mat,n,labels) {
+ if (missing(labels)) labels <- 1:length(init)
+ simlist <- numeric(n+1)
+ states <- 1:length(init)h
+ simlist[1] <- sample(states,1,prob=init)
+ for (i in 2:(n+1))
+ { simlist[i] <- sample(states,1,prob=mat[simlist[i-1],]) }
+ labels[simlist]
+}
> P<- 1matrix (c(.51,.49,.49,.51),nrow=2,ncol=2,byrow=TRUE)
> init<=c(1,0)
For example, with a starting value of 1 (AA × AA) and n = 100, the Markov function
markov(init,P,n) produces the realization
1111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111
1 1 1 1 1,
Examples of Markov Chains in Biology 175
21111111111111111111111111111111111111111111111111
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1, 1 1
1.
When studying the behavior of the chain in Equation 5.1, additional information is
available by viewing the corresponding transition graph, which is implemented with R
Code 5.1:
R Code 5.1
library(igraph)
P<-matrix(c(1,0,0,0,0,0,
1/4,1/2,1/4,0,0,0,
1/16,1/4,1/4,1/4,1/8,1/16,
0,0,1/4,1/2,0,1/4,
0,0,1,0,0,0,
0,0,0,0,0,1), nrow=6, ncol=6, byrow=TRUE)
> g<-[Link](P,weighted=TRUE)
> plot(g)
Refer to Figure 5.1, which clearly shows that states 1 and 6 are absorbing and positive
recurrent, but that the remaining are transient. Once the process is in one of the states 2, 3, 4,
or 5, there is a positive probability that the process will be absorbed.
4 3 2
6
1
FIGURE 5.1
Markov process for inbreeding.
176 Bayesian Inference for Stochastic Processes
TABLE 5.1
Five Realizations for Inbreeding Example
R1 R2 R3 R4 R5
n31 2 1 0 0 0
n32 1 2 1 3 2
n33 3 3 5 3 4
n34 2 1 2 1 2
n35 0 2 0 2 2
n36 2 1 2 1 0
For the Bayesian analysis, five multinomial realizations of size 10 of the third row of P are
generated with the R command: multinom(5,10,prob), where prob<-c(1/16,1/4,1/4,1/
4,1/8,1/16), and the results reported in Table 5.1.
The realizations of Table 5.1 will be used as the sample information for the Bayesian
analysis of estimating the transition probabilities of the third row of P; thus, it will be
necessary to assign a prior distribution to these unknown parameters. Consider the
improper prior density
j=6
Y
xðP31 , P32 , P33 , P34 , P35 , P36 Þ ∝ P−1
3j , (5.2)
j=1
j=6
X
where P3j = 1 and 0 < P3j < 1, j = 1, 2, 3, 4, 5, 6.
j=1
Using the first realization, it can be shown that the posterior distribution of the P3j ,
j = 1, 2, 3, 4, 5, 6 is Dirichlet with parameter (2,1,3,2,0,2).
Recall the interpretation of the states of this chain: For example, consider the parents with
type Aa × Aa, then their offspring will occur with frequencies 1/4 AA, 1/2 Aa, and 1/4 aa.
Consequently, the brother–sister mating will produce 1/16 of type 1 (AA × AA), 1/4 of type
2 (AA × Aa), 1/4 of type 3 (Aa × Aa), 1/4 of type 4 (Aa × aa), 1/8 of type 5 (AA × aa), and,
finally, 1/16 of type 6 (aa × aa). Note that these frequencies correspond to the third row of P
and are dictated by the laws of inheritance.
Our main objective for the Bayesian analysis is to estimate the six transition parameters
P3j , j = 1, 2, 3, 4, 5, 6. The Bayesian analysis is executed with WinBUGS Code 5.1 using
35,000 observations for the simulation with a burn-in of 5,000:
TABLE 5.2
Posterior Analysis of Inbreeding Example
Parameter Mean SD Error 2 1/2 Median 97 1/2
P31 .1998 .1215 .000713 .02789 .1782 .489
P32 .09442 .08948 .000489 .00281 .07413 .3354
P33 .2998 .1378 .000788 .0756 .2859 .5975
P34 .2006 .1209 .000726 .02912 .1799 .4863
P35 0 0 0 0 0 0
P36 .1991 .12 .000700 .0279 .1786 .482
P3: .999 .266 .001358 .5284 .9823 1.559
versus the alternative that H0 is not true. H0 is the hypothesis implied by the law of
inheritance for the offspring of brother–sister mating whose parents are of type 3, namely,
Aa × Aa. Therefore, one needs to compute the posterior probability of the null hypothesis.
I will use the first multinomial realization of Table 5.1 for the sample information; thus, let
The conditional mass function of the observations n given the unknown parameters P3 is
the multinomial mass function
2 3
j=6
Y j=6
Y n
f ðnjP3 Þ = 4n3: ! = n3j !5 P3j3j , (5.3)
j=1 j=1
178 Bayesian Inference for Stochastic Processes
j=6
X
where P3j are probabilities and P3j = 1. Note that for the first realization of Table 5.1,
j=1
n31 = 2, n32 = 1, n33 = 3, n34 = 2, n35 = 0, n36 = 2, and the transition count total is n3: = 10.
Recall that the posterior probability of the null hypothesis is
where
and
ð
gðnÞ = π1 xðP3 Þf ðnjP3 ÞdP3 : (5.5)
Also, π0 is the prior probability of the null hypothesis and π1 = 1 − π0 , the prior prob-
ability of the alternative. Also x(P3 ) is the prior density of P3 under the alternative
hypothesis. How should the prior density under the alternative be selected? I assume that
the prior density under the null hypothesis is Dirichlet with parameter (a1: , a2 , a3 , a4 , a5 ,
a6 ) = (1.25, 5, 5, 5, 2.5, 1.25), which gives the prior mean under the alternative as
(.0625,.25,.25,.25,.125,.0625).
One can show that
ð
xðP3 Þf ðnjP3 ÞdP3
82 3 0 1 9 8 0 19
< j=6
Y j=6
X Xj=6 =<Yj=6 j=6
Y j=6
X =
= 4n ! = n3j !5G@ aj A G n3j + aj + 1 n ! G aj G@ n3j + aj + 1 A
: j=1 j=1 j=1
; : j=1 3j j=1 j=1
;
(5.6)
In addition, it can be shown that z(n) = :000280001 and, consequently, that p0 = :9999;
thus, the data support the inbreeding probabilities implied by the laws of inheritance.
respectively. The genes of successive generations are selected with replacement inducing a
Markov chain fX(n) = 0, 1, 2, :::, 2Ng, where X(n) is the number of type a genes. The
transition matrix is given by
2N k 2N−k
Pr½Xðn + 1Þ = kjXðnÞ = j = pj qj , j, k = 0, 1, 2, :::, 2N: (5.8)
k
Thus, the conditional distribution of X(n + 1)jX(n) is binomial with parameters 2N and pj .
For additional information about the biology of this process, see Fisher.6 It is obvious that 0
and 2N are absorbing states; that is, if X(n) = 0, there are no type a genes, and when X(n) = 2N,
there are 2N type a genes. An interesting question is that of fixation; that is, assuming an
initial state of i type a genes, what is the probability that the process will be all type a genes
or all type A genes? The rate of approach to fixation is also something to be explored.
A more realistic model takes into account the possibility of mutations; therefore, prior to
the formation of a new generation, each gene has a chance to mutate. The model incor-
porating mutation is as follows: The probability of mutation a ! A is denoted by a1 and the
probability of mutation A ! a is a2 . As in the previous model, assume that the composition
of the next generation is determined by 2N independent trials according to the binomial
model in Equation 5.8. Assume that the parent population has j-type a genes, where the
probability of a type a gene is
pj = ð j=2N Þð1 − a1 Þ + ð 1 − j=2N Þa2 , (5.9)
Thus, the transition matrix for the model that takes into account mutation is given by
Equation 5.8, where the pj and qj , j = 0, 1, 2, :::, 2N, are defined by Equations 5.9 and 5.10,
respectively. It is assumed that the mutation forces act first, after which a new gene is
specified by selecting at random from the population. It should be observed that the chance
of selecting a type a gene is 1/2N times the number of type a genes; therefore, the average
probability of selecting an a-type gene is 1/2N times the average number of a genes which is
j(1 − a1 ) + (2N − j)a2 , which in turn implies Equation 5.9.
Note that the probabilities in Equations 5.9 and 5.10 of the transition matrix in Equa-
tion 5.8 depend on the unknown mutation rates a1 and a2 ; thus, the goal of the Bayesian
analysis will be to estimate these mutation rates and to test hypotheses about these
unknown parameters. One must generate an observation for the process with the 1 × 7 first
row of the transition matrix:
To generate the observations, a value for a2 must be assigned. Note that the first row of
the transition matrix in Equation 5.8 depends only on a2 ; thus, our approach is to generate
180 Bayesian Inference for Stochastic Processes
multinomial realizations for the first row of the transition matrix. Assuming that the
mutation rate for A ! a is a2 = :07, the first row probabilities are
Then, in a similar way, generate realizations for the seventh row of the transition matrix.
The components of the 1 × 7 seventh row will only depend on a1 , namely,
a61 , 6ð1 − a1 Þa51 , 15ð1 − a1 Þ2 a41 , 20ð1 − a1 Þ3 a31 , 15ð1 − a1 Þ4 a21 , 6ð1 − a1 Þ5 a1 , ð1 − a1 Þ6
(5.12)
= :000001, :000054, :001215, :01458, :098415, :354294, :531441,
when a1 = :1.
Our goal is to estimate the mutation rates, based on multinomial realizations for the first
and seventh rows of the transition matrix in Equation 5.8.
Consider the first row of the transition rule; then the following R Code is used to generate
multinomial realizations of size 100 for the mutation example:
> p<-c(.647,.299,.05498,.005518,.000311,.000009,.0000001)
> rmultinom(5,100,p)
The usual way to estimate a2 is to let 68/100 = .68 = (1 − a2 )6 , which implies the estimate
is a2 = :06223, which is quite close to the value of .07 used to generate the realizations of
Table 5.3. What is the Bayesian approach to estimating a2 ? It will be indirect as follows. Let
P0j , j = 0, 1, 2, :::, 6, be the transition probabilities for the first row of the transition matrix in
Equation 5.8, where
P00 = ð1 − a2 Þ6 : (5.13)
Suppose that the prior distribution for the first row is improper.
Then, the posterior distribution for the first row is Dirichlet with parameter (68,28,3,1,0,0,0)
and the marginal posterior of P00 is beta (68, 72). I executed the Bayesian analysis with
WinBUGS Code 5.2 using 35,000 observations for the simulation with a burn-in of 5,000,
and the posterior analysis is reported in Table 5.4.
TABLE 5.3
Multinomial Realizations for Mutation Example
R1 R2 R3 R4 R5
68 67 65 62 63
28 27 27 34 35
3 4 7 3 2
1 2 1 1 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
Examples of Markov Chains in Biology 181
TABLE 5.4
Posterior Analysis for the Mutation Rate a2
Parameter Mean SD Error 2 1/2 Median 97 1/2
a2 .06251 .01069 .0000687 .04309 .06192 .08524
p00 .6802 .04613 .000296 .5859 .6814 .7677
The posterior mean for mutation A ! a with rate a2 is .06251 with a 95% credible interval
of (.043,.085), and the posterior density appears to be symmetric about the mean, as seen
from Figure 5.2. Also, the distribution appears to be normally distributed in appearance,
which is an attribute that should be taken into account for testing hypotheses about a2 . The
student will be asked to perform a similar posterior analysis for estimating the rate a1 for
the mutation a ! A. It is interesting to note that the credible interval for a2 does contain .07,
the value used to generate the data, the first realization in Table 5.3.
One can show that if a1 a2 > 0, then the fixation will not occur in any state, and the reader
will be asked to investigate the fixation question by performing a Bayesian analysis.
Selection is another genetic force that should be taken into account, and the topic is
presented on page 57 of Karlin and Taylor.7 Suppose the selection forces are in favor of, say,
the a-type gene; that is, suppose we want to impose a selection advantage of a-type genes
over A-type genes, in such a way that the selected number of offspring have an expectation
proportional to 1 + s and 1, respectively, where s is small and positive. Thus, in the binomial
transition matrix (Equation 5.8), pj and qj given by Equations 5.9 and 5.10, respectively, are
replaced by
α2sample: 30001
40.0
P(α2)
20.0
0.0
α2
FIGURE 5.2
Posterior density of a2 .
182 Bayesian Inference for Stochastic Processes
and
qj = 1 − pj = ð2N − jÞ=ð2N + sjÞ, (5.15)
respectively.
It can be shown that if the parent population consists of j type a genes and 2N − j type A
genes, the next generation will on the average have 2Npj type a genes and 2Nqj type A
genes. Also, at the (n + 1) generation, the ratio of the expected size of the population of type
a genes to type A genes is
where r = [number of a-type genes in the nth generation ÷ number of type A genes in the nth
generation].
For the Bayesian, the main goal is to estimate the selection force s involved in the binomial
probabilities in Equations 5.14 and 5.15 of the binomial transition matrix (Equation 5.8).
It can be shown that the second row of the transition matrix is
P10 = :1328, P11 = :3188, P12 = :3187, P13 = :17, P14 = :05099, P15 = :008158,
(5.17)
P16 = :000544
The Bayesian approach will generate a multinomial realization for the second row of the
transition matrix; then using those as data to form the likelihood function, the selection
force s will be estimated assuming the improper prior density
j=6
Y j=6
X
xðP1 Þ ∝ P−1
1j , 0 < P1j < 1, P1j = 1, (5.18)
j=0 j=0
Consider
P10 = ½5=ð6 + sÞ6 = :1328 (5.20)
Examples of Markov Chains in Biology 183
TABLE 5.5
Five Multinomial Realizations of Selection Force s = 1
R1 R2 R3 R4 R5
n10 15 15 13 16 7
n11 26 33 29 37 31
n12 35 27 37 26 44
n13 17 18 14 15 13
n14 6 2 6 6 4
n15 1 5 1 0 1
n16 0 0 0 0 0
Now solving Equation 5.20 for s gives s = .99999634. What is the Bayesian approach to
estimating s? The first five multinomial realizations for the second row of the transition
matrix will be performed with a total of n = 100 counts as revealed in Table 5.5. The fol-
lowing R Code was employed to generate the transition counts of the table:
p<-c(.1328,.3188,.3187,.17,.05099,.008158,.000544)
rmultinom(5,100,p),
where p is the vector of transition probabilities of the second row of the transition matrix.
With the improper prior density for these transition probabilities and based on the first
realization of Table 5.5, it is well known that the posterior distribution of P1 of Equation 5.18
is Dirichlet (15,26,35,17,6,1,0). See pages 48–50 of Degroot.8
The Bayesian analysis is executed with WinBUGS Code 5.3 using 70,000 observations for
the simulation and a burn-in of 5,000, and the posterior distribution for P10 and s is reported
in Table 5.6.
The posterior mean of the selection force is 0.8975 with a 95% credible interval of
(0.4046,1.503), and it appears that the distribution is symmetric about the posterior mean.
The value of 0.897 for the posterior mean is fairly close to the value of s = 1 used to generate
the transition counts for the second row, but this is not surprising since one would expect a
TABLE 5.6
Posterior Analysis for Selection
Parameter Mean SD Error 2 1/2 Median 97 1/2
P10 .15 .03546 .000143 .0875 .1476 .2264
s 0.8975 0.2799 0.001134 0.4046 0.878 1.503
184 Bayesian Inference for Stochastic Processes
sample variation in the various realizations as portrayed in Table 5.5. In order to test the
hypothesis s = 1 versus s ≠ 1, one could test the hypothesis that P01 = :1328. See Equation
5.16, which expresses the transition probabilities in terms of the selection force s.
and i = 1, 2, …; P00 = 1; and P0J = 0, j ≠ 0. Also, note that PN,N+1 = bN = 0; therefore the
(N + 1) × (N + 1) transition matrix is given by
0 1
1, 0, 0, 0, 0, ::::, , , , , , , , , , , , , , , , , , , , , , , , , , , , 0
B C
B d1 , 1 − (d1 + b1 ), b1 , 0, 0, 0, 0, 0, 0, 0, :::, , 0 C
B C
B C
B 0, d2 , 1 − (d2 + b2 ), b2 , 0, 0, 0, 0, 0, 0, :::, 0 C
B C
B C
B
P = B: C: (5.22)
C
B C
B: C
B C
B C
B 0, 0, 0, :::::::::, 0, dN−1 , 1 − (dN−1 + bN−1 ), bN−1 C
@ A
0, 0, ::::::::::::::::::::::::::::::::, 0, dN , 1 − dN
Thus, the population increases by one, decreases by one, or remains the same. There are
two communicating classes where {0} and {1, 2, …, N}, where 0 is an absorbing state and the
remaining are transient. In addition, it can be shown that there is a unique stationary
distribution.
As an example of a birth and death process, let N = 10 and bi = bi, i = 1, 2, :::, 9, di = di,
i = 1, 2, :::, 10, where b and d are constants.
Three cases are considered: (1) b = :02 < :03 = d, (2) b = :025 = d, and (3) b = :03 > :02 = d.
Examples of Markov Chains in Biology 185
0 1
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
B C
B :03, :95, :02, 0, 0, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, :06, :9, :04, 0, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 0, :09, :85, :06, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 0, 0, :12, :8, :08, 0, 0, 0, 0, 0 C
B C
B C
P=B
B 0, 0, 0, 0, :15, :75, :10, 0, 0, 0, 0 C:
C (5.23)
B C
B 0, 0, 0, 0, 0, :18, :70, :12, 0, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, :21, :65, :14, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, :24, :60, :16, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, 0, :27, :55, :18 C
@ A
0, 0, 0, 0, 0, 0, 0, 0, 0, :30, :70
Recall in R Code 5.2 the Markov function that generates observations from the chain with
transition matrix P:
R Code 5.2
markov <- function(init,mat,n,labels) {
+ if (missing(labels)) labels <- 1:length(init)
+ simlist <- numeric(n+1)
+ states <- 1:length(init)
+ simlist[1] <- sample(states,1,prob=init)
+ for (i in 2:(n+1))
+ { simlist[i] <- sample(states,1,prob=mat[simlist[i-1],]) }
+ labels[simlist]
+}
The first simulation has initial value 2 and the process is absorbed by the state 1.
> init<-c(0,1,0,0,0,0,0,0,0,0,0)
> markov(init,p,100)
2222222222223333333333333222222222222
2222222222222222211111111111111111111
111111111111111111111111111
The second simulation begins with the state 3 and stays in state 2 for the remaining
observations:
186 Bayesian Inference for Stochastic Processes
> init<-c(0,0,1,0,0,0,0,0,0,0)
>init<-c(0,0,1,0,0,0,0,0,0,0,0)
>markov(init,p,100)
33334433333333333333333333333333333333333
33333333333322222222222222222222
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2.
The student should experiment with the Markov R function with additional simulations
using different initial values. Also of interest is the R function stationary, which when
applied to the transition P gives the stationary distribution π reported in Table 5.7:
It will be left to the student to find the Bayesian approach to determining the stationary
distribution as an exercise at the end of the chapter. The reader is referred to Equations 4.66
through 4.68 of Chapter 4 and to WinBUGS Code 4.6.
Our last goal for this example of a birth and death process is to estimate the birth and
death rates using a Bayesian approach, whereby multinomial realizations will be generated
from the first three components of the second row of P, namely, (.03,.95,.02), which are the
values assigned to the vector (d1 , 1 − (b1 + d1 ), b1 ). The R Code
p<-c(.03,.95,.02)
> rmultinom(5,100,p)
generates the following five realizations of size 100 depicted in Table 5.8.
TABLE 5.7
Stationary Distribution: Birth and Death Process
π0 .001782713
π1 .009306754
π2 .032048848
π3 .032048848
π4 .217523222
π5 .481424409
π6 .120759090
π7 .033324661
π8 .009965581
π9 .003265024
π10 .001287085
Examples of Markov Chains in Biology 187
TABLE 5.8
Five Realizations for Birth and Death Process
R1 R2 R3 R4 R5
d1 5 1 1 1 2
1 − (d1 + b1 ) 93 96 97 96 91
b1 2 3 2 3 7
Based on the fifth realization, the usual estimates of the death and birth rates d1 and b1 are
.02 and .07, respectively, compared to the values of .03 and .02, respectively, used to gen-
erate those realizations. Also apparent is the variation demonstrated between the five
realizations. Recall that the Bayesian analysis is based on assuming that the realizations
have multinomial distributions and an improper prior is assigned to the unknown
parameters d1 and b1 , that the prior density is
g(b1 , d1 ) ∝ 1=b1 d1 , 0 < b1 < 1, 0 < d1 < 1 (5.24)
Based on the fifth realization and the prior density (Equation 5.24), the posterior density
of b1 is beta (7,93) and that of d1 is beta (2,98), and the complete Bayesian analysis is
executed with WinBUGS Code 5.4:
I executed the analysis with 70,000 observations for the simulation and a burn-in of 5,000.
The actual value of the birth rate is .02, and the posterior mean is .02006 with a 95%
credible interval of (.0023,.0552), but the actual value of the death rate is .03 and is estimated
with the posterior median of .0672 with a 95% credible interval (.0287,.1269). Note also that
the credible interval for d1 does include .03! Both posterior distributions appear to be
skewed to the right. See the posterior density of b1 shown in Figure 5.3.
b1 sample: 65001
40.0
P(b1)
20.0
0.0
FIGURE 5.3
Posterior density of b1 .
188 Bayesian Inference for Stochastic Processes
The last aspect of Bayesian inference for the birth and death process is to derive the
predictive distribution of the multinomial distribution used to generate realizations
(Table 5.8) for the counts of the birth and death process (Equation 5.21) with transition
matrix (Equation 5.23).
In general, the predictive density of the future transition counts (m1 , m2 , m3 ) of the first
three components of the first row of P (Equation 5.23):
2 0 1 3
ððð j=3
X j=3
Y Yj=3
m +n +a −1
½m ! =m1 ! m2 ! m3 !4G@ mj + aj A= G mj + aj 5 Pj j j j dP11 , dP12 , dP13
j=1 j=1 j=1
2 32 0 13 2 3
j=3
Y j=3
X j=3
Y
= 4m= mj !54G@ nj + aj A5=4 G(nj + aj )5 (5.25)
j=1 j=1 j=1
2 0 13
j=3
Y j=3
X
4 G nj + mj + aj =G@ nj + mj + aj A5,
j=1 j=1
where the posterior density of (P11 , P12 , P13 ) is Dirichlet (n1 + a1 , n2 + a2 , n3 + a3 ), and the
corresponding prior density is Dirichlet (a1 , a2 , a3 ). Note that by letting the alpha hyper
parameters be zero, one is in effect assuming an improper prior for the three transition
parameters, which simplifies the predictive density to
where
and
B = Gð2ÞGð91ÞGð7ÞGð100 + m1 + m2 + m3 Þ:
Recall that the cell count m1 corresponds to the death rate d1 ; m2 , to 1 − (d1 + b1 ); and, m3 ,
to b1 . For example, it can be shown that
Of special interest is the expected time to extinction of the birth and death process.
According to page 122 of Allen,1 the average time to extinction of the birth and death
process fX(n), n = 0, 1, 2, :::g with
X
i=N
μm = 1=d1 + ðb1 :::bi−1 =d1 :::di Þ, m = 1
i=2
" # (5.28)
X
s=m−1 X
i=N
= μ1 + ½d1 :::ds =b1 ::bs ½b1 :::bi−1 =d1 :::di , m = 2, :::, N:
s=1 i=s+1
Using Equation 5.28, it can be shown that the average time to extinction is μ1 = 54:7933
time points. Note that this estimate does not have a standard error attached, and this
problem can be avoided using Bayesian inferential techniques. Is this value reasonable?
Remember that if the population size is 1, one would need a death for extinction, but the
probability of a death is .03, a small chance that extinction is imminent. Also, recall that the
probability that the population size remains at 1 with probability .95 at each time point.
The Bayesian approach will generate multinomial data using the transition matrix P of
Equation 5.23. I generated a multinomial realization of size 100 for the transition counts
corresponding to the 10 population sizes which correspond to the various birth and death
rates listed in columns 2 and 4. For example, corresponding to the population of size 5 with
death rate of .15 and birth rate of .10, the multinomial realization of size 100 is (11,76,13).
Thus, the usual estimate of the death rate is .11 compared to the actual value of .15. Of
course, we would expect the estimated rates to differ from the actual.
Assuming an improper prior density of the birth and death rates, the posterior distri-
bution of the transition probabilities (the birth and death rates) will each be beta. For
example, the posterior distribution of d2 is beta (8,92), which has a posterior mean of .08. I
executed the posterior analysis with WinBUGS Code 5.5 with 70,000 observations for the
simulation and a burn-in of 5,000.
d10~dbeta(28,72)
190 Bayesian Inference for Stochastic Processes
TABLE 5.9
Birth and Death Process
Parameter Mean SD Error 2 1/2 Median 97 1/2
μ1 134.4 465 1.702 21.53 76.55 574.4
b12<-b1*b2
b13<-b12*b3
b14<-b13*b4
b15<-b14*b5
b16<-b15*b6
b17<-b16*b7
b18<-b17*b8
b19<-b18*b9
d12<-d1*d2
d13<-d12*d3
d14<-d13*d4
d15<-d14*d5
d16<-d15*d6
d17<-d16*d7
d18<-d17*d8
d19<-d18*d9
d110<-d19*d10
mu1<-(1/d1)+(b1/d12)+(b12/d13)+(b13/d14)+(b14/d15)+(b15/d16)+(b16/d17)
+(b17/d18)+(b18/d19)+(b19/d110)
}
where r is the intrinsic growth rate, K is the carrying capacity, bi is the birth rate when the
population is of size i, and di the corresponding death rate. The process is observed at
various time points, such that the time between time points is sufficiently small so that
fdi + bi g ≤ 1. It can be seen from Equation 5.29 that the behavior of the process varies
according to the size of the population. Note that when i = 0 or i = K (the carrying capacity),
the birth and death rates are the same. Two cases are considered:
For the first case, the maximum population size is N = 2K, and the birth probability
increases when the population size is <K and decreases for population sizes >K, but the
death rate is always increasing. On the other hand, for the second case, both the birth and
death probabilities increase with the population size. Refer to pages 123–127 of Allen1 for
additional details about the logistic growth process.
For the Bayesian analysis, interest is restricted to the second case with N = 20, K = 10,
r = .004, and bi = ri, di = ri2 =K. The one-step 21 × 21 transition matrix for the second case is
given in the following by P, see Equation (5.31). The analysis consists of generating multino-
mial realizations of size 1000 for the nonzero entries of each row of P. In this way, the sample
information is available, then this is combined with the prior information for the unknown
parameters (the transition parameters of the transition matrix of which there are three for each
row of P). As before, an improper prior distribution is assigned, which, when combined with
the realizations of Table 5.10, results in Dirichlet distributions for the transition rows of P:
TABLE 5.10
Multinomial Realizations for the Logistic Growth Model
Population Size d 1−b−d b n1 n2 n3
1 .0004 .9956 .004 1 992 7
2 .0016 .9904 .008 1 996 3
3 .0036 .9844 .012 5 988 7
4 .0064 .9776 .016 4 977 19
5 .01 .9700 .020 9 964 27
6 .0144 .9616 .024 15 961 24
7 .0196 .9524 .028 18 952 30
8 .0256 .9242 .032 26 943 31
9 .0324 .9316 .036 29 935 36
10 .04 .92 .04 48 912 40
11 .0484 .9076 .044 41 914 41
12 .0576 .8944 .048 62 888 50
13 .0676 .8804 .052 74 880 46
14 .0784 .8656 .056 63 882 55
15 .09 .85 .06 84 859 57
16 .1024 .8336 .064 93 841 66
17 .1156 .8164 .068 109 824 67
18 .1296 .7984 .072 132 801 67
19 .1444 .7790 .076 139 781 80
20 .16 .84 154 846
192 Bayesian Inference for Stochastic Processes
0 1
1:0, 0:0, 0:0, 0:0, 0:0, 0:0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
B C
B :0004, , 9966, :004, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, :0016, :9904, :008, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 0, :0036, :9844, :012, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 0, 0, :0064, :9776, :016, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, C
B C
B C
B 0, 0, 0, 0, :01, :97, :02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, :0144, :9616, :024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, :0196, :9524, :028, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, :0256, :9424, :032, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, 0, :0324, :9316, :036, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, 0, 0, :04, :92, :04, 0, 0, 0, 0, 0, 0, 0, 0, 0 C
B C
P=B C: (5.31)
B 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, :0484, :9076, :044, 0, 0, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, :0576, :8944, :048, 0, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, :0676, :8804, :052, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, :0784, :8656, :056, 0, 0, 0, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, :09, :85, :06, 0, 0, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, :1024, :8336, :064, 0, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, :1156, :8164, :068, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, :1296, :7984, :072, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, :1444, :7796, :076 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, :16, :84 C
@ A
The first column of Table 5.10 designates the population size; the second, third, and fourth
rows are the transition probabilities (the death and birth rates) of the transition matrix of the
logistic growth model (Equation 5.30), while the last three columns of Table 5.10 are the
corresponding multinomial realizations. Each realization is based on a sample of size 1000,
and the realizations provide sample information for the Bayesian analysis.
For example, corresponding to a population size of 10, the death and birth rates are each
.04, and the corresponding multinomial realization is (48,912,40), giving .48 and .40 as the
usual estimates of the death and birth rates, respectively, when the population is of size 10.
I chose 1000 for the realization size because the birth and death rates are very small. I
wanted to avoid a transition count of zero! Note that the last row of Table 5.10 does not have
an entry (corresponding to the population of size 20, the maximum size), since a birth is
impossible, but a death can occur with probability .16.
Using Equation 5.28, the goal of the Bayesian analysis is to estimate the time to extinction
assuming a population of size 1.
Examples of Markov Chains in Biology 193
d.12<-d1*d2
d.13<-d.12*d3
d.14<-d.13*d4
d.15<-d.14*d5
d.16<-d.15*d6
194 Bayesian Inference for Stochastic Processes
d.17<-d.16*d7
d.18<-d.17*d8
d.19<-d.18*d9
d.110<-d.19*d10
d.111<-d.110*d11
d.112<-d.111*d12
d.113<-d.112*d13
d.114<-d.113*d14
d.115<-d.114*d15
d.116<-d.115*d16
d.117<-d.116*d17
d.118<-d.117*d18
d.119<-d.118*d19
d.120<-d.119*d20
b.12<-b1*b2
b.13<-b.12*b3
b.14<-b.13*b4
b.15<-b.14*b5
b.16<-b.15*b6
b.17<-b.16*b7
b.18<-b.17*b8
b.19<-b.18*b9
b.110<-b.19*b10
b.111<-b.110*b11
b.112<-b.111*b12
b.113<-b.112*b13
b.114<-b.113*b14
b.115<-b.114*b15
b.116<-b.115*b16
b.117<-b.116*b17
b.118<-b.117*b18
b.119<-b.118*b19
mu1<-
1/d1+b1/d.12+b.12/d.13+b.13/d.14+b.13/d.14+b.14/d.15+b.15/d.16+b.16/d.17
+b.17/d.18+b.18/d.19+b.19/d.110+b.110/d.111
+b.111/d.112+b.112/d.113+b.113/d.114+b.114/d.115+b.115/d.116
+b.116/d.117+b.117/d.118+b.118/d.119+b.119/d.120
}
I used 55,000 observations for the simulation with a burn-in of 5,000, and the results are
reported in Table 5.11.
The posterior distribution of three death and birth rates are portrayed in Table 5.11, while
the posterior median to the time to extinction is 919,400 time units. When the population is
size 1, note that the probability of a death is .0004; thus, it is not surprising that the median
time to extinction is extremely large. The student will be asked to enlarge the posterior
analysis to the parameter μ10 , the average time to extinction assuming that the population is
size 10.
Examples of Markov Chains in Biology 195
TABLE 5.11
Posterior Analysis of Logistic Growth Model
Parameter Mean SD Error 2 1/2 Median 97 1/2
b1 .00699 .00263 .000008 .0028 .0066 .0130
b2 .0030 .0017 .000005 .00062 .0026 .0071
b3 .0069 .0026 .000007 .0028 .0066 .0130
d1 .0009 .0009 .000003 .000025 .0006 .0036
d2 .0010 .00099 .000003 .00002 .0006 .0036
d3 .0049 .00223 .000006 .00163 .0046 .0102
μ1 5.37 × 107 3.4 × 109 1.04 × 107 24,200 919,400 1.2 × 108
I ðn + 1Þ = IðnÞ½bðN − IðnÞÞ=N + 1 − b − g
(5.33)
= IðnÞ½1 + b − b − g − bI ðnÞ=N :
There are two equilibrium solutions; that is, where I(n + 1) = I(n) = E, which are E = 0 and
E = N½1 − (b + g)=b.
The equilibrium point is a function of the reproduction number
R0 = b=ðb + g Þ, (5.34)
The goal as a Bayesian is to make inferences about the unknown parameters, the birth rate
b, the number of contacts b, and the number of infected people that recover g. I will begin
with estimating the parameters b, g, and b used as data transition counts for the first three
entries of the second row of P, where the transition counts will be realizations generated via
the multinomial distribution.
Consider the multinomial distribution with parameter p = (.005,.9851,.0099), then using
the R function rmultinom, the following realization was generated with transition counts
(n10 , n11 , n12 ) = (3,993,4) corresponding to the transition probabilities
P10 = b + g,
P11 = 1 − l1 − ðb + g Þ,
P12 = l1 = bðN − 1Þ=N, (5.37)
N = 100,
b = g = :0025,
and
b = :01
Therefore, the transition probabilities are estimated as P ~ 10 = :003, P~ 11 = :973, and
~ 12 = :004. Thus, using Equation 5.37, the estimates for the parameters of the epidemic are
P
.0040404 for b and .0015 for b and g. What are the Bayesian estimates?
Assume that the prior distribution for the transition probabilities is the improper prior
j=2
X
zðP10 , P11 , P12 Þ = P−1
1j , (5.38)
j=0
198 Bayesian Inference for Stochastic Processes
where
j=1
X
P1j = 1, 0 < P1j < 1, and j = 1, 2, 3
j=0
It can be shown the posterior distribution of the transition probabilities is Dirichlet with
parameter (n10 , n11 , n12 ) = (3,993,4); thus, the marginal posterior distribution of P10 is
beta(3,997), that of P11 is beta(993,7), and that of P12 is beta(4,996).
The Bayesian analysis is executed with WinBUGS Code 5.8 with 35,000 observations for
the simulation and a burn-in of 5,000. The step command g2 gives the posterior probability
that R0 > 1.
As a result of the simulation, the Bayesian analysis for the simple epidemic model is
reported in Table 5.12.
Note that the posterior probability that R0 > 1 is .663; that is, in symbols, g2 = Pr½R0 >
1jdata = :663. The estimates of the other parameters P10 , P11 , and P12 are similar to the usual
estimates given earlier. Recall that the transition probabilities P10 = :005, P11 = :9851,
P12 = :0099 were used to generate the multinomial realization (n10 , n11 , n12 ) = (3,993,4) for
the Bayesian analysis, and these values for the transition probabilities should be compared
TABLE 5.12
Posterior Analysis for Simple Epidemic
Parameter Mean SD Error 2 1/2 Median 97 1/2
R0 2.029 2.655 0.0097 0.2935 1.389 7.538
b .00149 .000859 .0000032 .00031 .00133 .00361
b+g .002986 .001718 .0000064 .00062 .00267 .00722
P10 .002986 .001718 .0000064 .00062 .00267 .00722
P11 .993 .00262 .0000096 .987 .9933 .9972
P12 .00399 .001992 .0000083 .0011 .00366 .00879
b .004037 .002003 .0000112 .00113 .003705 .00886
g2 .663 .4727 .002646 0 1 0
Examples of Markov Chains in Biology 199
to the posterior means (.0029,.993,.0039) of Table 5.12. It appears that the posterior means
are quite close to these values.
For additional information about the stochastic epidemic model, refer to Allen and
Burgin,10 Daley and Gani,11 and Allman and Rhodes.12
The epidemic terminates when I(n) = 0 for some n. The preceding explanation for chain
binomial models is somewhat simplified, and the reader is referred to Daley and Gani11 for
additional information about the subject. Let a be the probability of a contact between an
infected and a susceptible individual, and suppose that b is the chance the contact results in
the susceptible person becoming infected; therefore, the probability that a susceptible
person does not become infected is
p = 1 − ab (5.40)
In view of Equation 5.40, 1 − p is the probability of a contact not resulting in an infection,
and as will be revealed, p is an important parameter in both versions of the chain binomial
model.
There are two versions of the chain binomial model: (1) the Greenwood and (2) the Reed–
Frost.
First, the Greenwood model is investigated. At time n + 1, there are S(n + 1) susceptible
people among which S(n + 1) contacts were not successful, and the number of contacts that
were successful is I(n + 1) = S(n + 1) − S(n). This implies that the probability of a one-step
transition from S(n + 1) to S(n) is
!
sðn Þ h isðn+1Þ h isðnÞ−sðn+1Þ
PSðnÞ,Sðn+1Þ = piðnÞ 1 − piðnÞ , (5.41)
sðn + 1Þ
where s(n + 1) = 0, 1, 2, ..., s(n), and 0 < p < 1. Note that this determines the s(0) × s(0)
transition matrix of the Greenwood model in Equation 5.41 for an epidemic, which is to be
initiated with I(0) > 0 infectious people.
Note that the state space for the chain is {S(n),n = 1,2,…}, where S(0) is positive. A
realization of the process is depicted by {s(0),s(1),…,s(t)}, where the number of infected
people at time t is zero, that is, I(t) = 0, which is equivalent to S(t − 1) = S(t). The duration
200 Bayesian Inference for Stochastic Processes
of the epidemic is t, and the size of the epidemic is the number of susceptible people who
became infected during the duration or S(0) − S(t). This type of epidemic is of the chain
binomial type because the distribution of S(n + 1) is binomial with parameters s(n) and p.
From Equation 5.41, the (s(0) + 1) × (s(0) + 1) matrix is
0 1
1, 0, 0, ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::, 0
B C
B ð1 − pÞ, p, 0, :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::, 0 C
B C
B C
B ð1 − pÞ2 , 2pð1 − pÞ, p2 , 0, :::::::::::::::::::::::::::::::::::::::::::::, 0 C
B C
B C
B: C
B C
P=B C: (5.42)
B: C
B C
B C
B: C
B ! ! C
B C
B
@ ð1 − pÞs(0) , s ð 0Þ s ð 0Þ C
s(0) A
pð1 − pÞ s(0)−1
, p ð1 − pÞ
2 S(0)−2
, ::::, p
1 2
0 1
1, 0, :::::::::::::::::::::::::::::::::::::::, 0
B C
B 1 − p, p, 0, ::::::::::::::::::::::::::::::, 0 C
B C
P=B C (5.43)
B (1 − p)2 , 2p(1 − p), p2 , :::::::::::::, 0 C
@ A
(1 − p)3 , 3p(1 − p)2 , 3p2 (1 − p), p3
Now let b = :05, the probability that a susceptible person is infected after contact with an
infected person, and suppose that the probability of a contact between a susceptible indi-
vidual and an infected individual is p = .025, which is the probability that a susceptible
person is infected. Substitute .025 for p in Equation 5.43 to give as the transition matrix
0 1
1, 0, 0, 0
B C
B :02500, :97500, 0, 0 C
B C
P=B C: (5.44)
B :000625, :04875:95060, 0 C
@ A
:0000156, :001821, :07129, :92685
Examples of Markov Chains in Biology 201
There are two classes {0} and {1, 2, 3} where the latter states are transient and the first is
absorbing. Does it have a limiting distribution?
R Code 5.3 generates realizations from the Greenwood process using the transition matrix
P (Equation 5.44):
R Code 5.3
markov <- function(init,mat,n,labels) {
+ if (missing(labels)) labels <- 1:length(init)
+ simlist <- numeric(n+1)
+ states <- 1:length(init)
+ simlist[1] <- sample(states,1,prob=init)
+ for (i in 2:(n+1))
+ { simlist[i] <- sample(states,1,prob=mat[simlist[i-1],]) }
+ labels[simlist]
+}
> p<-matrix(c(1,0,0,0,
.02493,.9751,0,0,
.001567,.04672,.9517,0,
.000156,.004232,.004232,.9298),nrow=4,ncol=4,byrow=TRUE)
init<-c(0,1,0,0)
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 ,
init<-c(0,0,1,0)
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 1,1,1,1,1,1,1, 0,0,0,0,
202 Bayesian Inference for Stochastic Processes
init<-c(0,0,0,1)
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
init<-c(1,0,0,0)
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.
Do these simulations demonstrate the transient behavior of the states 1, 2, and 3 and that
0 is an absorbing state?
For the Bayesian analysis, I used multinomial realizations of size 500 for each row of P
(Equation 5.44), which generates the transition count matrix Q (Equation 5.46). The tran-
sition counts will serve as the sample information for Bayesian estimation of p (the second
entry of the second row of P), the fundamental unknown parameter of the process with
transition matrix P (Equation 5.44).
0 1
500, 0, 0, 0
B C
B 10, 490, 0, 0 C
B C
Q=B C: (5.46)
B 1, 17, 482, 0 C
@ A
1, 2, 2, 495
Assuming a uniform prior for p, the posterior density of p is beta (491,11), with posterior
mean of 491/502 = .978087649. A more complete analysis is executed with WinBUGS Code
5.8.
p32<-3*pow(p,2)*(1-p)
p33<-pow(p,3)
p3219<-p32*p21*p10
q310<-3*p*pow(1-p,2)*(1-p*p)
s3210<-6*pow(p,3)*pow(1-p,3)
}
The Bayesian simulation is for the transition probabilities of the transition matrix P
(Equation 5.43), whose entries are in terms of the fundamental parameter p. For example,
note that p30 of the code is the first entry P30 of the last row of Equation 5.43. The posterior
analysis is executed with 45,000 observations for the simulation and 5,000 for the burn-in.
The Bayesian analysis shown in Table 5.13 is quite complete in that the relevant posterior
information is shown for all the entries of the transition matrix (Equation 5.43).
Thus, the fundamental parameter p (the probability that a susceptible person does not
become infected) is estimated with the posterior mean as .9781 with a 95% credible interval
(.9637,.989). Based on the posterior medians, the transition matrix P in Equation 5.43 is
estimated as
0 1
1, 0, 0, 0
B C
∼ B :0212, :9787, 0, 0 C
B C
P=B C (5.47)
B :000454, :04172, :9578, 0 C
@ A
:000009::001334, :06125, :937
TABLE 5.13
Posterior Analysis for the Greenwood Model
Parameter Mean SD Error 2 1/2 Median 97 1/2
p .9781 .00648 .000037 .9637 .9787 .989
P10 .0219 .00648 .000037 .01104 .02132 .03631
P11 .9781 .00648 .000037 .9637 .9787 .989
P20 .000522 .000314 .000001 .000122 .000454 .001318
P21 .0428 .01236 .000071 .02184 .04172 .06998
P22 .9567 .01267 .000073 .9287 .9578 .978
P30 .000013 .000012 .0000000 .000001 .000009 .000047
P31 .00152 .000906 .0000052 .000361 .001334 .003812
P32 .0626 .0176 .000101 .0324 .06125 .1012
P33 .9358 .0185 .000107 .895 .9374 .9672
P3210 .000074 .000068 .0000003 .000007 .000054 .00026
s3210 .000074 .000068 .0000003 .000007 .000054 .00026
204 Bayesian Inference for Stochastic Processes
Note that the last row of the table which shows the posterior distribution of the sample path
{s(0), s(1), s(2), s(3)} = {3, 2, 1, 0} to extinction of the epidemic is estimated as .000074 with the
posterior mean and a 95% credible interval (.000007,.00026). Thus, the posterior probability
that the epidemic ends after 4 time units along that particular path is extremely small.
Up to this point, Bayesian inference has focused on the estimation of the fundamental
parameter p, the probability a susceptible person does not become infected; now the focus
will be on predicting future transition counts for the Greenwood model. That is, starting
with a given number of susceptible and infected individuals, what is the Bayesian pre-
dictive mass function for the future number of infected persons?
Recall that given S(n) = s(n), the distribution of I(n + 1) is binomial with parameters s(n)
and (1 – p)s(n); thus, given s(n) susceptible people at time n, the average number of infec-
tions is
where i(n) is the number of infected people at time n and the number infected at time n is
I(n) = S(n − 1) − S(n) for n = 1, 2, …. The primary difference between the Greenwood
version (Equation 5.41) and the Reed–Frost one is that the probability p of a susceptible
individual being infected depends on the number of infected, namely, the probability pi(n) .
Let us evaluate the posterior probability of the path {s(0),s(1),s(2),s(3)} = {3,2,1,0}, which
has the probability
With the Bayesian approach, refer to WinBUGS Code 5.9, the statement s3210 , and the last
row of Table 5.13, which is identical to the next to the last row, which in turn corresponds to
the posterior probability of the same sample path. The posterior distribution of the two
probabilities P3210 and s3210 are the same, as they should be. Since the number of infections
E½I(n + 1)jS(n) = s(n) = (1 − p)s(n), the transition probabilities of the Reed–Frost model
(Equation 5.49) are the same as those for the Greenwood model (Equation 5.43). For the two
models to differ, i(n) > 1, for some n.
Examples of Markov Chains in Biology 205
Now consider the sample path {s(0),s(10),s(2),s(3)} = {3,1,0,0}, which occurs with proba-
bility
P31 P10 = 3pð1 − pÞ2 1 − p2 = 3ð:975Þð:275Þ2 ð:049375Þ = :0109219
It is left for the student to do the Bayesian analysis to estimate P31 P10 . Refer to WinBUGS
Code 5.8 and the WinBUGS statement s3210<-6*pow(p,3)*pow(1-p,3) which is the proba-
bility of the sample path {3,1,0,0} assuming the Reed–Frost model.
It is obvious that each base communicates with the other three with probability d as
portrayed in Figure 5.4.
206 Bayesian Inference for Stochastic Processes
A T
FIGURE 5.4
Directed graph of molecular evolution.
This model is known as the Jukes–Cantor model13 and page 49 of Allen1 gives a detailed
description of the model. It can be shown that the probability that there has been no sub-
stitutions of base i in n generations is
where a = 3d is the rate of mutation. Note that a is the probability that a particular base is
substituted by one of the other three bases. Our main interest is to estimate d and a and to
test hypotheses about them. For the Bayesian analysis, let d = 1/12, then
0 1
3=4, 1=12, 1=12, 1=12
B C
B 1=12, 3=4, 1=12, 1=12 C
B C
P=B C (5.53)
B 1=12, 1=12, 3=4, 1=2 C
@ A
1=12, 1=12, 1=12, 3=4
0 1
37, 4, 3, 6
B C
B 5, 35, 6, 4 C
B C
Q=B C: (5.54)
B 5, 4, 36, 5 C
@ A
1, 9, 3, 37
It is interesting to note that in practice, one would observe Q (not the known transition
matrix P [Equation 5.54]), and using Q as sample information one would make inferences
about the unknown transition probabilities Pij : i, j = 1, 2, 3, 4. Based on proportions, the
usual estimates are portrayed in the matrix
0 1
:74, :08, :06, :12
B C
B :10, :70, :12, :08 C
B C
R=B C: (5.55)
B :10, :08, :72, :10 C
@ A
:02, :18, :06, :74
Thus, consider the first row, which shows what happens to base A over 50 generations,
namely, .74 of 50 generations; no substitution occurred for A; but 8% of 50 generation A was
substituted with the base G, 6% by C; and 12% by T, with a mutation rate of 26%. That is, A
mutates 26% over 50 generations.
A question of interest is on the basis of the estimates R, how are inferences of the
parameter d of the matrix in Equation 5.51 determined? Of course, this assumes that one
knows the pattern of molecular evolution given by Equation 5.51. Suppose one did not
know that the chain has the pattern displayed by Equation 5.51, then could one deduce that
pattern based on the sample information (Equation 5.54)? Using a Bayesian approach, both
of these problems will be addressed.
The first inference problem to be solved is that of estimating the parameter d (or, equiv-
alently, the mutation rate) of Equation 5.51; that is, one is assuming that molecular evolu-
tion occurs according to the pattern in Equation 5.51. The value of d, the off-diagonal term, is
estimated by taking the average of the 12 off-diagonal terms, then the diagonal entry is
estimated by computing 1 − 3d, and the analysis is executed with WinBUGS Code 5.9.
The Bayesian approach assumes that the transition probabilities have an improper prior
distribution
j=4
Y
gðPÞ ∝ P−1
ij , (5.56)
j=1
j=4
X
where and Pij = 1, i = 1, 2, 3, 4.
j=1
By the Bayes theorem, the first row of the transition matrix has a posterior Dirichlet
distribution with parameter (37,4,3,6); thus, the diagonal element P11 has a posterior beta
distribution with parameter (37,13).
208 Bayesian Inference for Stochastic Processes
The analysis is executed with 45,000 observations for the simulation and 5,000 for the
burn-in. See WinBUGS Code 5.9.
Thus, the posterior analysis estimates the off-diagonal entries with a posterior mean of
.0915 and estimates the diagonal entries as .7254. Note that the 95% credible interval for d
contains the number 1/12 = .0833, and that for the diagonal entry, the 95% credible
interval contains .75. This suggests that the data support the evolution pattern of matrix
(Equation 5.51).
The second phase of the Bayesian analysis will center on a formal Bayesian test of the
hypothesis that the molecular evolution pattern of Equation 5.51 is correct.
Consider the transition matrix and the null hypothesis
H: P12 = P13 = P14 = P21 = P23 = P24 = P31 = P32 = P34 = P41 = P42 = P43 (5.57)
versus the alternative that H is not true. Note that the null hypothesis states that all off-
diagonal entries of the transition matrix are the same, which implies that all the diagonal
elements are the same. This is the pattern specified by the matrix in Equation 5.41.
In order to test the hypothesis H, let the prior probability of the null hypothesis be πo and
that of the alternative π1 .
Examples of Markov Chains in Biology 209
Under the null hypothesis, the likelihood function in Equation 5.60 reduces to
2 3
6 7
6 Y j=4
i=4 Y 7
6 7 n
gðnoff jHÞ = 6
6 n ! = n 7
ij 7p ,
! (5.61)
6 i=1 j=1 7
4 5
i≠j
where n is the total of the off-diagonal transition counts shown in the matrix Q in Equation
1.53, and p is the common value of the transition probabilities.
j=4
i=4 X
X
n= nij :
i=1 j=1
j≠i
ð1
gðnoff Þ = gðnoff jHÞxðpÞdp = 1=n, (5.62)
0
and r1 is the prior density of Poff , the off-diagonal entries of the transition matrix.
210 Bayesian Inference for Stochastic Processes
Y j=4
i=4 Y
r1 ðPoff Þ ∝ P−1
ij ,
i=1 j=1
i≠ j
Y j=4
i=4 Y
l1 (noff ) = n != nij ! = :000046296 (5.65)
i=1 j=1
j≠i
Now let π0 = π1 = :5, then the posterior probability of the null hypothesis is
p0 = (:5=54)=½(:5=54) + :5(:000046296) = :009259259=:009282407 = :995018719. Therefore, the
data of observed counts Q (Equation 5.53) very strongly support the assertion that
molecular evolution follows the pattern specified by the Jukes–Cantor model specified
by the matrix in Equation 5.51! This is not a surprising conclusion, since to some extent,
it is implied by the corresponding observed transition probabilities portrayed by matrix
R (Equation 5.54) and by the Bayesian estimation analysis displayed in Table 5.14.
Kimura14 proposed another version of molecular evolution given by the transition matrix
0 1
1 − a − 2d, a, d, d
B C
B a, 1 − a − 2d, d, d C
B C
P=B C, (5.66)
B d, d, 1 − a − 2d, a C
@ A
d, d, a, 1 − a − 2d
where, 0 < a < 1/3 and 0 < d < 1/3. Note that when a = d, the Kimura chain reduces to the
Jukes–Cantor model.
If a ≠ d, what is the difference between the Jukes–Cantor model (Equation 5.51) and the
variation in Equation 5.65? The Kimura model is a two-parameter model which assumes
that the bases occur with equal frequency and the rate of all transitions is the same and that
the rate of all transversions are the same.
A transvesion refers to the substitution of a (two-ring) purine for a (one-ring) pyrimide, or
vice versa. Recall that the two purine bases are adenine and guanine, while the other two
bases cytosine and thymine are pyrimidines. See Futuyma15 for additional information
TABLE 5.14
Posterior Analysis for Molecular Evolution
Parameter Mean SD Error 2 1/2 Median 97 1/2
d .0915 .0115 .0000551 .07015 .0911 .1154
Pii .7254 .0347 .000165 .6539 .7267 .7896
Examples of Markov Chains in Biology 211
about molecular evolution. Thus, there are two types of transitions, A ↔ G and C ↔ T, and
four transversions: C ↔ A, C ↔ G, G ↔ T, and A ↔ T.
From an inferential standpoint, it is of interest to test the hypothesis H that a = d versus
the alternative A: a ≠ d.
Consider the Kimura version (Equation 5.66) with a = .0316 and d = .1666, then the cor-
responding transition matrix is
0 1
:7917, :0416, :1666, :1666
B C
B :0416, :7917, :1666, :1666 C
B C
P=B C, (5.67)
B :1666, :1666, :7917, :0416 C
@ A
:1666, :1666, :0416, :7917
and suppose the corresponding distribution of row counts is assumed to be multinomial with
a total of 50, then using R to generate the row counts, a possible transition count matrix is
0 1
33, 4, 7, 6
B C
B 1, 38, 7, 4 C
B C
Q=B C: (5.68)
B 6, 7, 35, 2 C
@ A
11, 3, 1, 35
Therefore, with probability .0416, a G base is substituted for an A base, but with prob-
ability .1666, a C base is substituted for A. In a similar fashion out of 50 cycles, 33 times out
of 50 A did not change, while 4 times out of 50, the C base was substituted in the first
position. Note that the usual estimate for no change in the A base in the first position is
33/50 = .66 compared to the value .79, which was used to generate the count.
Our main concern is to provide Bayesian inferences for the unknown transition proba-
bilities of the process which includes estimating the eight differences between a and d of the
Kimura model given by Equation 5.66. For example, the difference P12 − P13 = a − d in the
transition matrix (Equation 5.66).
If an improper prior distribution is used for the transition probabilities, then the rows of
the transition counts have a posterior distribution, which is Dirichlet. For example, for the
first row of Q, the counts have a Dirichlet (33,4,7,6), and the transition probability P11 has
posterior distribution which is beta(33,17).
The Bayesian analysis is executed with WinBUGS Code 5.10 using 35,000 observations for
the simulation and 5,000 for the burn-in, and the results are reported in Table 5.15:
p22~dbeta(38,12)
p23~dbeta(7,43)
p24~dbeta(4,46)
p31~dbeta(6,44)
p32~dbeta(7,43)
p33~dbeta(35,15)
p34~dbeta(2,48)
p41~dbeta(11,39)
p42~dbeta(3,47)
p43~dbeta(1,49)
p44~dbeta(35,15)
# the a-d differences
d1213<-p12-p13
d1214<-p12-p14
d2123<-p21-p23
d2124<-p21-p24
d3431<-p34-p31
d3432<-p34-p32
d4341<-p43-p41
d4342<-p43-p42
The Bayesian analysis is quite interesting as exhibited in Table 5.15. For example, the first
row shows the posterior distribution of one of the a − d differences specified by P12 − P13 ,
which has a posterior mean of −.06118 and a posterior median of −.05945. The 95% credible
interval for this difference does not contain zero, implying informally that there is no dif-
ference in this particular one (of eight) a − d differences. The main emphasis for this analysis
is estimating these a − d differences of the Kimura model, not testing hypotheses.
It is left for the student in the exercises to perform a formal test that the Kimura model
reduces to the Jukes–Cantor model by testing the null hypothesis specified by
TABLE 5.15
Posterior Analysis Kimura Model
Parameter Mean SD Error 2 1/2 Median 97 1/2
P12 − P13 −.06018 .06172 .000338 −.1851 −.05945 .06048
P12 − P14 −.0406 .05921 .000337 −.159 −.0397 .0755
P21 − P23 −.12 .05222 .00029 −.2323 −.1162 −.02737
P21 − P24 −.05999 .04295 .000257 −.1546 −.05635 .01677
P34 − P31 −.07982 .05298 .000296 −.1897 −.0773 .02108
P34 − P32 −.1002 .005579 .000338 −.2161 −.09795 .004984
P43 − P41 −.2008 .0613 .000388 −.3286 −.1979 −.08915
P43 − P42 −.0401 .0384 .000232 −.124 −.0365 .0200
Examples of Markov Chains in Biology 213
Pi,i−1 = i=2N
and (5.70)
Pi,i+1 = 1 − i=2N:
Also, states 0 and 2N are reflecting barriers. If this process is observed for a long time, it
is clear that the chain will visit each state infinitely often, where N is an equilibrium
value. Assume that the initial state i is far removed from N, then it is also intuitively clear
that state i will be visited infinitely often. It is not so obvious that the time between visits
to i is so large that state i is not recurrent. For a large number of molecules and one
diffusion per second, the expected return time can exceed billions of years, and the chain
appears to be irreversible. Irreversibility resolves this contradiction! Bellman and Harris18
introduced a continuous version of the diffusion process, and this chain will be studied in
Chapter 7.
214 Bayesian Inference for Stochastic Processes
0 1
0, 1, 0, 0, :::::::::::::::::::::::::::::::::::::::::::, 0, 0
B C
B 1=2N, 0, ð2N − 1Þ=2N, 0, 0, ::::::::::::::::0, 0 C
B C
B C
B 0, 2=N, 0, ð2N − 2Þ=2N, 0, 0, ::::::::::::::0, 0 C
B C
B C
B: C
B C
P=B C: (5.71)
B: C
B C
B C
B: C
B C
B C
B 0, 0, :::::::::::::::::::, ð2N − 1Þ=2N, 0, 1=2N C
@ A
0, 0, 0, ::::::::::::::::::::::::::::::::::::::::::, 0, 1, 0
Note that this matrix is of the order of 2N + 1 corresponding to the state space {0,1,2,…, 2N}.
It is clear that the chain is irreducible and the states are recurrent. It is easy to derive the
stationary distribution of the Ehrenfest chain as where for state i:
2N −2N
πð i Þ = 2 , i = 0, 1, :::, 2N: (5.72)
i
Bayesian inferences will be directed at estimating the stationary distribution and the
average return time, given by Equations 5.72 and 5.73, respectively.
Consider the special case N = 5; thus, the transition matrix (Equation 5.71) reduces to the
11th order of matrix Q:
0 1
0, 1, 0, 0, :::::::::::::::::::::::::::::, 0
B C
B 1=10, 0, 9=10, 0, 0, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 2=10, 0, 8=10, 0, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 0, 3=10, 0, 7=10, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 0, 0, 4=10, 0, 6=10, 0, 0, 0, 0, 0 C
B C
B C
Q=B C
B 0, 0, 0, 0, 5=10, 0, 5=10, 0, 0, 0, 0 C:
B C
B 0, 0, 0, 0, 0, 6=10, 0, 4=10, 0, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 7=10, 0, 3=10, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, 8=10, 0, 2=10, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, 0, 9=10, 0, 1=10 C
@ A
0, 0, 0, 0, 0, ::::::::::::::::::::, 0, 1, 0
Examples of Markov Chains in Biology 215
The matrix Q will be used as sample information for the Bayesian analysis. Using the Q
matrix, the multinomial distribution was used to generate transition counts as sample
information given by the T matrix.
0 1
0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0
B C
B 2, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 1, 0, 19, 0, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 0, 4, 0, 16, 0, 0, 0, 0, 0, 0 C
B C
B C
B 0, 0, 0, 9, 0, 11, 0, 0, 0, 0, 0 C
B C
B C
B
T = B 0, 0, 0, 0, 7, 0, 13, 0, 0, 0, 0 C
C:
B C
B 0, 0, 0, 0, 0, 11, 0, 9, 0, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 16, 0, 4, 0, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, 18, 0, 2, 0 C
B C
B C
B 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 4 C
@ A
0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0
If one assumes an improper prior for the transition probabilities, the rows of the transition
count matrix follow a Dirichlet distribution; thus, for example, the two nonzero entries of
the second row follow a Dirichlet (2,18) distribution. It is suspected that N = 5, but not sure.
Based on the sample information from matrix T, we will test the hypothesis that N = 5. If
N = 5, then the following null hypothesis H is true:
P10 = 1=10,
P21 = 2=10,
P32 = 3=10,
P43 = 4=10,
H : P54 = 5=10, (5.74)
P65 = 6=10
P76 = 7=10,
P87 = 8=10,
P98 = 9=10
Note that there are many forms for the alternative. Under the null hypothesis, the order of
the ratios 1/10, 2/10, etc., are quite specific; however, under the alternative, one could have
a completely different order of these ratios.
The likelihood for the observed transition counts is
2 3
Y j=8
i=9 Y j=8
i=9 Y
Y n
20−nij
f ðnjPÞ = 420 ! = nij !5 Pijij 1 − Pij , (5.75)
i=1 j=i−1 i=1 j=i−1
216 Bayesian Inference for Stochastic Processes
where
n = ðn10 , n21 , n32 , n43 , n54 , n65 , n76 , n87 , n98 Þ (5.76)
and
P = ðP10 , P21 , P32 , P34 , P45 , P56 , P67 , P78 , P89 Þ, (5.77)
where
X j=8
i=9 X
1= Pij :
i=1 j=i−1
f ðnjHÞ = f ðnjPH Þ,
and the components of the vector PH are specified by the null hypothesis, namely,
The prior beta distributions for the alternative are chosen so that the prior means are the
same as the hypothesized values of the transition probabilities under the null hypothesis;
however, the prior variances are relatively large so that one is uncertain, a priori, for the
values of the transition probabilities under the alternative hypothesis.
Given this information, the posterior distribution of the transition probabilities (Equation
5.77) under the alternative hypothesis is
p0 = :998
Therefore, the data confirm the Ehrenfest model (Equation 5.71) with N = 5.
(5) AA × aa, and (6) aa × aa. The laws of inheritance imply the following makeup of the next
generation: (1) If the parents are both of type AA, the offspring will be AA individuals, so
that the crossing of brother and sister will be of one type, and P11 = 1; (b) now suppose
the parents are type 2, namely, Aa × Aa, then the offspring will occur in the following
proportions: 1/2 AA and 1/2 Aa; therefore, the crossing of brother and sister will be 1/4
of {AA × AA}, 1/2 of{AA × Aa}, and 1/4 of {Aa × Aa}. (c) Lastly, if the parents are of type
Aa × Aa, the offspring are in the proportion 1/4 type AA, 1/4 type Aa, and 1/4 type aa;
thus, brother and sister mating will give 1/16 type {AA × AA}, 1/4 type {AA × Aa}, 1/4 type
{Aa × Aa}, 1/4 type {Aa × aa}, 1/8 type {AA × aa}, and 1/16 type {aa × aa}. This information is
sufficient for determining the 6 × 6 transition matrix P in Equation 5.1 of the inbreeding
problem. The R routine involving igraph produces the directed graph of the process by
displaying the connection between the six alternatives and is followed by the R function
Markov, which generates realizations from the inbreeding process. This function depends
on the initial configuration of the process. The primary focus for Bayesian inference is
testing hypothesis, namely, the laws of inheritance for the inbreeding problem. Testing
hypothesis is based on sample information from multinomial realizations (of size 10 for
each row) of the transition matrix, then the posterior probability of the null hypothesis is
computed as .999, which implies that the laws of inheritance are valid for the inbreeding
model.
Next to be considered is the Wright model of genetics, which allows for the effect of
mutation and selection on gene frequency. Transition matrix P is shown to depend on the
binomial distribution where the two mutation rates are accounted for, and the main
emphasis is on estimating the transition probabilities.
The birth and death process is defined by fX(n), n = 0, 1, 2, :::g, where X(n) is the size of
the population at time n, and is the next subject presented in this chapter. The transition
matrix is a function of the birth and death rates, which give the probabilities of a birth and
death, respectively, at each time point. The birth and death rates depend on the present size
of the population, and the process is illustrated with birth and death rates bi = bi and di = di,
where i is the present size of the population and b = .02 and d = .03. Since the basic death rate
is more than that of the birth rate, one would expect the population to become extinct. Of
interest for the Bayesian is to estimate the time to extinction. The logistic growth process is a
special case of the birth and death process, and fundamental parameters of the process are
estimated via Bayesian methods using multinomial realizations for the data and an
improper prior distribution for the birth and death rates.
Much of this chapter is devoted to Bayesian inferences for several versions of an epi-
demic. In the simplest case at a given time point, there are two types of individuals,
infected or susceptible, in a fixed population of individuals. Also, infected individuals can
again become susceptible. A more realistic version of the epidemic process is presented as
an exercise at the end of the chapter. First to be described is the deterministic process,
which includes definitions of the basic parameters. In the stochastic version of the epi-
demic, the one-step transition matrix is defined in terms of the number of the number of
infected people in the population. b, b, and g are the fundamental parameters of the
process, and their meaning is made clear in the following explanation: Suppose the
interval between time n and time n + 1 is small enough so that at most, one event occurs.
Therefore, the following can occur: (1) a susceptible person becomes infected, (2) a sus-
ceptible person give birth (and a corresponding death of either a susceptible or infected
individual), or (3) an infected person recovers. Suppose the probability of a susceptible
individual becoming infected is bI=N, where b is the number of contacts made by one
Examples of Markov Chains in Biology 219
infectious individual that results in one infection during the interval (n, n + 1); thus, only
bS=N of these contacts may result in a new infection, and the total number of new
infections by the whole class of infected individuals is bSI=N. Suppose susceptible and
infected persons are born or die with probability b and that infected individuals recover
with probability g. The transition matrix (Equation 5.36) of the process is determined by
the three parameters b, b, and g. The Bayesian posterior analysis is executed with
WinBUGS Code 5.8, where the sample information is data generated by multinomial
realizations and an improper prior used for prior information. See Table 5.9 for infor-
mation about the posterior distribution of the fundamental parameters. Another version of
the epidemic model is presented and is called the chain binomial model because the
transition probabilities are computed according to the binomial distribution. For this
model, the parameters are a, b, and p, where a is the probability that a susceptible person
comes in contact with an infected person, b is the probability that the contact results in an
infection, and the probability a susceptible person is not infected. There are two versions
of the chain binomial model: (1) Greenwood and (2) Reed–Frost. For the Greenwood
model, the transition matrix is given by the binomial distribution where the probability
of success is given by p, whereas for the Reed–Frost model, the probability of success is
given by pi(n) , where i(n) is the number of infected at time n and the I(n) process satisfies
S(n) + I(n) = S(n − 1) for n = 1, 2, ….
A Bayesian analysis is performed for the special case s(0) = 3, and the transition matrix in
Equation 5.43 is expressed in terms of p and in terms of a and b with the transition matrix in
5.45. For the case when p = .025, multinomial realizations of size 500 are generated for each
row of the transition matrix; then assuming an improper prior distribution for p, the
Bayesian analysis is executed with 45,000 observations for the simulation and a burn-in of
5,000.
Our attention is turned to a very interesting topic in genetics, namely, that of molecular
evolution where the focus is on four sites of a strand of DNA, and each site is occupied by one
of the four bases: (1) adenine, (2) guanine, (3) cytosine, and (4) thymine. The corresponding
4 × 4 one-step transition matrix is quite special, in that, the off-diagonal entries are all the
same, namely, probability d, and this arrangement of transition probabilities is called the
Jukes–Cantor model. The time unit is one generation; thus, we will be observing the evolution
of the four bases over generations. Usually in such situations, the emphasis is on estimating
the mutation rate 3d. Bayesian inferences consist of estimating the probability of a mutation
and the mutation rate, and an example is provided with d = 1/2. The sample information is
generated using the multinomial distribution of size 50 generations, and the prior distribu-
tion is assumed to be improper, and the resulting analysis determined that the posterior mean
is .0918. Also, included in the Bayesian analysis is a test of the hypothesis that the Jukes–
Cantor model is the proper evolutionary model. It was found that the posterior probability
that this is true is p0 = :995. Lastly, the so-called Kimura model is a generalization of the
Jukes–Cantor model, and the following Bayesian analysis consists of testing the hypothesis
that the Kimura model reduces to the Jukes–Cantor model.
Finally, this concludes with a Bayesian analysis of the Ehrenfest model for diffusion
through a cell membrane. This example is quite interesting in that the model’s origin is in
statistical thermodynamics and was later adopted in biology. Finally, there are several more
references that will be of interest to the reader. With additional information about epi-
demics, see Allen19 and Anderson and May.20 A good reference for the role mathematics
plays in genetics is given by Ewens,21 and for the role stochastic processes play in epi-
demics, refer to Gabriel, Lefevre, and Picard.22
220 Bayesian Inference for Stochastic Processes
5.10 Exercises
H: P31 = 1=16, P32 = P33 = P34 = 1=4, P35 = 1=8, P36 = 1=16,
which are the rules on inheritance for the inbreeding example. As sample
information, use the first realization listed in Table 5.1. Also, assume that the
likelihood function is given by Equation 5.3.
a. Verify Equation 5.4 for the posterior probability of the null hypothesis.
b. Verify Equation 5.6.
c. Based on Equations 5.3 through 5.6, verify that the posterior probability of
the null hypothesis is .999.
Examples of Markov Chains in Biology 221
6. Refer to the transition probability matrix for the birth and death process given by
Equation 5.21, where di and bi are the death and birth rates when the population is
size i. Assume that the birth and death rates are given by bi = bi and di = di, where
b = .02 and d = .03. Thus, the birth rate is increasing at 2% for an increase of 1 in the
population size, while the death rate is increasing at a rate of 3%.
a. Refer to R Code 5.2 and generate 100 observations for the birth and death
process by using the R function Markov with an initial value of 1 person.
b. Using the R function stationary, determine the stationary distribution of this
birth and death process.
c. Generate five multinomial realizations of size 10 for the birth and death
process using the probability vector p<-c(.03,.95,.02). See Table 5.8.
d. Assume an improper prior distribution for the birth and death rates b1 and
d1 , the birth and death rates when the population consists of only one
individual. Use the fifth multinomial realization for the sample information
and execute WinBUGS Code 5.5 with 45,000 observations for the simulation
and 5,000 for the burn-in.
e. What is the 95% credible interval for d1 ?
f. Are the posterior distributions for these birth and death rates skewed?
g. Demonstrate their skewness by plotting the posterior density of the birth
and death rates.
7. Refer to the time of extinction of the birth and death given by Equation 5.28.
a. Generate multinomial realizations of size 100 of the 10 birth and death
processes shown in Table 5.17.
b. Assume an improper prior for the birth and death rates. Execute a Bayesian
analysis using WinBUGS Code 5.5 for estimating the 10 birth and death
rates b and d (where bi = bi and di = di, i = 1, 2, …, 10) and time to extinction.
Use 35,000 observations for the simulation and 4,000 for the burn-in.
c. What are the posterior characteristics for the 10 average time to extinction?
d. What are the 95% credible intervals for d3 and b3 ?
e. The posterior median of μ1 is 76.55. Does this seem reasonable to you?
TABLE 5.16
Posterior Analysis for Birth and Death Process: Fifth Realization
Parameter Mean SD Error 2 1/2 Median 97 1/2
TABLE 5.17
Multinomial Realizations for Birth and Death Process
Population Size d 1−d−b b n1 n2 n3
1 .03 .95 .02 2 97 21
2 .06 .90 .04 8 86 6
3 .09 .85 .06 7 91 2
4 .12 .8 .08 15 81 4
5 .15 .75 .10 11 76 13
6 .18 .7 .12 17 66 17
7 .21 .65 .14 22 64 14
8 .24 .6 .16 23 59 18
9 .27 .55 .18 27 57 16
10 .30 .70 28 72
9. a. Refer to Section 5.64 and describe the purpose of the parameters a, b, and 1 − ab.
b. Verify that the matrix P (Equation 5.42) is the one-step probability transition
matrix of the Greenwood model.
c. Show that Equation 5.42 reduces to the matrix Equation 5.43 when s(0) = 3.
d. As a special case, let a = :5, b = :05, and verify that the probability transition
matrix is Equation 5.44.
e. What states are transient for the special case?
f. Using the R function Markov, generate 25 observations for the epidemic with an
initial value of 2.
g. For each row of the transition matrix (Equation 5.44), generate multinomial
realizations of size 500. The result should be similar to the matrix Q (1.46).
h. Assuming a uniform prior distribution for the parameter p, show that the pos-
terior distribution of p is beta (491,11).
i. In order to estimate p and the other entries of the transition matrix in Equation
5.43, execute WinBUGS Code 5.9 with 35,000 observations for the simulation and
5,000 for the burn-in.
j. What is the 95% credible interval for p? Is this a reasonable value? Explain why.
10. The SIR model is an abbreviation for susceptible people, infected, and removed
individuals during the course of an epidemic. A person is susceptible if they have not
had the disease, infected if they currently have the disease, and removed if they
have had the disease and have since recovered (and are now immune) or have died.
Time is measured in discrete steps, and at each step, each individual can infect sus-
ceptible individuals or can recover/die, at which point, the infected is removed.
Therefore, this version of an epidemic is more realistic than the previous model. See
Jones, Maillardet, and Robinson23 for additional information about the SIR model.
Suppose S(t), I(t), and R(t) denote the number of susceptible individuals, infected, and
removed at time t, where at each time point, each infected has a probability a of
infecting each susceptible (this assumes each person has an equal chance of contact-
ing all susceptible persons). At the end of each step, after having had a chance to
infect people, each infected person has probability b of being removed. The initial
conditions are S(0) = N, I(0) = 1, R(0) = 0, where the total population is of size
N + 1 and remains fixed (is not random), that is, S(t) + I(t) + R(t) = N + 1, for all t = 0,
1, 2, ….
Note that at each time point, the chance a person remains uninfected is (1 − a)I(t) , that
is, each infected must fail to pass on the infection to the susceptible individuals. Because
each infected has a probability b of being removed,
Rðt + 1Þ ∼ RðtÞ + binðI ðtÞ, bÞ: (5.81)
Also, S(t + 1), given S(t), is binomial
h i
SðtÞ, ð1 − aÞIðtÞ : (5.82)
The following R Code for SIR stipulates the instructions for simulating the SIR epi-
demic if one knows the inputs a = a; b = b; N, the total population size; and T, the
number of time points that the epidemic is followed:
An epidemic will be simulated with the following inputs: a = .001, b = .1, N = 1000,
and T = 100. Thus, an infected person has a probability of .001 of infecting a susceptible,
while the probability is .1 that an infected is removed. Table 5.18 portrays an SIR
TABLE 5.18
Simulation of SIR Epidemic
Time S I R
1 1000 1 0
2 998 3 0
3 994 7 0
4 982 18 1
5 964 34 3
6 933 63 5
7 886 102 13
8 795 188 18
9 631 341 29
10 435 504 62
11 256 631 114
12 136 690 175
13 67 690 244
14 41 638 322
226 Bayesian Inference for Stochastic Processes
simulation with the preceding inputs. I used 100 time points, but the table displays on
the first 14 time points. It is interesting to observe that by time 14, there are already 638
infected individuals and 322 have been removed. The student should simulate the
epidemic for all 100 time points.
Now the interesting aspect of this exercise is to make Bayesian inferences for the a
and b parameters of the SIR model, given the data in Table 5.18. Does the information in
this table allow one to estimate a and b with reliable values? In order to estimate these
two parameters, the following WinBUGS Code for SIR will be used to execute the
posterior analysis. In the code, alphamean is the mean of the 13 alphas, and betameans
is the mean of the 13 betas. Assuming an improper prior for the alphas and gams, their
corresponding posterior distribution is beta. This follows from Equations 5.81 and 5.82.
The Bayesian analysis is executed with 70,000 observations for the simulation and 5,000
for the burn-in.
alpha1<-1-gam1
alpha2<-1-pow(gam2,1/2)
alpha3<-1-pow(gam3,1/3)
alpha4<-1-pow(gam4,1/4)
alpha5<-1-pow(gam5,1/5)
alpha6<-1-pow(gam6,1/6)
alpha7<-1-pow(gam7,1/7)
alpha8<-1-pow(gam8,1/8)
alpha9<-1-pow(gam9,1/9)
alpha10<-1-pow(gam10,1/10)
alpha11<-1-pow(gam11,1/11)
alpha12<-1-pow(gam12,1/12)
alpha13<-1-pow(gam13,1/13)
meanalpha<-(alpha1+alpha2+alpha3+alpha4+alpha5+alpha6+alpha7+alpha8+alpha9
+alpha10+alpha11+alpha12+alpha13)/13
}
Note that a is the posterior mean of the average of the 13 alphas, and b is the pos-
terior mean of the mean of the nine betas calculated with WinBUGS Code for SIR. The
posterior mean for a, should be compared to the value of a = .001 to generate the data
for the epidemic. In a similar way, the posterior mean of b should be compared to b = .1
used to generate the epidemic data of Table 5.18.
a. Using WinBUGS Code for SIR with 70,000 observations for the simulation with a
burn-in of 5,000, execute the Bayesian analysis appearing in Table 5.19.
b. What does the posterior distribution for a appearing in Table 5.19 imply about
a = .001 used to generate the epidemic data of Table 5.18.
c. What does the posterior distribution of b imply about b = .1, the value used to
generate the epidemic portrayed in Table 5.18?
TABLE 5.19
Bayesian Analysis for SIR Model
Parameter Mean SD Error 2 1/2 Median 97 1/2
a .02421 .000985 .0000038 .02235 .02419 .0262
b .0916 .01139 .0000413 .07213 .0906 .1167
228 Bayesian Inference for Stochastic Processes
11. Consider the Jukes–Cantor model of molecular evolution: At four sites of the DNA,
there are four different bases:
a. Adenine
b. Guanine
c. Cytosine
d. Thymine
The Jukes–Cantor model specifies that the probability transition matrix P in Equa-
tion 5.51 should have equal off-diagonal entries and, hence, equal diagonal compo-
nents. The off-diagonal entry d is the probability that a base will be substituted by a
different base, and 3d is the mutation rate.
a. Derive Equation 5.52, the probability that a base substitution has occurred.
b. Show that when d = 1/12, the transition matrix is Equation 5.53.
c. Based on the transition matrix (Equation 5.53), use the appropriate multinomial
realization of size 50 to generate transition counts for each row. Your result
should be similar to the Q matrix (Equation 5.54).
d. Verify the entries of matrix R (Equation 5.55). Consider the second row. What is
the estimated mutation rate?
e. Using the Q matrix as data and assuming an improper prior distribution
(Equation 5.56) for the transition probabilities, use WinBUGS Code 5.9 to execute
a Bayesian analysis with 35,000 observations for the simulation and 5,000 for the
burn-in.
f. Your result should be similar to that in Table 5.14 for the posterior analysis.
g. Based on the posterior mean, what is your estimate of the mutation rate 3d? Use
WinBUGS Code 5.9 to calculate the posterior mean of 3d.
Examples of Markov Chains in Biology 229
12. Refer to the Jukes–Cantor model of molecular evolution. This exercise pertains to the
Bayesian analysis for the stationary distribution and time reversibility of the Jukes–
Cantor model. Also recall the Bayesian analysis of estimating the parameters of time
reversibility. Denote the stationary distribution of a k-state chain by (π1 , π2 , :::, πk ) and let
the transition probabilities of the process be Pij , i, j = 1, 2, :::, k; then for the chain to be
time reversible
Refer to the Jukes–Cantor transition matrix (Equation 5.53) in the special case d = 1/12.
a. Find the stationary distribution for the transition matrix (Equation 5.53).
b. Use the Q matrix (Equation 5.54) as the sample information. Make an appropriate
revision of WinBUGS Code 4.6 and use the modification to estimate the stationary
distribution of the Jukes–Cantor model. Note that the stationary distribution has
four components.
c. Based on the stationary distribution found in item b, perform the Bayesian
analysis for determining the time reversibility. You will need to write WinBUGS
Code similar to WinBUGS 4.8, and your results should be presented in the same
format as that of Table 4.13.
d. Based on the analysis described in item c, is the Jukes–Cantor time reversible?
Explain your answer carefully!
13. a. Refer to Section 5.8 and briefly describe the Ehrenfest cell diffusion model with 2N
total molecules and state space
S = f0, 1, 2, ::::, 2N g:
b. What is the transition probability matrix for the cell diffusion model? See Equa-
tion 5.70, and the general form of the transition matrix is given by Equation 5.71.
c. Consider the special case N = 5 with transition probability Q and transition counts
T. Assume an improper prior distribution for the rows of the transition proba-
bility matrix. Note that the Ehrenfest model must satisfy the null hypothesis
(Equation 5.74). Using this information and employing Equations 5.75 through
5.79, test the null hypothesis (Equation 5.74). Calculate the posterior probability
of the null hypothesis p0 in Equation 5.78 as .998.
230 Bayesian Inference for Stochastic Processes
References
1. Allen, J. S. L. 2011. An Introduction to Stochastic Processes with Applications to Biology, Second Edition.
Boca Raton, FL: CRC Press.
2. Hoppensteadt, R. 1975. Mathematical Methods of Population Biology. Cambridge, UK: Cambridge
University Press.
3. Bailey, N. T. J. 1990. The Elements of Stochastic Processes with Applications to the Natural Sciences.
New York: John Wiley & Sons.
4. Feller, W. 1968. An Introduction to Probability Theory and Its Applications. New York: John Wiley &
Sons.
5. Wright, S. 1932. The roles of mutation, inbreeding, crossbreeding, and selection in evolution,
Proceedings of the 6th International Congress in Genetics 1:356–366.
6. Fisher, R. A. 1962. The Genetical Theory of Natural Selection. New York: Oxford (Clarendon) Press.
7. Karlin, S., and Taylor, H. M. 1975. A First Course in Stochastic Processes, Second Edition. New York:
Academic Press.
8. DeGroot, M. H. 1970. Optimal Statistical Decisions. New York: McGraw-Hill.
9. Dobrow, R. P. 2016. Introduction to Stochastic Processes with R. New York: John Wiley & Sons.
10. Allen, L. J. S., and Burgin, A. 2000. Comparison of deterministic and stochastic SIS and SIR models
in discrete time, Mathematical Biosciences 163:1–33.
11. Daley, D. J., and Gani, J.1999. Epidemic Modeling: An Introduction. Cambridge Studies in Mathematical
Biology 15. Cambridge, UK: Cambridge University Press.
12. Allman, E. S., and Rhodes, J. A. 2004. Mathematical Models in Biology, An Introduction. Cambridge,
UK: Cambridge University Press.
13. Jukes, T. H., and Cantor, C. R. 1969. Evolution of protein molecules, in Munro, H. N. (Ed.)
Mammalian Protein Metabolism. New York: Academic Press.
14. Kimura, M. 1990. A simple method for estimating evolutionary rates of base substitutions through
the comparative studies of sequence evolution, Journal of Molecular Evolution 16:111–120.
15. Futuyma, D. J. 2013. Evolution, Third Edition. Sunderland, MA: Sinauer.
16. Kannan, D. 1979. An Introduction to Stochastic Processes. New York: Elsevier (North Holland).
17. Ehrenfest, P., and Ehrenfest, T. 1907. Über zwei bekannte Einwände gegen das Boltzmannsche
H-Theorem, Physikalishce Zeitschrift 8:311–314.
18. Bellman, R., and Harris, T. E. 1951. Recurrence time for the Ehrenfest model, Pacific Journal of
Mathematics 1:179–193.
19. Allen, L. J. S. 2000. Some discrete time SI, SIR, and SIS epidemic models, Mathematical Biosciences
124:83–105.
20. Anderson, R. M., and May, R. M. 1992. Infectious Diseases in Humans: Dynamics and Control.
Oxford, UK: Oxford University Press.
21. Ewens, W. J. 1979. Mathematics Population Genetics. Berlin: Springer-Verlag.
22. Gabriel, J. P., Lefevre, C., and Picard, P. 1990. (Editors). Stochastic Processes in Epidemic Theory:
Lecture Notes in Biomathematics. New York: Springer-Verlag.
23. Jones, O., Maillardet, R., and Robinson, A. 2014. Introduction to Scientific Programming and Simu-
lation Using R. Boca Raton, FL: Taylor & Francis.
6
Inferences for Markov Chains in Continuous Time
6.1 Introduction
Our main goal for this chapter is to present Bayesian inferences for processes in continu-
ous time. As in earlier chapters, Bayesian ways to estimate parameters, test hypotheses
about those parameters, and predict future observations will be developed. There are many
examples of Markov chains in continuous times, and the best known is the Poisson process.
The Poisson process is a counting process that records many interesting events such as
the number of accidents in a given stretch of highway over a selected period, the number of
telephone calls at a switchboard, the arrival of customers at a counter, the number of visits
to a website, earthquake occurrences in a particular region, etc.
The definition of the Poisson process begins this chapter, which is followed by a
description of the arrival and interarrival times, then various generalizations are considered
such as the nonhomogeneous Poisson processes, which include compound processes and
processes that contain covariates. Of course, R is employed to generate realizations from
the several examples of homogeneous and nonhomogeneous Poisson processes.
231
232 Bayesian Inference for Stochastic Processes
4. The process has independent increments; that is, for 0 ≤ q < r ≤ s < t, N(t) −
N(s) and N(r) − N(q) are independent.
Consequently, the distribution of the number of events depends only on the length
of the interval. It should be noted that the mean and variance of the process are
E½N(t) = Var½N(t) = lt for all t > 0. The next definition of a Poisson process is given
in terms of the arrival times of the events. The arrival times are the times the event
occur while the interarrival times are the times between consecutive events. It will be
shown that the interarrival times are independent and have identical exponential
distributions.
• Definition b
For a Poisson process with parameter l, let Y be the time of the first arrival after
time 0, then
Sn = Y1 + Y2 + ::: + Yn :
Thus, the interarrival time between event k − 1 and the kth one is
Yk = Sk − Sk−1 , k = 1, 2, ::: :
and moments
EðSn Þ = n=l
and
VarðSn Þ = n=l2 :
Inferences for Markov Chains in Continuous Time 233
• Definition c
A Poisson process with parameter l is a counting process fN(t), t ≥ 0g, satisfying
the following properties:
1. N(0) = 0
2. The process has stationary and independent increments
3. P½N(t) = 0 = 1 − lh + o(h)
4. P½N(t) = 1 = lh + o(h) (6.4)
5. P½N(t) > 1 = o(h)
where h ! 0 and o(h)=h ! 0.
Thus, the first event arrives at time 2.976133; the second, at time 3.248414; and the last, the
12th, at time unit 39.28297; consequently, N(39:28) = 12.
Consider the following fact about the minimum n of independent exponential random
variables Y1 , Y2 , :::, Yn with parameters l1 , l2 , :::, ln , respectively.
Let M = min (Y1 , Y2 , :::, Yn ) t and t > 0; then
The first assertion earlier implies that M has an exponential distribution with parameter
l1 + l2 + ::: + ln .
The statistical problem is to generate realizations from the n Poisson processes and then
estimate the probabilities given by 1 and 2 earlier.
R Code 6.1 is used to generate realizations from n = 3 processes mentioned in the fol-
lowing interesting problem described on pages 231 and 232 of Dobrow.1
A bus station serves three routes labeled 1, 2, and 3. Buses on each route arrive at the bus
station according to three independent Poisson processes. Buses on route 1 arrive at the
station on the average every 10 minutes, those on route 2 arrive on the average every 15
minutes, while route 3 buses arrive on the average every 20 minutes.
1. When a person arrives at the station, what is the probability that the first bus to
arrive is from route 2?
2. On average, how long will the person wait for some train to arrive?
3. The person has been waiting for 20 minutes for a bus on route 3 to arrive and
during this time, three route 1 buses arrive at the station. What is the expected
additional time the person will have to wait for the arrival of a route 3 bus?
Note that we have three independent Poisson processes with parameters l1 = 10, l2 = 15,
and l3 = 20. Since the parameters are known, it is straightforward to calculate these
probabilities. Let Y1 , Y2 , and Y3 denote the waiting times for buses from routes 1, 2, and 3,
respectively, then it is known that Y1 e exp (1=10), Y2 e exp (1=15), and Y3 e exp (1=20).
To answer question 1, note that the desired probability is given by Equation 6.6, namely,
Now let us take the role of a statistician where the three Poisson parameters are unknown,
but that one has information about the waiting time for passengers at the bus station. One
has available observations for the waiting times Yi , i = 1, 2, 3, which will be generated with
R Code 6.1, and t = 120 minutes.
When l1 = 1=10, there are 14 arrivals with the following waiting times:
When l2 = 1=15, there are 9 arrivals with the following waiting times:
Lastly, when l3 = 1=20, there are 8 arrivals with corresponding waiting times (minutes) as
follows:
Bayesian inferences for the parameter of a Poisson process are well known, and the
reader is referred to Chapter 6 of Dobrow,1 Chapter 5 of Insua, Ruggeri, and Wiper,2
and Albert.3
Suppose Y1 , Y2 , :::, Yn is a random sample from an exponential population of size n
with parameter l and corresponding observations y1 , y2 , :::, yn , then the likelihood
function for l is
!
X
i=n
lðljdataÞ ∝ l n exp −l yi , l > 0: (6.8)
i=1
X
i=n
Note that yi is the waiting time to the nth event.
i=1
Prior information will be expressed with the gamma distribution with density
In the former case with the gamma prior, the posterior distribution of l is gamma (n +
X
i=n X
i=n
a, b + yi ), while for the improper prior, the posterior distribution is gamma (n, yi ).
i=1 i=1
If one uses the improper prior density (Equation 6.10), the posterior density of l1 is
gamma (15,109.65), implying that the posterior mean is 15/109.65 = .1367, and the posterior
variance is 15/(109.65)(109.65) = .001247, and the 95% credible interval is (.1087,.215). Now
consider the estimation of l2 , the per unit average waiting time for the second route, then
the posterior mean is 9/115.96 = .0776 and posterior variance is 9/(115.96)(115.96) = .00066
with a 95% credible interval of (.06,.136). Lastly, for the third bus route with parameter l3 ,
the posterior mean is 8/112.26 = .0712 with posterior variance .000634 = 8/(112.96)(112.96).
The 95% credible interval is (.055,.13).
We now present the Bayesian analysis using WinBUGS Code 6.1 to determine the pos-
terior distribution of
Assuming that the improper prior density (Equation 6.10), recall that the posterior dis-
tribution of li , i = 1, 2, 3, is known, namely,
l1 e gammað14,109:65Þ,
l2 gammað9,115:96Þ,
e
and
l3 e gammað8,112:26Þ:
236 Bayesian Inference for Stochastic Processes
The Bayesian analysis is executed with 35,000 observations for the simulation with a
burn-in of 1,000, giving the results in Table 6.1.
The main parameter of interest is P½M = l2 jdata, the posterior probability that the first
train to arrive at the station is from bus route 2.
A point estimate of this parameter is given by the posterior mean of .2808 with a 95%
credible interval of (.1417,.4477). Note the Monte Carlo Markov chain (MCMC) error is
quite small at .00029.
Our next objective is to conduct a formal test of the null hypothesis
The data used will be the 14 waiting times at the bus station for busses on route 1, namely,
7.922561, 31.770897, 50.570418, 57.364507, 57.593699, 61.285045, 70.839773, 78.795652,
83.963642, 84.830358, 91.112292, 94.419953, 106.066164, 109.656950.
The test will be based on the 14th waiting time S14 , which has a gamma distribution with
density
h i
f ðs14 jl1 Þ = l14 s
1 14
14−1
exp ð −l 1 14 =G ð14Þ,
s Þ s14 > 0: (6.13)
Thus, S14 has a gamma distribution (14, l1 ), and the observed value of S14 is 109.6569.
Pages 126 and 127 of Lee4 will be closely followed for details about the Bayesian approach
to testing hypotheses (Equation 6.12), a simple null versus a composite alternative
hypothesis.
The Bayesian test is based on the posterior probability of the null hypothesis given by
TABLE 6.1
Posterior Distribution for Arrivals at Bus Station
Parameter Mean SD Error 2 1/2 Median 97 1/2
ð
f1 ðs14 Þ = r1 ðl1 Þf ðs14 jl1 Þ dl1 , (6.16)
where the integral is over the interval (0, ∞), and r1 (l1 ) is the prior density of l1 under the
alternative hypothesis. How does one choose r1 (l1 )? If one chooses this prior as gamma
(a,b), one can show
Now the problem is to choose a and b. Remember that the mean of the prior
gamma is E(l1 ) = a=b and the variance is Var(l1 ) = a=b2 . Suppose a = :1 and b = 1, then
E(l1 ) = :1 = Var(l1 ).
It can be shown that f (s14 jl1 = :1) = 9:2589289 and f1 (s14 ) = 0; thus, with π0 = π1 = :5 and
based on Equation 6.14, the posterior probability of the null hypothesis is p0 = 1. The evi-
dence provided by the 14th waiting time together with the prior information imply that the
null hypothesis is true.
Note the sensitivity of p0 to the prior probabilities of the null and alternative hypotheses
and to the prior distribution of l1 under the alternative hypothesis.
The third phase of the Bayesian inference is to develop the Bayesian predictive distri-
bution of S15 , the 15th waiting time for the first bus route based on the posterior distribution
of l1 induced by S14 .
ð∞
f ðs15 js14 Þ = f ðs15 jl1 Þ f ðl1 js14 Þdl1 , (6.18)
0
where
h i
f ðs15 jl1 Þ = l15 15−1
1 s15 expð−l1 s15 Þ =G ð15Þ, s15 > 0 (6.19)
and
h i
f ðl1 js14 = 109:65Þ = l14
1 expð−l1 ð109:65ÞÞ =Gð14Þ, l1 > 0: (6.20)
The student will be asked to compute the density in Equation 6.21 by using the following
code:
WinBUGS Code 6.2
model;
{
# posterior distribution of lamda1
lamda1~dgamma(15,109.65)
# predictive density of s15
s15~dgamma(15,lamda1)
}
238 Bayesian Inference for Stochastic Processes
I executed the analysis with WinBUGS Code 6.2 using 270,000 observations for the
simulation and a burn-in of 5,000, where the results are reported in Table 6.2.
Table 6.3 contains 100 values generated from the predictive density (Equation 6.21).
Note that the predictive distribution appears to be skewed to the right with a mean of
117.3 and a median of 109.9. The right skewness is evident in Figure 6.1.
TABLE 6.2
Bayesian Predictive Distribution for Bus Route 1
Parameter Mean SD Error 2 1/2 Median 97 1/2
TABLE 6.3
Future Values of S15
83.77,89.58,160.6,74.27,87.25,
76.97,94.05,100.0,101.0,80.83,
69.22,77.03,73.96,120.8,133.0,
112.6,91.21,94.86,144.0,131.3,
77.8,103.1,72.66,115.2,129.3,
63.82,74.24,112.5,123.1,92.33,
142.9,93.23,53.3,98.26,105.8,
101.3,81.08,65.44,72.09,111.7,
97.93,62.18,118.9,71.02,102.4,
81.03,103.7,98.24,110.5,107.6,
102.8,96.02,82.43,113.5,88.26,
52.24,61.58,113.2,106.7,90.15,
84.26,110.1,73.8,89.37,93.89,
111.7,62.92,90.31,92.29,94.87,
92.22,156.8,76.08,78.1,96.15,
90.96,127.8,96.16,84.85,71.09,
86.75,106.5,149.2,92.08,74.57,
99.08,85.64,99.83,71.1,76.48,
141.2,51.87,84.59,87.38,73.04,
146.7,105.9,114.1,54.26,110.3
Inferences for Markov Chains in Continuous Time 239
P(S15)
0.01
0.0
0.0 200.0 400.0 600.0
S15
FIGURE 6.1
Predictive density of S15 .
1. On an 8-hour shift, what is the expectation and standard deviation of the number of
female births?
2. Find the probability that only girls were born between 2 p.m. and 5 p.m.
3. Assume that three babies were born at the hospital yesterday. Find the probability
that two are female.
Suppose that fN(t), t > 0g, fM(t) > 0g and fF(t), t > 0g denote the overall, male, and
female processes, respectively, and consider the first problem (1) earlier. It is obvious that
240 Bayesian Inference for Stochastic Processes
the females form a Poisson process with parameter l(1 − p) = 2(1 − :519) = :962 births per
hour. Therefore, the mean of the number of female births over an 8-hour process is
E½F(8) = 8ð2Þð:481Þ = 7:696 = Var½Fð8Þ, (6.22)
the average number of female births over an 8-hour period.
Now consider problem 2, namely,
P½Mð3Þ = 0, Fð3Þ > 0 = P½Mð3Þ = 0P½Fð3Þ > 0
= exp½−2ð:519Þ4½1 − expð−2ð:481Þ3Þ = :042:
Lastly, for problem 3, the desired probability is
!
3
ð:481Þ2 ð:519Þ = :3602: (6.23)
2
The solution to problems 1, 2, and 3 are based on the “true” values of l and p; however, in
practice, these true values are not available. Instead what is available are observations from
the three processes fN(t), t > 0g, fM(t) > 0g, and fF(t), t > 0g. From the overall process,
one can estimate l, and from that, for males, one can estimate pl and, consequently, p.
R Codes 6.2 and 6.3 generate observations for the overall births over an 8-hour period with a
birth rate of l per hour and generate male births with 2(.519) = 1.038 births per hour.
R Code 6.2
> t<-8
> lamda<-2
> N<-rpois(1,lamda*t)
> unifs<-runif(N,0,t)
> births<-sort(unifs)
> arrivals
1.263526, 1.414724, 1.593349, 2.248500, 2.329316, 2.597407,
2.653645, 2.861839, 3.654373, 3.881924, 4.310339, 4.450808, 5.0
5.008346, 5.085663, 5.315546, 6.850246, 7.320440, 7.524868.
R Code 6.3
> t<-8
> lamda<-1.038
> N<-rpois(1,lamda*t)
> unifs<-runif(N,0,t)
> malebirths<-sort(unifs)
> malebirths
1.284937, 1.861346, 2.364378, 2.823737, 3.577798, 4.628334,
5.542943, 6.022781, 6.304477, 6.743645, 6.779419.
There are 18 overall births with 11 male births over the 8-hour period, which implies a
maximum likelihood estimate of 18/8 = 2.25 births per hour for the overall birth rate, while
that for the male birth rate, the estimate is 11/8 = 1.375, and consequently, the maximum
likelihood estimate of p is 1.375/2.25 = .611. The overall rate of 2.25 should be compared to
2, the value used to generate the data with R Code 6.2. In the same way, the male birth rate
estimate of .611 should be compared to the true value of .519.
Inferences for Markov Chains in Continuous Time 241
TABLE 6.4
Bayesian Analysis for Overall and Male Birth Rates
Parameter Mean SD Error 2 1/2 Median 97 1/2
What is the Bayesian approach to estimating the overall and male birth rates over an
8-hour period? First, consider estimating the overall birth rate l, using the conditional dis-
tribution of the waiting time S18 , given l as the likelihood function. When this is combined
with the improper prior density (Equation 6.10), the posterior distribution of l is gamma
(18, S18 ), where S18 = 7:524868. In a similar fashion, it can be shown that the posterior
distribution of g = pl is gamma (11,6.779419).
WinBUGS Code 6.3
model;
{ lamda~dgamma(18,7.5248)
gam~dgamma(11,6.7794)
p<-gam/lamda
}
WinBUGS code 6.3 is executed with 70,000 observations for the simulation with a burn-in
of 5,000, and the Bayesian analysis is reported in Table 6.4.
The posterior distributions for p and g are skewed; thus, I recommend the posterior
median as the estimate of the parameter. For example, the posterior median of g is 1.572,
which should be compared to g = pl = 1.038, the true value of that parameter. In the same
manner, the posterior median of l of 2.343 should be compared to the true value of l = 2.
Also, the true value of p is .519, which should be compared to the posterior median of .672.
These so-called true values are the values used to generate the realizations from the relevant
Poisson process via R Codes 6.2 and 6.3. One can see the uncertainty of posterior estimates
induced by the sample realizations.
The preceding description of the earthquake analysis is from pages 126–130 of Insua,
Ruggeri, and Wiper,2 and in order to complete the analysis, the data in Table 6.5 are used.
Inferences for Markov Chains in Continuous Time 243
TABLE 6.5
Data for Three Areas
X
i=n X
i=n X
i=n
xi yi zi
n
i=1 i=1 i=1
TABLE 6.6
Posterior Distributions for the Earthquakes in Italy
p ~ beta(,) μ ~ beta(,) l ~ gamma(,)
How should the hyperparameters be assigned? According to page 129 of Insua, Ruggeri,
and Wiper,2 the hyperparameters are chosen on the basis of the following argument: A
major earthquake occurs with probability p, and since major quakes are less likely than
minor earthquakes, p is close to zero, consequently, a1 = 2 and b1 = 8, giving a prior mean of
E(p) = 1/5. It is approximately true that major earthquakes occur every 10 years, and the
investigators choose b3 = 4 and a3 = 2 to reflect that prior information. Now consider μ and
remember that it is very close to the number 1; the corresponding hyperparameters are
chosen as a2 = 8 and b2 = 2, implying that the prior mean is 4/5. When this prior infor-
mation is combined with the posterior distributions (Equation 6.27), one can verify the
posterior distribution of the three parameters for the three areas given by Table 6.6.
A more detailed analysis is provided with WinBUGS Code 6.4, and the code lists the
posterior distribution of the three parameters of the three areas, and the analysis is executed
with 45,000 observations for the simulation and a burn-in of 5,000:
TABLE 6.7
Bayesian Analysis for Earthquakes in Italy
Parameter Mean SD Error 2 1/2 Median 97 1/2
Upon comparing Table 6.7 with Table 5.3 of page 130 of Insua, Ruggeri, and Wiper,2 the
agreement is remarkable, but note that Table 6.7 is much more informative. For example, in
addition to the posterior mean and standard deviation, the posterior median and the upper
and lower posterior of 2½ percentiles are reported. One can assess the symmetry of the
posterior distributions, and one sees the first nine posterior distributions appear to be
symmetric about their posterior means.
Also analyzed is the parameter of the interarrival time of major earthquakes, namely,
ti = li pi , i = 1, 2, 3; thus, the mean interarrival times between major earthquakes for area i is
ki = 1=ti . For example, with area 1, the posterior median is 11.7 years, an estimate of the
time between consecutive earthquakes. On the other hand, the posterior median for the
time between major earthquakes for area 2 is 4.896. Also, it is apparent that the three
posterior distributions for the three times between consecutive earthquakes are skewed to
the right. The gamma distribution appears to be a good approximation to these three
posterior distributions.
Our next effort is directed toward determining the predictive distributions of the three
series of observations X, Y, and Z. Consider the predictive mass function of Y(n + 1), the
future value of the magnitude of the (n + 1)st major earthquake; then we know that the
conditional mass function is
and that the posterior distribution of μ is beta(11, 11); thus, the predictive density function is
where
! !
X
i=n X
i=n
f1 = ðn + 11ÞG n + 11 + yi + 11 G yi + 11 + yðn + 1Þ (6.30)
i=1 i=1
and
! !
X
i=n X
i=n
f2 = G yi + 11 G n + 11 + yi + 11 + yðn + 1Þ + 1 : (6.31)
i=1 i=1
Note that the predictive mass function is pertinent for area 1 (see Table 6.6); thus, to
X
i=n
compute the future mass function value, let yi = 9.
i=1
This section is concluded with a formal test of hypothesis about the mean interarrival
times ki = 1=ti , i = 1, 2, 3, between the three areas. For simplicity, consider the null
hypothesis
H: k 1 = k 2 versus A: k 1 ≠ k 2 : (6.32)
That is to say, the null hypothesis is that the interarrival time between major earthquakes
between the first and second areas is the same versus the alternative that they are not the
same. The probability of the null hypothesis is given by
ð∞
p0 = π0 f ðs3 , s16 jkÞr0 ðk Þdk=D, (6.33)
0
where r0 is the prior density of k, the common value of k 1 and k 2 under the null hypothesis
(k 1 = k 2 = k), and π0 is the prior probability of the null hypothesis with π1 = 1 − π0 . Also S3
and S16 are the waiting times for the 3rd and 16th major earthquakes of area 1 and area 2,
respectively.
ð∞
D= f ðs3 , s16 jkÞr0 ðk Þdk + π1 f ðs3 , s16 Þ, (6.34)
0
where
h i
f ðs3 , s16 jkÞ = k n1 +n2 s3n1 −1 s16
n2 −1 −k (s3 +s15 )
e =Gðn1 ÞGðn2 Þ, (6.35)
ð∞ h i
f ðs3 , s16 jkÞr0 ðk Þdk = ba Gðn1 + n2 + aÞs3n1 −1 s16
n2 −1
=Gðn1 ÞGðn2 ÞGðaÞðs3 + s16 Þn1 +n2 +a ,
0 ð∞ð∞
f ðs3 , s16 Þ = f ðs3 , s16 jk 1 , k 2 Þr1 ðk 1 , k 2 Þ dk 1 dk 2 , (6.37)
0 0
where r1 is the prior density of k 1 and k 2 under the alternative hypothesis. Note that
h ih i
f ðs3 , s16 jk 1 , k 2 Þ = k n1 1 s3n1 −1 e−s3 k1 =Gðn1 Þ k n2 2 s16
n2 −1 −s16 k2
e =Gðn2 Þ , (6.38)
Thus,
f ðs3 , s16 Þ = ba1 1 ba2 2 Gðn1 + a1 ÞG(n2 +2 ) =Gða1 ÞGða2 ÞGðn1 ÞGðn2 Þðs3 + b1 Þðn1 +a1 Þ ðs16 + b2 Þðn2 +a2 Þ
The preceding expressions (Equations 6.34 through 6.39) depend on known quantities,
namely, known parameters of prior information or of sample information, and these are
now listed.
The sample information consists of observing three major earthquakes in area 1 where the
third occurred after 9 years, while for the second area, the waiting time for 16 quakes was
53 years,
The following is prior information for the average interarrival times between earthquakes
of area 1, a1 = :11 and b1 = :01.
Note the prior mean for k 1 is a1 =b1 = 11 with prior variance a1 =b21 = 1100.
The following is prior information for k 2 , the average time between major earthquakes of
area 2. b2 = :01 and a2 = :1.
Thus, E(k2 ) = a2 =b = :05=:01 = 5, and Var(k2 ) = a2 =b22 = :05=(:01)2 = 500.
Lastly, the common values of the average interarrival time between major earthquakes
are a = :07, b = :01, E(k) = a=b = :07=(:01) = 7, and Var(k) = a=b2 = :07=(:01) = 700.
One must assign a value to π0 which I take to be .5 because I am not sure which
hypothesis, the null or alternative, is the true. Using this information, it is left to the reader
to calculate the posterior probability of the null hypothesis p0 (Equation 6.33).
dimension, |A| would be a length; in two dimensions, an area; etc.); then the spatial
Poisson process {N(A), A ⊂ Rd } is defined as follows:
Note how properties 1 and 2 generalize the Poisson process to higher dimensions, where
1 is the generalization of stationary increments and 2 is a generalization of independent
increments.
Consider the following problem, in two dimensions with parameter l = 1=3, then what is
the probability that a circle of radius 2 centered at (3,4) contains five points?
Let C denote the circle, where |C| = πr2 = 4π; then
Recall how the uniform distribution arises with a Poisson process in one dimension, and
one sees that it generalizes to the spatial case. Suppose N(A) = n, then the locations of the
points in A are uniformly distributed in A. In order to simulate a spatial Poisson process,
first simulate a Poisson process with parameter ljAj, then generate n points uniformly
distributed in A. R Code 6.4 generates a realization from a Poisson process with parameter
l = 100 on the unit square. Circle C inside the square is centered at (.7, .7) with radius r = .2.
The simulation was repeated 100,000 times, counting the number of points in the circle at
each location. Figure 6.2 depicts one realization of the simulation, and Tables 6.8 and 6.9 list
the x and y coordinates of the points appearing in the square. Refer to Table 6.10 for the
results of the simulation.
1.0
0.8
0.6
y points
0.4
0.2
0.0
x points
FIGURE 6.2
Spatial Poisson process l = 100.
248 Bayesian Inference for Stochastic Processes
R Code 6.4
lamda<-100
> squarearea<-1
> trials<-100000
> simlist<-numeric(trials)
> lamda*pi*(0.2)^2
[1] 12.56637
> plot(xpoints,ypoints)
TABLE 6.8
Abscissa for Spatial Poisson
0.69947304, 0.752098439, 0.123763154, 0.296506146, 0.928317846,
0.429585261, 0.488405587, 0.697309565, 0.993607834, 0.532608426,
0.756079691, 0.826716592, 0.034607809, 0.730601819, 0.118687329,
0.852127976, 0.263830818, 0.793649223, 0.745337202, 0.176954050,
0.452190885, 0.038280711, 0.734769342, 0.901897682, 0.042760698,
0.493274997, 0.367916513, 0,81977386, 0.624886743, 0.867079208,
0.960224926, 0.725773072, 0.225712035, 0.818893997, 0.884597214,
0.577080285, 0.572040944, 0.08996827, 0.195316027, 0.189498151,
0.095972550, 0.038441649, 0.061324936, 0.307401637, 0.999510041,
0.257187202, 0.707372153, 0.477685743, 0.993814115, 0.213965860,
0.147804266, 0.045082209, 0.166208690, 0.188101258, 0.264188643,
0.613630638, 0.003161575, 0.810800111, 0.563908210, 0.989670485,
0.676237988, 0415593890, 0.545226286, 0.565639704, 0.723113632,
0.205693715, 0.291846363, 0.833905545, 0.222310579, 0.627019410,
0.918520986, 0.233912573, 0.933558643, 0.943388963, 0.647354387,
0.455108665, 0.251903168, 0.511865139
Inferences for Markov Chains in Continuous Time 249
TABLE 6.9
Ordinate Spatial Poisson
0.26124186, 0.44396077, 0.72392878, 0.49111736, 0.89497749,
0.99227313, 0.56237175, 0.86285194, 0.77451082, 0.03185146,
0.71030768, 0.43206807, 0.83520226, 0.65923869, 0.80783829,
0.99454636, 0.19521338, 0.92224793, 0.16692210, 0.65440660,
0.13786445, 0.17622265, 0.47331905, 0.78017173, 0.66753798,
0.90558875, 0.70708760, 0.22333211, 0.61457419, 0.72894909,
0.70386713, 0.44872583, 0.95518757, 0.40273958, 0.82697592,
0.59400583, 0.76483304, 0.18288699, 0.30049257, 0.27454940,
0.44961878, 0.08830324, 0.35170958, 0.43822516, 0.81478120,
0.13588946, 0.82128662, 0.01149270, 0.68743833, 0.57614086,
0.20674913, 0.80565632, 0.94538263, 0.70551711, 0.58287165,
0.42483037, 0.90379620, 0.53658911, 0.16208827, 0.06086748,
0.47875291 0.64352514, 0.75371784, 0.16645801, 0.53436726,
0.31414601, 0.30729664, 0.33627592, 0.36142669, 0.81547725,
0.66096427, 0.71732857, 0.67960241, 0.57335401, 0.41865694,
0.47824777, 0.10624367, 0.69410526
TABLE 6.10
Number of Points in Target Circle C
Counts 0–4 5–9 10–14 15–19 20–24 25–29
The reader should refer to pages 249–252 of Dobrow1 for additional information about
this simulation.
Of course, spatial statistics is an active area of research, and for additional details, refer to
pages 249–252 of Bivand, Pebesma, and Gomez-Rubio;10 and for a Bayesian perspective, to
Blangiardo and Camdelli.11 The R package spatstat is very useful for additional ideas about
the simulation of spatial processes similar to the Poisson. See the technical report from
the University of California, Los Angeles ([Link]
/0094/spatial_R_1_09S.pdf.).
For example, R Code 6.5 is another way to simulate a spatial Poisson process with
intensity function f (x, y) = 50(x2 + y2 ). One must employ the R package spatstat.
A plot of the simulation is portrayed in Figure 6.3.
R Code 6.5
From a Bayesian viewpoint, how would one estimate the parameter l of a spatial Poisson
process with parameter l with probability mass function
pp1
FIGURE 6.3
Spatial Poisson process with intensity f (x, y) = 50(x2 + y2 ).
with the likelihood function (Equation 6.40), then via the Bayes theorem, the posterior
distribution of l is gamma with parameters k (the observed number of points appearing in
subset A) and the size of A, namely, jAj. Recall the previous simulation where l = 100 and A
is the circle centered at (.7,.7) with radius A; thus, jAj = πr2 = :12566.
I used WinBUGS Code 6.5 for the Bayesian estimation of l with 45,000 observations for
the simulation and a burn-in of 5,000. Referring to Table 6.10, the number of points in A is
varied from 1 to 20.
model;
{
for ( k in 1:20){
delta[k]~dgamma(k,.125)}
}
Table 6.11 reports the posterior distribution of l for various values of k, the observed
number of points appearing in the subset A.
As k varies from 1 to 20, the posterior median of l varies from 5.544 to 157.5. Recall that
the value of l used for the simulation is 100; thus if in fact, the observed value of k is 13; the
Inferences for Markov Chains in Continuous Time 251
TABLE 6.11
Posterior Distribution of the Poisson Rate Parameter l
k Mean SD Error 2 1/2 Median 97 1/2
posterior mean is 101.6, a “good” estimate of l. On the other hand, if the observed value of k
is 3, the posterior median is 21.3, somewhat far away from the true value l = 100. This
shows how the sample variation affects the posterior median on the observed number of
points in the circle! Remember when l = 100, and the preceding spatial Poisson process has
parameter jAj = :1256 per unit area.
The last stage for Bayesian inferences for spatial Poisson processes is to test the hypothesis
Recall the case discussed previously where simulations were generated from a spatial
Poisson process with l = 100. See Figure 6.2 for a graph of the simulations, Table 6.10 for the
counts of the number of points in the target circle of radius .2, and, finally, the estimation of
l depicted in Table 6.11. All this information is needed to implement the Bayesian test of H
versus A.
The posterior probability of the null hypothesis is
where
h i
gðkjl = 100Þ = ð100jAjÞk expð−100jA j Þ =k !, (6.44)
252 Bayesian Inference for Stochastic Processes
ð∞
g1 ðkÞ = z1 ðlÞgðkjlÞ dl, (6.45)
0
h i
gðkjlÞ = ðljAjÞk expð−ljA j Þ =k !, (6.46)
and
is the prior density of l under the alternative hypothesis (l ≠ 100). Thus, one must choose
the hyperparameters a and b. If one chooses an improper prior for, l, namely, z1 (l) = 1=l,
one can show
and
thus,
p0 = :5865, (6.50)
which implies that the null hypothesis is indeed plausible. In the exercises, the reader will
be asked to compute p0 for values of k = 1, 2, …, 20.
This concludes the presentation of Bayesian methods for estimating the parameter of a
spatial Poisson process.
parameters li for the cases, namely, of independence of and complete and partial similarity
between the k processes.
6.6.1 Independence
This is the simplest case where the intersections are far enough away from each other, and
one would not expect the accidents at intersection i to affect those at intersection j. Thus, the
usual inferential procedures would be repeated for each of the k intersections; that is, if one
uses a gamma prior for li , the posterior is also gamma. See Section 6.3.
X
i=k
ni !
Y
i=k X
i=k
LðljdataÞ ∝ ðlti Þni expð−lti Þ = l i=1 exp −l ti , l > 0:
i=1 i=1
Therefore, if the prior distribution for l is gamma (a,b), the posterior distribution of l is
Xi=k X
i=k
also gamma ( ni + a, ti + b). With an improper prior for l, its posterior distribution is
i=1 i=1
X
i=k Xi=k X
i=k X
i=k
gamma ( ni , ti ) and a posterior mean of E(ljdata) = ni = ti .
i=1 i=1 i=1 i=1
Suppose that over a 24-hour period, one expects to see on the average of seven accidents
at six intersections of the city. Let us generate data for the six intersections over a 10-day
period.
For example, R Code 6.6 generates observations for an intersection over a 10-day period.
R Code 6.6
> t<-10
> lamda<-7
> N<-rpois(1,lamda*t)
> unifs<-runif(N,0,t)
> arrivals<-sort(unifs)
> arrivals
See the following for the hourly arrival times for 10 days:
Thus, for day 10, there were seven accidents with the first accident occurring at .13 (of a
24-hour day), and the last, at .908 of a 24-hour day = 21.79 hours. Over the 10-day period,
there were five accidents where the last accident occurred at hour 9.9 of day 10; thus, the
usual estimate of l is 55/9.9 = 5.6 accidents per hour.
If one uses an improper prior for l, the posterior distribution for l is gamma (56,9.9).
The Bayesian analysis is executed with 35,000 observations for the simulation with a
burn-in of 5,000, and the results are reported in Table 6.12.
Recall that the accident count was generated with l = 12, but the posterior median is
5.515; however, the 95% credible interval (4.182,7.124) does contain 7.
Ni ðti Þ e Poissonðli ti Þ,
(6.51)
li ja, b e gammaða, bÞ, i = 1, 2, ::, k,
and
a e gammað:001, :001Þ,
b e gammað:001, :001Þ:
The Bayesian analysis will be based on observations generated directly from a Poisson
process. WinBUGS Code 6.6 considers five intersections with accident rates of 5.5, 6, 6.5, 7,
and 7.5 accidents per day. I chose these rates because the intersection are all on the same
street and follow one after the other. The intersection with the largest accident rate is an area
that has the most business activity. Also, the accidents were followed for 10 consecutive
days.
TABLE 6.12
Posterior Distribution for the Accident Rate
Parameter Mean SD Error 2 1/2 Median 97 1/2
n1[i]~dpois(t1[i])
n7[i]~dpois(t7[i])
n7.5[i]~dpois(t7.5[i])
n5.5[i]~dpois(t5.5[i])
n6[i]~dpois(t6[i])
n6.5[i]~dpois(t6.5[i])
t5.5[i]<-5.5*t1[i]
t6[i]<-6*t1[i]
t6.5[i]<-6.5*t1[i]
t7[i]<-7*t1[i]
t7.5[i]<-7.5*t1[i]
}}
list(t1=c(1,2,3,4,5,6,7,8,9,10))
In the following are the daily accidents for 10 days at five intersections:
• Intersection 4 with l = 7:
8.0,8.0,16.0,29.0,35.0,
31.0,46.0,59.0,62.0,65.0.
Therefore, at day 1, there are 7 accidents, while at day 10, the total at intersection 5 is 70,
providing the usual estimate of 70/10 = 7 compared to the value of 7.5 used to generate the
observations.
256 Bayesian Inference for Stochastic Processes
The posterior analysis is implemented with WinBUGS Code 6.7 using 35,000 observa-
tions for the simulation with a burn-in of 2,000. Consider intersection 1; then the week 10
observation is 61, and the corresponding mass function is
P½N1 (10) = 61jl5:5 = l10
5:5 =10 ! exp −l5,5 10 , l5:5 > 0: (6.52)
The resulting posterior distribution is gamma (61,10). See the following code, which
specifies the five posterior distributions corresponding to the five intersections:
model;
{
lamda5.5~dgamma(61,10)
lamda6~dgamma(60,10)
lamda6.5~dgamma(71,10)
lamda7~dgamma(65,10)
lamda7.5~dgamma(70,10)
}
TABLE 6.13
Posterior Distribution for Five Intersections for 10 Days
Parameter Mean SD Error 2 1/2 Median 97 1/2
For the Bayesian approach, it is convenient to employ gamma(a, b) and gamma(d, g) prior
distributions which implies then following conditional posterior distributions:
I will use information about the accident rates for intersections 1 and 5, where for
intersection 1 there are n1 = 61 over a t1 = 10 day period, and for the other intersection, there
are n2 = 70 over a t2 = 10 day period. For prior information, I used the vague gamma prior
with a = b = d = g = :01.
The posterior distributions are now determined by Equation 6.55, and WinBUGS
Code 6.8 will implement the Bayesian analysis for estimating l, μ, and lμ.
model;
{
lamda~dgamma(z1,z2)
z1<-131.01
z2<-10.01+mu*10
mu~dgamma(v1,v2)
v1<-70.01
v2<-.01+lamda*10
}
list(lamda =6,mu=2)
258 Bayesian Inference for Stochastic Processes
TABLE 6.14
Posterior Distribution with Covariates
Parameter Mean SD Error 2 1/2 Median 97 1/2
The Bayesian analysis, via WinBUGS Code 6.8, is executed with 45,000 observations for
the simulation and a burn-in of 5,000, and the Bayesian analysis is reported in Table 6.14.
The effect of the covariate (population density) is to increase the daily accident rate 6.103
(using the posterior mean) of the first intersection by an amount of 1.165 (using the posterior
mean), resulting in a daily accident rate of 6.995 (using the posterior mean) for the other
intersection. Are these estimates plausible?
Now another way to include covariates into the Poisson process is with the prior dis-
tribution for the rate l. The model described on page 117 of Insua, Ruggeri, and Wiper2
considers k Poisson processes fNi (t), t > 0g, i = 1, 2, :::, k, where the ith has m covariates
Xi = (Xi1 , Xi2 , ::::, Xim ), then the covariates are included in the model as follows:
Ni (ti )jli ∼ Poisðli ti Þ, i = 1, 2, ::, k,
(6.56)
li ja, b ∼ gammaðaexpðXi b, aÞÞ,
Our goal is to determine the posterior distribution of a and b. For simplicity, let
Eðli Þ = expðb0 + b1 xi Þ, i = 1, 2; (6.58)
that is, there are two intersections, and li is the daily accident rate for intersection i, and xi is
the corresponding population total of the neighborhood (a circle with center at the inter-
section with a radius of a quarter mile) of intersection. I assume that for intersection 1, the
population in the neighborhood is 12,000 persons and 36,000 for the second intersection.
Based on WinBUGS Code 6.9, the student will be asked to verify the Bayesian analysis for
estimating b0 and b1 . I assume for the first exercise that at day 10, there were a total of 61
accidents, while for intersection 2, there were a total of 80 accidents over a 10-day period.
TABLE 6.15
Posterior Distribution for b0 and b1
Parameter Mean SD Error 2 1/2 Median 97 1/2
One would conclude that the slope is 0; that is, that the population density does not affect
the accident rates at the two intersections (Table 6.15).
where the limit is as Dt ! 0, and N(t) has a Poisson distribution. It can be shown that
20 1n 0 13
ðt ðt
P½N(s, t) = n = 4@ lðxÞdxA exp@− lðxÞdxA5=n!: (6.60)
s s
ðt
E½N ðtÞ = mðtÞ = lðxÞdx, t>0 (6.61)
0
Consequently,
ðt
E½N ðs, tÞ = mðs, tÞ = lðxÞdx, s < t, s, t > 0, (6.62)
s
Since the intensity function and the mean value function can vary over time, in general,
the nonhomogeneous Poisson process does not have stationary increments; however,
it does have independent increments, and the superposition (the sum of independent
260 Bayesian Inference for Stochastic Processes
Poisson process has a Poison distribution) and valid coloring theorem (when the events
occur with a set of multinomial probabilities) are valid.
The goal of this section is to develop Bayesian inferences for the parameters of the mean
value function or, equivalently, the intensity function. Of special interest is the intensity
function
ðt ðt
mðtÞ = lðxÞdx = Mbtb−1 = Mtb , t > 0: (6.65)
0 0
Consider observations taken at times t1 < t2 < ::: < tk with corresponding counts N(ti ) =
ni , i = 1, 2, :::, k, then
Now use the mean value function (Equation 6.65); then Equation 6.66 reduces to
P½N ðti Þ = ni = Mni tbn
i
i
exp −Mtb
i =ni !: (6.67)
See Ntzoufras12 for making Bayesian inferences for the parameters of nonstandard dis-
tributions, such as the nonhomogenous Poisson process (Equation 6.67) with the power law
intensity function. Page 275 of Ntzoufras12 shows how one can provide Bayesian inferences
using an approximation to the likelihood function. This approach to approximating the
likelihood function will be demonstrated in the next section.
is a possible alternative; however, as stated on page 205 of Insua, Ruggeri, and Wiper,2 if
the mean value function becomes unbounded as time increases, a possible alternative is
the Musa–Iannino–Okumoto14 mean value function:
MðtÞ = Mlogðt + bÞ: (6.69)
where
Y1
i=n
l1 ðM, b1 jdataÞ = Mn1 bn1 1 Tib1 −1 exp −Myb11 , (6.71)
i=1
Y2
i=n b
y2 b2 −y1 2
l2 ðM, b2 jdataÞ = Mn2 bn2 2 Tib2 −1 exp −My1 , (6.72)
i=n1 +1
and
Y3
i=n b b
y1 2 −y2 3
l3 ðM, b3 jdataÞ = Mn3 bn3 3 Tib3 −1 exp −My1 : (6.73)
i=n1 +n2 +1
As an example, the following data points are generated according to the posterior distri-
butions given by Equation 6.70 through 6.72 using the following code:
R Code 6.7
M<-1
> beta<-.4
> t<-30
> N<-rpois(1,lamda)
> unifs<-runif(N,0,t)
> arrivals<-sort(unifs)
> arrivals
262 Bayesian Inference for Stochastic Processes
there are only two events with arrival times at 20.54698, 22.14968.
R Code 6.8
> t<-20
> M<-1
> beta<-1
> lamda<-M*t**beta
> N<-rpois(1,lamda)
> unifs<-runif(N,0,t)
> arrivals<-sort(unifs)
> arrivals
R Code 6.9
> t<-10
> M<-1
> beta<-2
> lamda<-M*t**beta
> N<-rpois(1,lamda)
> unifs<-runif(N,0,t)
> arrivals<-sort(unifs)
> arrivals
Thus, this is the bathtub sort of intensity function with three stages over the three
intervals (0,10], (11,20], and (21,30], where there are 94 observations in the first, 11 in the
second, and 2 in the third. See Ntzoufras12 for making Bayesian inferences for the param-
eters of nonstandard distributions given by the likelihood function (Equation 6.70). The
Bayesian estimation for M, b1 , b2 , and b3 is based on WinBUGS Code 6.10 with the code that
closely follows Equations 6.70 through 6.73.
I executed the analysis with 45,000 observations for the simulation and 5,000 for the
burn-in. See Table 6.16 for the posterior analysis.
model;
{
am<-1
bm<-1
n<-108
#see (6.70)
M~dgamma(c1,c2)
c1<-n+am
c2<- bm+pow(10,beta1)+
pow(20,beta2)-pow(10,beta2)+pow(30,beta3)-pow(20,beta3)
# the prior distributions for the regression coefficients
beta1~dgamma(.5,1)
beta2~dgamma(1,1)
beta3~dgamma(2,1)
a1<-1
b1<-1
n1<-94
# see (6.71)
# this is the log likelihood function M and beta1
for ( i in 1:95){
l1[i]<-(a1+n1-1)*log(beta1)-b1*beta1-
M*pow(10,beta1)+beta1*log(T[i])}
n2<-11
a2<-1
264 Bayesian Inference for Stochastic Processes
b2<-1
# see (6.72)
# this is the log likelihood function for M and beta2
for( i in 96:107){
l2[i]<-(a2+n2-1)*log(beta2)-b2*beta2-M*(pow(20,beta2)-
pow(10,beta2))+beta2*log(T[i])}
a3<-1
b3<-1
# see (6.73)
# this is the likelihood function for M and beta3
for ( i in 108:110){
l3[i]<-(a3+n-n1-n2-1)*log(beta3)-b3*beta3-M*(pow(30,beta3)-
pow(20,beta3))+beta3*log(T[i])}
}
list(T= c(0.01929614, 0.16683374, 0.30868937, 0.45783466,
0.45783841, 0.60971629, 0.69073963, 0.72312287, 0.73048354,
0.78726970, 0.87282923, 1.11631418, 1.19893630, 1.24930384,
1.29853977, 1.86708471, 1.99640772, 2.09816973, 2.31948325,
2.31964980, 2.31978450, 2.32668238, 2.38249653, 2.39276180,
2.40731530, 2.51792069, 2.69428169, 2.86724672, 2.93153171,
2.95547242, 3.09350756, 3.11019411, 3.41164040,3.48050033,
3.51716059, 3.52967131, 3.66419103, 3.70468339, 3.73201358,
3.76651419, 3.77171997, 3.80131188, 3.83412594, 4.27709175,
4.32951888, 4.33360442, 4.45838177, 4.46452007, 4.67891457,
4.72167716, 4.81387984, 5.00014701, 5.24055764,5.30405366,
5.45888764, 5.49390880, 5.52179333, 5.66381047, 6.16508507,
6.24032858, 6.2442796, 6.29753330, 6.30779498, 6.31612410,
6.41120937, 6.41448096, 6.43383395, 6.77219317, 6.84154629,
6.90076633, 6.92867827, 6.93095933, 7.10138919, 7.26750958,
7.27311966, 7.33515741, 7.50370963, 7.52847685, 7.67226142,
7.6930181, 7.73796714, 7.78828417, 8.08008341, 8.42653468,
8.42955573,8.43619858, 8.50564013, 8.70426517, 8.74478266,
8.80415160, 9.0581363, 9.27984186, 9.28731328, 9.35034508,
9.51775680, 9.74506902, 9.96410355, 9.98975439, 11.127021,
11.570835, 12.520865, 12.714158, 13.288865, 15.761193, 16.741561,
16.948549, 17.125616, 18.301101, 18.812169, 20.54698, 22.14968))
list(beta1=.2, beta2=1,beta3=3,M=1)
TABLE 6.16
Posterior Distribution for the Bathtub Mean Value Function
Parameter Mean SD Error 2 1/2 Median 97 1/2
Recall that the true values for b1 , b2 , and b3 are .5, 1, and 2, respectively, and that of M is 1.
The posterior means are very close to these beta values, but the posterior mean of M is 3.309
and the posterior median is .231. Also, note that the posterior distributions for b1 , b2 , and b3
are skewed to the right. As an exercise, the student will be asked to study the sensitivity of
the posterior distributions to their priors. The following example is similar to that earlier for
the washtub-shaped mean value function, but instead, the mean value function is the
reverse to that of the washtub shape.
This section on nonhomogeneous Poisson processes is concluded with an example pre-
sented on page 253 of Dobrow1 in the form of a problem. Students arrive at a cafeteria for
lunch according to a Poisson process, where the rate of arrival varies in a linear way from
100 to 200 students over the time interval from 11:00 a.m. to noon, but the rate stays con-
stant over the next 2 hours (from noon to 2:00 p.m.) and then decreases linearly to 100 from
2:00 to 3:00 p.m. Find the probability that there are at least 400 people in the cafeteria
between 11:30 a.m. and 1:30 p.m. The intensity function is given by
It is easy to see that the answer to the question is as follows: The mean value function is
ð1 ð
2:5
Thus,
X
k=399
P½N ð2:5Þ − N ð:5Þ ≥ 400 = 1 − ð387:5Þk expð−387:5Þ=k ! = :269:
k=0
Our approach will take more of a statistical approach by generating observations from the
nonhomogeneous Poisson process with intensity function (Equation 6.77), then based on
that information, estimate the expected value of the process and, consequently, estimate the
required probability.
R Code 6.10 for generating the interarrival times for the process with intensity function
(Equation 6.77) over the range 0 < t < 1.
R Code 6.10
t<-1
> lamda<-200*t
> N<-rpois(1,lamda)
> unifs<-runif(N,0,t)
> arrivals<-sort(unifs)
> arrivals
266 Bayesian Inference for Stochastic Processes
There are 129 arrivals corresponding to the intensity function l(t) = 100 + 100t, 0 < t < 1:
When the intensity function is l(t) = 200t, there are 375 arrivals:
When the intensity function is m(t) = 500t − 50t2 , there are 292 events:
for( i in 1:129){
n1[i]~dexp(delta1[i])
lamda1[i]<-beta11*i+beta12*i*i
delta1[i]<-1/lamda1[i]}
beta11~dnorm(100,1)
beta12~dnorm(50,1)
270 Bayesian Inference for Stochastic Processes
for ( i in 1:375){
n2[i]~dexp(delta2[i])
lamda2[i]<-beta2*i
delta2[i]<-1/lamda2[i]}
beta2~dnorm(200,1)
for( i in 1:292){
n3[i]~dexp(delta3[i])
lamda3[i]<-abs(beta31*i-beta32*i*i)
delta3[i]<-1/lamda3[i]}
beta31~dnorm(500,1)
beta32~dnorm(-50,1)
E<-beta11/2+3*beta12/8+1.5*beta2
}
TABLE 6.17
Posterior Distribution for Regression Parameters Nonhomogeneous Process
Parameter Mean SD Error 2 1/2 Median 97 1/2
list(beta11=100,beta12=50, beta2=200,beta31=500,beta32=-50)
Recall that the value of b11 used to generate the arrival times for the first stage is 100 and
that for b12 is 50 and that the corresponding posterior means are very close to these values. It
can also be confirmed that this is true for the remaining beta parameters. Also, recall the
expectation
ð1 ð
2:5
However, the posterior mean given by Table 6.17 is 364.9! Why the discrepancy?
state, and upon departing the state, the system changes with regard to the probabilities that
depend solely on the leaving state. The process is completely specified by the initial state,
the transition probabilities from the current state to the future state and the parameter of the
exponential distribution of the current time the process is in the current state. All phases of
inference will be explored, which includes estimation, testing hypotheses, and forecasting
of future observations (states or interarrival times).
Let fX(t), t > 0g be a continuous-time stochastic process with state space S = f1, 2, :::, kg
such that when the process enters state i, it remains in state i according to the exponential
distribution with parameter ni (with mean 1=ni ). At the end of this period (being in state i),
the process transitions to another state say j ≠ i with transition probability pij ,
j=k
X
where pij = 1. It should be emphasized that for some j, it is possible that pij is zero. If
j=1
one ignores time, the process occupies the states, the transition probability matrix of the
various states is P = (pij ) corresponds to what is referred to as the embedded chain. The
birth and death process discussed in the following is an example of a continuous-time
Markov chain.
In such a process, the state space is S = f0, 1, :::, kg and represents the size of the popu-
lation. Suppose the process is in state i, then the population can increase by a single birth
with rate li and decrease by one unit with a single death occurring at rate μi , and the
transition matrix is defined as follows:
pi,i+1 = li =ðli + μi Þ
and (6.79)
pi,i−1 = μi =ðli + μi Þ
Also, note that if the population is 0, the size of the population remains zero, and if the
population is size k, it can only decrease by one death and, of course, cannot increase by
one birth.
Furthermore, in general, for a continuous time chains with state space S = f1, 2, :::, kg,
when the process is in state i, it remains in state i according to an exponential distribution
with parameter ni > 0. The jumping intensity from state i to state j is defined by
is described. Note that this follows because the process is homogeneous; that is, only the
length of the interval is important in determining the transition from i to j.
Inferences for Markov Chains in Continuous Time 275
where
P0 ðtÞ = ðd=dtÞPij ðtÞ :
Or in matrix form as
with
I = Pð0Þ,
where I is the identity matrix and P(t) is the matrix of transition probability functions. It is
easy to show that the solution to the Kolmogorov system of equations (Equation 6.83) is the
exponential form
which according to Moler and Van Loan15 can be solved for the given t using matrix
exponentiation.
We now come to the central focus of this section, namely, Bayesian inference of continuous-
time Markov chains. To this end, it is assumed that the transition matrix P and the vector n
of the transition rates are unknown and that P is not a function of n. Assume that the initial
state is x(0), which is followed by n transitions times ti and corresponding observations
x(i), i = 1, 2, :::, n; then the likelihood function is
Y
i=n
lðP, n jdataÞ = ni−1 exp ni−1 ðti − ti−1 Þpxði−1Þ,xðiÞ
i=1
(6.85)
Y
i=n Y
i=n
n
= nini expð−ni ti Þ pijij ,
i=1 i=1
where nij is the number of transitions from state i to j, ti is the time occupying state i (with an
exponential distribution with parameter ni ), pij is the probability of the transition from state
j=k
X
i to state j, and ni : = nij is the number of transitions out of state i. Referring to the
j=1
likelihood function (Equation 6.85), it is understood that state j is x(j), j = 1, 2, :::, k. It is
obvious from Equation 6.85 that the likelihood function can be written as
Therefore, inferences can be made separately for P and n, by first generating transitions nij
from i to j, then generating exponential holding times after the transition to state i. Recall
Chapter 4 where R Code 4.1 is used to generate transitions according to the transition
probability matrix P and to R Code 6.10 of this chapter to generate exponential interarrival
times. Thus, starting in state i, one can generate transitions to state j for some of the j = 1, 2, .., k.
If one knows the transition probabilities pij , j = 1, 2, :::, k, one could employ the multinomial
distribution to generate the transitions, as was done in Section 4.3.
Suppose prior information for the ni , i = 1, 2, ::, k is gamma (ai , bi ), then the posterior
distribution of ni is gamma (ni + ai , ti + bi ) with posterior mean (ni + ai )=(ti + bi ). Recall that
the posterior mean of the transition time Ti is
E ni−1 dataÞ = ðti + bi Þ=ðni + ai − 1Þ:
Now for the prior distribution of the transition probabilities pij , because of practical
reasons, it is important to remember that some of the pij are zero, but nevertheless, that one
may employ a Dirichlet distribution for the row of P; thus, the posterior analysis is dem-
onstrated with an example.
Suppose that the probability transition matrix of the embedded chain is
0 1
p11 , 0, p13 , p14 , 0
B C
B 0, p22 , 0, p24 , 0 C
B C
B C
P=B B 0, 0, p , p ,
33 34 35 Cp C (6.87)
B C
B p41 ,p42 , 0, p44 , p45 C
@ A
0, p52 , p53 , 0, p55
with permanence rates ni , i = 1, 2, :::, 5, the goal is to provide Bayesian inference for the
unknown parameters ni , and the nonzero pij of (Equation 6.87). Inferences will be based on
the transition counts given by the matrix
0 1
n11 , 0, n13 , n14 , 0
B C
B 0, n22 , 0, n24 , 0 C
B C
B C
B
c = B 0, 0, n33 , n34 , n35 C C (6.88)
B C
B n41 , n42 , 0, n44 , n45 C
@ A
0, n52 , n53 , 0, n55
TABLE 6.18
Prior Dirichlet Distribution for Rows of P
Row Parameters
1 (1, 0, 1, 1, 0)
2 (0, 1, 0, 1, 0)
3 (0, 0, 1, 1, 1)
4 (1, 1, 0, 1, 1)
5 (0, 1, 1, 0, 1)
t5 = 5:65137. Using the multinomial generator in R, the following transition counts repre-
sented by the matrix
0 1
1, 0, 17, 2, 0
B C
B 0, 10, 0, 20, 0 C
B C
B C
B
C = B 0, 0, 7, 4, 4 C C (6.89)
B C
B 10, 7, 0, 7, 6 C
@ A
0, 6, 8, 0, 16
are computed.
Thus, the number of transitions out of the various states are n1 = 19, n2 = 20, n3 = 8, n4 =
23, and n5 = 14. This completes the sample information; therefore, in order to execute the
posterior analysis, the prior distributions need to be assigned to the unknown parameters P
and n.
The rows of P are assigned prior Dirichlet distributions as shown in Table 6.18:
In addition, the improper prior
gðni Þ ∝ 1=ni , i = 1, 2, 3, 4, 5
is assigned to the parameter of the exponential distribution of the occupation times of the
various states.
The Bayesian analysis is executed with WinBUGS Code 6.12 using 45,000 observations
for the simulation and 5,000 for the burn-in.
nu4~dgamma(23,3.2565)
nu5~dgamma(14,5.65132)
p11~dbeta(2,20)
p13~dbeta(17,5)
p14~dbeta(3,19)
p22~dbeta(11,21)
p24~dbeta(21,11)
p33~dbeta(8,10)
p34~dbeta(5,13)
p35~dbeta(5,13)
p41~dbeta(11,23)
p42~dbeta(8,26)
p44~dbeta(8,26)
p45~dbeta(7,25)
p52~dbeta(7,26)
p53~dbeta(9,24)
p55~dbeta(17,16)
mu1<-1/nu1
mu2<-1/nu2
mu3<-1/nu3
mu4<-1/nu4
mu5<-1/nu5
}
Table 6.19 reports the Bayesian analysis for the example with five states with five intensity
parameters and the probabilities of the transition matrix.
Most of the posterior distributions are symmetric about the posterior mean, and it
appears that the MCMC simulation errors are sufficiently small so that one had confidence
in these estimates. The reader should display the posterior densities of the parameters of
Table 6.19 to show the symmetry of the posterior distributions. This chapter will develop in
much greater detail the fundamental ideas of continuous-time Markov chains, which are
illustrated with applications in business, biology, and medicine.
Inferences for Markov Chains in Continuous Time 279
TABLE 6.19
Posterior Distribution for Continuous Markov Chain
Parameter Mean SD Error 2 1/2 Median 97 1/2
6.9 Summary
This chapter on continuous-time Markov chains begins with three definitions of the Poisson
process where the emphasis is on Bayesian inferences for one parameter l. R Code 6.1
generates arrival times of a Poisson process, and these observations are used in the example
of Bayesian inferences about l. All three phases of inferences are displayed including
estimation, testing hypotheses, and prediction of future observations. Next to be considered
is the concept of the superposition of Poisson processes, and the ideas are explained in terms
of an example involving major and minor earthquakes in Italy. Included with Bayesian
inference is testing the hypothesis that the rate of occurrence of major earthquakes is the
same as that for minor earthquakes.
Next to be presented is a generalization to nonhomogeneous Poisson processes, where the
rate of occurrence of events varies over time. An example involving the Bayesian estimation
of the regression parameters that may affect the rate of occurrence of events is explained in
detail. A test of the hypothesis that the regression parameters have no effect is also presented.
This chapter ends with a Bayesian approach to the general continuous-time Markov chain,
where the parameters of interest are the average occupation of a given state and the transition
probabilities of moving from one state to the others.
280 Bayesian Inference for Stochastic Processes
The reader should be aware of the basic references for continuous-time Markov chains,
both from a classical and a Bayesian perspective. From a non-Bayesian view, see Guttorp16
and Ross,17 while for a Bayesian flavor, refer to Geweke, Marshal, and Zarkin,18 and lastly,
for those interested in reliability, see Cano, Moguerza, and Rios-Insua.19 In addition, pages
103–105 of Insua, Ruggeri, and Wiper2 list more relevant references.
6.10 Exercises
1. Define a Poisson process with parameter l.
2. Refer to Section 6.2 and show that the three definitions a, b, and c of a Poisson
process are equivalent.
3. Show that the interarrival times of a Poisson process with parameter l are i.i.d.
exponential with mean 1=l.
4. Use R Code 6.1 with t<-40 and lamda<-1/2 to generate the interarrival times of a
Poisson process with parameter l = 1/2. How many interarrival times are generated?
5. Show that the distribution of the waiting time to the nth event is gamma with
X
i=n X
i=n
parameters n and ti , where ti is the waiting time to the nth event.
i=1 i=1
6. Assume one has observed n events of a Poisson process with parameter l and that
one employs the improper prior density g(l) ∝ 1=l, l > 0 for l. What is the
posterior distribution of l?
7. Execute WinBUGS Code 6.1 with 45,000 observations for the simulation and a burn-
in of 5,000 and verify the posterior analysis reported in Table 6.1. What is the 95%
credible interval for M? Is the posterior distribution of M symmetric about its mean?
8. Derive the predictive distribution of the waiting time S15 given by Equation 6.21.
9. Refer to Section 6.4 and explain the idea behind the thinning Poisson processes.
10. Using R Code 6.2, do the following:
a. Generate the birth times that follow aPoisson process with l = 2 over an 8-hour
period.
b. Generate the birth arrival times of males using R Code 6.3 with l = 1:03 over
an 8-hour period.
c. Show that the posterior distribution of l of the overall birth rate is gamma
with parameters 18 and S18 = 7:524868.
d. Show that the posterior distribution of g = pl is gamma (11, 6.779414).
e. Verify Table 6.4, the Bayesian analysis for p, l, and g = pl.
Inferences for Markov Chains in Continuous Time 281
11. a. Verify Table 6.6, the posterior analysis of the three parameters p, l, and μ for
the three Italian quake zones. The Bayesian analysis is based on data from
Table 6.5. Note that l is the overall rate of earthquakes, while lp and l(1 − p)
are the rates for major and minor earthquakes, where p is the probability of a
major quake.
b. Execute WinBUGS Code 6.4 with 45,000 observations and 5,000 for the
burn-in, and then verify the posterior analysis reported in Table 6.7, the
Bayesian analysis for the three earthquake zones.
12. Derive the predictive density (Equation 6.29) of Y(n + 1), the future magnitude of
a major earthquake in zone 1.
13. Refer to Section 6.5 for the spatial Poisson process.
a. Define a spatial Poisson process.
b. Use R Code 6.4 with l = 100 with a square area of 1 (the unit square), using
100,000 trials for generating observations for a spatial process. The goal is to
estimate the number of points that fall with a circle of radius r = .2 and center
(.7,.7). For your answer, refer to Table 6.10.
c. By referring to R Code 6.4, explain how the plot of Figure 6.2 is conducted.
d. Execute WinBUGS Code 6.5 with 45,000 observations for the simulation and
burn-in 5,000 and verify the posterior analysis reported in Table 6.11.
14. a. Refer to Section 6.6 on concomitant Poisson processes and define the
following and how they play a role in such chains: (1) independence,
(2) complete similarity, and (3) partial similarity.
b. Refer to Section 6.6.2 on the complete similarity between several Poisson
processes and use WinBUGS Code 6.6 with t = 10 and l = 7 to generate the
times of accidents over a 10-day period. Refer to Table 6.12 and see if your
results are similar to those in this table.
c. With the data generated in item b, assuming an improper prior distribution
for l, show that the posterior distribution of the accident rate l is gamma
(56, 9.9).
15. Partial similarity is defined by Equation 6.51.
a. Use WinBUGS Code 6.6 with 45,000 observations for the simulation and
5,000 for the burn-in to generate the accident times at five intersections over
a 10-day period with daily rates l1 = 5:5, l2 = 6:0, l3 = 6:6, l4 = 7:0, l5 =
7:5 for the five intersections. Your results should be similar to those reported
in Table 6.13.
b. Execute WinBUGS Code 6.7 with 35,000 observations for the simulation
and a burn-in of 5,000. The posterior distribution for the five accident rates
li , i = 1, 2, 3, 4, 5 is reported in Table 6.13. Your results should be similar to
those.
c. Are these five posterior distributions symmetric about their posterior
means?
d. Do the 95% credible intervals include the corresponding true li , i = 1, 2, 3, 4, 5
values used to generate the accident rates for the five intersections?
282 Bayesian Inference for Stochastic Processes
16. a. Execute WinBUGS Code 6.8 with 55,000 observations for the simulation and
a burn-in of 5,000. Verify the posterior analysis reported in Table 6.14.
b. Are the posterior means for l, μ, and lμ reasonable estimates? Explain why.
c. What do the parameters l, μ, and lμ represent?
d. What prior distribution is used for l and μ?
17. There are several ways to incorporate covariates into the Poisson process.
a. Execute WinBUGS Code 6.9 with 35,000 observations for the simulation and
a burn-in of 5,000. Use your results to verify Table 6.14, the Bayesian
analysis for two regression coefficients.
b. Based on the results of Table 6.15, is b1 = 0? Explain your answer.
18. a. Execute R Code 6.8 using M = 1 and beta = 1; generate the arrival times
listed in Equation 6.75. The mean value function for this nonhomogeneous
Poisson process is m(t) = 6, 0 < t < 20.
b. Execute R Code 6.9 with the mean value function m(t) = t2 , 0 < t < 10; that
is, use t<1= and M<-1, and beta<-1 as inputs for the code. Your results
should be similar to the 94 arrival times reported below Equation 6.76.
19. a. Execute WinBUGS Code 6.10 with 40,000 observations for the simulation
and a burn-in of 3,000 and verify Table 6.16.
b. Is the estimate of M reasonable? Explain your answer.
c. Are the estimates of b1 , b2 , and b3 reasonable? Explain your answer.
d. What prior distribution is used for b1 , b2 , b3 , and M?
e. Why are the posterior means of these four parameters so close to the true
values?
20. Refer to Section 6.8.
a. Define a continuous-time Markov chain. What is the Markov property of
such a process?
b. What is the distribution of the interarrival times?
c. What is the parameter of the interarrival time when the process leaves state i
but has yet to enter a different state j?
d. Describe the transition probability matrix of a continuous-time Markov chain.
e. What are the jumping intensities of such a process?
21. a. Explain the solution Pij (t) to the Kolmogorov system of differential equa-
tions (Equation 6.82).
b. Show that the solution is given by the exponential form (Equation 6.84).
22. Derive the likelihood function (Equation 6.85) for the arrival time parameters ni ,
i = 1, 2, 3, 4, 5, and the transition probabilities Pij , i, j = 1, 2, 3, 4, 5.
23. a. What is the prior distribution of the ni , i = 1, 2, 3, 4, 5?
b. Show that the posterior distribution of ni , i = 1, 2, 3, 4, 5 is gamma(ni + ai , ti +
bi ), i = 1, 2, 3, 4, 5.
c. Show that the posterior distribution of the rows of the transition probabil-
ities is Dirichlet.
d. What is the prior distribution of the rows of the transition probabilities?
Inferences for Markov Chains in Continuous Time 283
24. a. Execute WinBUGS Code 6.12 with 41,000 observations for the simulation
and a burn-in of 2,500.
b. Verify the Bayesian analysis reported in Table 6.19.
c. What is the posterior mean of the interarrival time when the process leaves
state i?
References
1. Dobrow, R. P. 2016. Introduction to Stochastic Processes with R. New York: John Wiley & Sons.
2. Insua, D. R., Ruggeri, F., and Wiper, M. P. 2012. Bayesian Analysis of Stochastic Process Models. New
York: John Wiley & Sons.
3. Albert, J. 1985. Simultaneous estimation of Poisson means under exchangeable and independent
models, Journal of Statistical Computation and Simulation 23:1–14.
4. Lee, P. M. 1989. Bayesian Statistics: An Introduction, Second Edition. New York: John Wiley & Sons.
5. Rotondi, R., and Varini, E. 2003. Bayesian analysis of a marked point process: Application in
seismic hazard assessment, Statistical Methods & Application 12:79–92.
6. Vere-Jones, D. 1970. Stochastic models for earthquake occurrence, Geophysical Journal of the Royal
Astronomical Society 42:811–826.
7. Vere-Jones, D., and Ozaki, T. 1982. Some examples of statistical estimation applied to earthquake
data, Annals of the Institute of Statistical Mathematics 34:189–207.
8. Ogata, Y. 1988. Statistical methods for earthquake occurrences and residual analysis for point
processes, Journal of the American Statistical Association 83:9–27.
9. Ruggeri, F. 1993. Bayesian comparison of Italian earthquakes, Quaderno IAMI, 93.8, Milano: CNR-
IAMI.
10. Bivand, R. S., Pebesma, E. G., and Gomez-Rubio, V. 2013. Applied Spatial Data Analysis with R. New
York: Springer.
11. Blangiardo, M., and Carmeletti, M. 2015. Spatial and Spatio-Temperal Bayesian Models with R. New
York: John Wiley & Sons.
12. Ntzoufras, I. 2009. Bayesian Modeling Using WinBUGS. New York: John Wiley & Sons.
13. Cox, D. R., and Lewis, I. A. W. 1966. Statistical Analysis of Series of Events. London: Methuen.
14. Musa, J. D., Iannio, A., and Okumoto, K. 1987. Software Reliability Measurement, Prediction,
Application. New York: Mc Graw-Hill.
15. Moler, C., and Van Loan, C. 2003. Nineteen dubious ways to compute the exponential of a matrix,
twenty five years later, Siam Review 45:3–49.
16. Guttorp, P. 1995. Stochastic Modeling of Scientific Data. Boca Raton, FL: Chapman and Hall.
17. Ross, S. M. 2009. Introduction to Probability Models, 10th Edition, New York: Academic Press.
18. Geweke, J., Marshal, R., and Zarkin, G. 1986. Mobility indices in continuous time Markov chains,
Econometrica 54:1407–1423.
19. Cano, J., Moguerza, J., and Insua, D. R. 2010. Bayesian reliability, availability, and maintainability
analysis for hardware systems described through continuous time Markov chains, Technometrics
52:324–334.
[Link]
7
Bayesian Inference: Examples of Continuous-Time
Markov Chains
7.1 Introduction
In Chapter 6, details of the Poisson process, an important case of continuous-time Markov
chains (CTMCs), were presented. In this chapter, Bayesian inferences for general CTMC are
presented. First to be considered are the important concepts involved in the study of such
processes. For example, the ideas of transition rates, holding times, embedded chain, and
transition probabilities are defined and explained. Such concepts are illustrated by using R
to compute the transition function and to generate observation from the CTMC. This is
followed by a presentation of Bayesian inferences of estimation and testing hypotheses
about the unknown parameters of the process. Also developed is the Bayesian predictive
distribution for future observations of the CTMC.
As with discrete time chains, the understanding of stationary distributions, absorbing
states, mean time to absorption, and time reversibility is an essential part when discussing
CTMCs.
The chapter is concluded with many examples, including deoxyribonucleic acid (DNA)
evolution, birth and death processes, and queuing.
285
286 Bayesian Inference for Stochastic Processes
for all states i, j, and x(u), 0 ≤ u < s. Of course, it is understood that the state space is
countable.
Also, a CTMC is time homogenous, that is to say,
Thus, the probabilistic properties of a CTMC over the interval [s, t + s] are the same as that
over the interval [0, t]. Or to express it in another way, when the chain visits state i, its
forward behavior from that time toward the future is the same as if the process started in i at
time t = 0. Note that the function Pij (t) is called the transition function of the process.
Recall that for a Poisson process, the interarrival times are identically exponentially
distributed; however, for the CTMC, there is a difference as follows. Let Ti be the holding
time of the process that is the time the process occupies state i before switching to another
state, and then it can be shown that Ti has an exponential distribution.
To show that Ti is memoryless, consider
and the last statement of Equation 7.3 shows that the process is memoryless. Recall that the
only continuous distribution that is memoryless is the exponential. The evolution of the
process can be described as follows: Starting in state i, the process remains in this state for an
exponentially distributed time with parameter qi (average time in this state is 1=qi ); then it
hits a new state j with probability pij and remains in state j for a time which has an expo-
nential distribution with mean 1=qj ; then it hits a new state k, k ≠ j, with probability pjk ; etc.
I am assuming that the process does not hit an absorbing state and that the process is not
explosive. See pages 268 and 269 of Dobrow1 for additional information. There is a con-
nection between the transition probabilities pij and the exponential parameters qi of the
holding times, and this connection is the transition rate of the process.
parameter qij . When state i is first occupied, the alarms are all started at the same time, and
the first alarm that is activated determines the next state to be occupied. If the alarm (i,j) is
first activated and the process moves to state j, a new set of alarms are activated with
exponential transition rates qj1 , qj2 , …. Thus, to repeat, the first alarm that is activated
determines the next state to be occupied, etc. The qij are called transition rates, and from
them, the transition probabilities and holding time parameters can be determined.
Suppose the process starts at i, then the alarms are initiated, and the first one that is
activated determines the next transition; therefore, the time of the first alarm is the
minimum of independent exponential random variable X with parameters qi1 , qi2 , :::, which is
an exponential random variable with parameter qik . Thus, the process remains in state i
k X
for a holding time, which has an exponential distribution with parameter qik = qi . From
k
i, the chain moves to state j if the alarm (i,j) is activated first, which occurs with probability
which is the transition probability of moving from state i to state j of the embedded chain.
One sees from Equation 7.4 that the transition probabilities of the chain are completely
determined by the transition rates qij .
As a simple example, consider a four-state chain with the transition rates of the chain
given by
ðq1 , q2 , q3 , q4 Þ = ðq12 + q13 + q14 , q21 + q23 + q24 , q31 + q32 + q34 , q41 + q42 + q43 Þ: (7.5)
The transition rates qij are quite important when studying CTMC. Assume that the
CTMC has a differentiable transition function P(t), where pij (0) = 1 if i = j; otherwise, its
value is 0.
Note that if X(t) = i, then the instantaneous transition rate of hitting j ≠ i is given by
= ðd=dtÞpij ð0Þ
= p0 ij ð0Þ:
288 Bayesian Inference for Stochastic Processes
Consider the matrix Q = P0 (0); then the off-diagonal elements of Q are the transition rates
qij ; that is, qij = Qij , i ≠ j, and the diagonal entries are − qi ; thus, each row of Q has sum 0.
As an example, consider the four-state chain in Equation 7.6, where q12 = q13 = q14 = 1, q21 =
q23 = q24 = 2, q31 = q32 = q34 = 3, and q41 = q42 = q43 = 4; thus, q1 = 3, q2 = 6, q3 = 9, and q4 = 12.
For this four-state chain, the process remains in state 1 for an average of 1/3 hours, in state 2
for 1/6 hours, and in state 3 for 1/9 hours, and in state 4 for an average of 1/12 hours.
Consequently, the infinitesimal generator matrix is
0 1
−3, 1, 1, 1
B C
B 2, −6, 2, 2 C
B C
Q=B C (7.8)
B 3, 3, −9, 3 C
@ A
4, 4, 4, −12
X
and πi Qij = 0, ∀ j. Since the transition rates determine the transition probabilities of the
i
embedded chain, which is the matrix
0 1
0, 1=3, 1=3, 1=3
B C
B 1=3, 0, 1=3, 1=3 C
B C
P=B C: (7.9)
B 1=3, 1=3, 0, 1=3 C
@ A
1=3, 1=3, 1=3, 0
This is a very special transition matrix, because I chose the transition rates in such a way
that each transition has the same chance of occurring, namely, 1/3.
7.2.3 Kolmogorov Forward and Backward Equations and the Matrix Exponential
We now see the role the equation pij = qij =qi plays in determining the transition probability
matrix P(t), which is a solution to the forward Kolmogorov equation
P0 ðtÞ = PðtÞQ,
where Q is the infinitesimal matrix and P0 (t) is the derivative matrix with respect to t of the
transition probability matrix.
This is also expressed as
X X
P0 ij ðtÞ = pik ðtÞqkj = −pij ðtÞqj + pik ðtÞqkj : (7.10)
k k≠j
For a proof of Equation 7.10, see page 276 of Dobrow.1 It is obvious that the solution P(t)
to Equation 7.10 is given by the matrix equation
where P(0) = I.
Bayesian Inference 289
X
n=∞
P0 ðtÞ = ðd=dtÞetQ = ð1=n !ÞðtQÞn = I + tQ + t2 Q2 =2 + t3 Q3 =3 ! +::: :
n=0
The next section will use R to express solution P(t) in matrix form of Equation 7.11.
R Code 7.1
>[Link]("expm")
>library(expm)
# Q is the infinitesimal generator matrix
> Q<-matrix(c(-3,1,1,1,
+ 2,-6,2,2,
+ 3,3,-9,3,
+ 4,4,4,-12),ncol=4,nrow=4,byrow=TRUE)
# the following is the command that executes the matrix exponential
> P<- function (t){expm(t*Q)}
# P(2) is the probability transition matrix at 2
> P(2)
[,1] [,2] [,3] [,4]
[1,] 0.4800078 0.2399952 0.1599982 0.1199989
[2,] 0.4799903 0.2400060 0.1600023 0.1200014
[3,] 0.4799945 0.2400034 0.1600013 0.1200008
[4,] 0.4799954 0.2400028 0.1600011 0.1200007
# P(0) is the probability transition matrix at t=0.
# this serves as a check since P(0)=I, the identity matrix
> P(0)
[,1] [,2] [,3] [,4]
[1,] 1 0 0 0
[2,] 0 1 0 0
[3,] 0 0 1 0
[4,] 0 0 0 1
> P(4)
[,1] [,2] [,3] [,4]
[1,] 0.48 0.24 0.16 0.12
[2,] 0.48 0.24 0.16 0.12
[3,] 0.48 0.24 0.16 0.12
[4,] 0.48 0.24 0.16 0.12
> P(1.2)
290 Bayesian Inference for Stochastic Processes
For example, when the time is t = 1.2 hours, the transition probability matrix is
P(1.2); thus, the probability of changing states from state 1 to 2 over a 1.2-hour interval is
.2395, etc.
where πj is the jth component of the vector π. The limiting distribution does not have to
exist, but if it does, it is the stationary distribution of the chain. Of course, the stationary
Bayesian Inference 291
π = πPðtÞ, t ≥ 0, (7.13)
which is equivalent to
X
πj = πi Pij (t), t≥0 (7.14)
i
There is a relation between the stationary distribution and the infinitesimal generator
matrix Q, given by
πQ = 0, (7.18)
or, in scalar terms,
X
πi Qij = 0, ∀ j:
i
292 Bayesian Inference for Stochastic Processes
The following example is from pages 286 and 287 of Dobrow1 with the infinitesimal
generator matrix
0 1
−2:0, 1:0, 1:0
B C
Q=B C
@ 1=2, −1, 1=2 A: (7.19)
0, 1=3, −1=3
This corresponds to a three-state chain with states eat, play, and sleep.
A newborn baby is in one of three states: eat, play, and sleep. The baby eats on the average
for 30 minutes, plays for an average of 1 hour, and, on the average, sleeps for approximately
3 hours. After eating, there is a 50–50 chance that he will sleep or play, and after playing,
there is a 50–50 chance that he will sleep or eat. Lastly, after sleeping, he will always eat. The
corresponding transition matrix of the embedded chain is
0 1
0, 1=2, 1=2
B C
P=B
@ 1=2, 0, 1=2 A:
C (7.20)
0:0, 1:0, 0, 0
Then, using the fact that qij = qi pij , the generator matrix is given by Equation 7.19.
Instead of using Equation 7.18, let us find the stationary distribution of this process with R
Code 7.2. The corresponding code computes the corresponding P matrix and then approx-
imates the limiting distribution P(100):
R Code 7.2
> Q<-matrix(c(-2,1,1,
+ 1/2,-1,1/2,
+ 0,1/3,-1/3),nrow=3,byrow=TRUE)
> P<-function(t){expm(t*Q)
+}
> P(100)
[,1] [,2] [,3]
[1,] 0.07142857 0.2857143 0.6428571
[2,] 0.07142857 0.2857143 0.6428571
[3,] 0.07142857 0.2857143 0.6428571
other k − 1 states are transient. If the chain starts in a transient state, there is a positive
probability that the chain will be absorbed.
Suppose the generator matrix is partitioned as
!
0, 0∗
Q= , (7.21)
∗, V
where V is the k − 1 order submatrix of transient states; then if the chain has initial state i, the
mean time to absorption is
X
ai = Fij , (7.22)
j
Then according to Bartolomeo, Trerotoli, and Serio,4 the matrix is the generator matrix
corresponding to the progression of liver disease among three states: state 1 corresponds to
cirrhosis; state 2, liver cancer; and state 3, death. Of course, state 3 is an absorbing state;
thus, it is of interest to determine the average time to death, beginning from cirrhosis and
from liver cancer.
The fundamental matrix is
!−1 !
−ðq12 + q13 Þ, q12 1=ðq12 + q13 Þ, q12 =q23 ðq12 + q13 Þ
F= = , (7.25)
0:000000, −q23 0:00000000000000000, 1=q23
and the mean time to absorption for a person who has cirrhosis is
In a similar way, for those with liver cancer, the mean time to death is
a2 = 1=q23: (7.27)
For the statistician, one would have to have sample information about the transition rates
q12 , q13 , and q13 . Bartolomeo, Trerotoli, and Serio’s study4 estimated these rates as follows:
~q12 = .0151, ~q13 = .0071, and ~q23 = .0284, and these can be substituted into Equations 7.26 and
7.27 for estimates of the mean time to death for those with cirrhosis of the liver and liver
cancer, respectively.
294 Bayesian Inference for Stochastic Processes
Using these estimates, R Code 7.3 computes an estimate, using the simulation of the
average time to death for a patient diagnosed initially with cirrhosis of the liver, where the
time unit is months:
R Code 7.3
> trials<-10000
> simlist<-numeric(trials)
> init<-1
> for ( i in 1:trials){
+ state<-init
+ t<-0
+ while (TRUE){
+ if (state==1){ q12<-rexp(1,0.0151)
+ q13<-rexp(1,.0071)}
+ if (q12<q13) {t<-t+q12
+ state<-2}
+ else{t<-t+q13
+ break}
+ if (state==2){q23<-rexp(1,.0284)
+ t<-t+q23
+ break}
+}
+ simlist[i]<-t}
> mean(simlist)
[1] 68.37068
Therefore, one’s estimate of the average time to death for a person initially diagnosed
with cirrhosis of the liver is 68.37068 months!
Time reversibility is related to the idea of global balance. Let π be the stationary distri-
bution to the CTMC; that is, πQ = 0 is satisfied, which in turn implies
X
πi qij = πj qj , ∀j: (7.29)
i≠j
Note that the holding time parameter qj is the transition rate from j and that πj is the long-
time proportion of the time the process is in state j; thus, the right-hand side of Equation 7.29
is the long-term rate the process leaves j. Also, it is clear that πiqij is the long-term rate of
transition from i to j; thus, the left-hand side of Equation 7.29 is the long-term rate that the
Bayesian Inference 295
process enters state j. This in turn implies that for a stationary process, the rates in and out
of any state are the same, and the equations in Equation 7.29 are called the global balance
equations. As an example, let
0 1
0 : 0, 1 : 0, 0 : 0
B C
P=B
@ 1=3, 0, 2=3
C
A (7.30)
0 : 0, 1 : 0, 0 : 0
be the transition matrix of an embedded chain, where the process remains in state 1 for an
average of 5 minutes before moving to state 2, where it remains for an average of 2 minutes
before moving to state 3, which is occupied for an average of 4 minutes before moving to
state 2. It can easily be shown that the stationary distribution is π = (5/19,6/19,8/19); thus
Equation 7.29 implies
Thus, the global balance for this example shows that every 19 minutes, the process incurs
one transition to and from state 1, three transitions to and from state 2, and two transitions
to and from state 3.
This concludes the fundamental properties that need to be understood in order to
perform Bayesian inferences for CTMCs.
For this part of the chapter, Bayesian inferences will be performed for a variety of
examples, including some from biology, physics, and business.
where the first row and column correspond to adenine; the second row and column, to
guanine; the third row and column, to cytosine; and the last row and column, to thymine.
Thus, the corresponding transition matrix is
PðtÞ = expðtQÞ
0 1
1 + 3e−4rt , 1 − e−4rt , 1 − e−4rt , 1 − e−4rt
B C
B 1 − e−4rt , 1 + 3e−4rt , 1 − e−4rt , 1 − e−4rt C (7.33)
B C
= ð1=4ÞB C:
B 1 − e−4rt , 1 − e−4rt , 1 + 3e−4rt , 1 − e−4rt C
@ A
1 − e−4rt , 1 − e−4rt , 1 − e−4rt , 1 + 3e−4rt
296 Bayesian Inference for Stochastic Processes
Thus, at time t, the probability that the DNA base adenine is replaced by quinine (or by
cytosine or by thymine) is (1=4)(1 − e−4rt ), etc. On the other hand, the probability that
adenine at time t is not replaced by another base is (1=4)(1 + 3e−4rt ).
The statistical problem is to make inferences about rate r based on observing the evolution
at various times.
Based on Equation 7.32, the infinitesimal rates are
qij = r, i ≠ j, i, j = 1, 2, 3, 4; (7.34)
qi = 3r, i = 1, 2, 3, 4: (7.35)
If one assigns a value to r, one can make inferences about the holding time parameters in
Equation 7.35 and the transition probabilities in Equation 7.36; however, one knows that the
transition probabilities are all 1/3; thus, only the holding time exponential parameters will
be of interest.
In practice, one would observe the holding times of the various states and then from those
observations estimate r. Using WinBUGS, we will assume a value of r and then generate the
exponential holding times. Consider the holding time for occupying the first-state adenine
and assume that its mean time is 2 time units. The WinBUGS program that follows is based
on 50 observations of the holding time for adenine with an average holding time of 2 time
units. The main objective is to estimate the average holding time for adenine.
The holding time T1 for adenine has an exponential distribution with parameter l,
namely,
f ðt1 Þ = l expð−lt1 Þ, t1 > 0; (7.37)
Let l = 1=6 and generate the 50 observations in the list statement of WinBUGS Code 7.1,
which corresponds to a mean holding time of 6 time units. Refer to the generator matrix in
Equation 7.32 for the DNA example where the holding time exponential parameter is 3r;
thus I let 3r = 1/6. It is also assumed that the prior distribution of l is gamma (.001,.001),
a noninformative prior with mean of 1 and variance of 1000.
WinBUGS Code 7.1 is executed with 45,000 observations for the simulation and a burn-in
of 5,000. The results of the analysis are reported in Table 7.1.
TABLE 7.1
Posterior Analysis for Holding Time for Adenine
Parameter Mean SD Error 2 1/2 Median 97 1/2
l .163 .02314 .0001259 .121 .1618 .2118
μ 6.259 0.9034 0.004947 4.721 6.181 8.264
Bayesian Inference 297
The parameter of interest is μ, the average holding time for adenine, which has a posterior
mean of 6.259 with a 95% credible interval of (4.721,8.264). Note that the credible interval
contains the value of 6, which was used to generate the observations in the list statement of
WinBUGS Code 7.1.
It appears that the distributions are symmetric about their posterior means and that the
simulation errors are reasonably small. In summary, based on the posterior median, our
estimate of the mean holding time is 6.181. Clearly, the type of analysis can be repeated for
the other three holding times. There is nothing new to be learned because the mean holding
time μ is the same for all four holding times. The student will be asked to estimate the
holding times for the other three DNA bases as an exercise at the end of this chapter.
Now consider another aspect of Bayesian inference for the holding time for the DNA base
adenine. Remember that the value l = 1=6 (u = 6) is used to generate the adenine holding
times listed in the list statement of WinBUGS Code 7.1. It is of paramount interest to test the
hypothesis that l = 1=6 (u = 6) is a plausible value of the mean holding time.
Thus, using the Bayesian approach, consider a test of the null hypothesis
The approach presented on pages 126–128 of Lee5 is employed to test a simple null
hypothesis versus the two-sided alternative (Equation 7.39).
Recall that the posterior probability of the null hypothesis is given by
ð∞
p0 = ½ π0 f ðtjl = 1=6Þ=½ π0 f ðtjl = 1=6Þ + π1 r1 ðlÞf ðtjlÞdl, (7.40)
0
298 Bayesian Inference for Stochastic Processes
where π0 = P (l = 1=6) is the prior probability of the null hypothesis and π1 = 1 − π0 is the
prior probability of the alternative hypothesis. Also, the probability density of the n holding
times is
X
i=n
n
−l ti
f ðtjlÞ = l e i=1 , (7.41)
X
i=n
n
−ð1=6Þ ti
f ðtjl = 1=6Þ = ð1=6Þ e i=1 : (7.42)
In addition, r1 (l) is the prior density of l under the alternative hypothesis l ≠ 1=6. How
does one choose r1 (l)? It seems reasonable to choose the improper prior density; thus, let
X
i=50
Since ti = 306:32, there is sufficient information to compute the posterior probability of
i=1
the null hypothesis given by Equation 7.40.
Equation 7.40 for the posterior probability of the null hypothesis is formulated as
where
2 3
ð∞
ra = 4 π1 r1 ðlÞf ðtjlÞ dl5=½ π0 f ðtjl = 1=6Þ: (7.45)
0
Thus, the posterior probability of the null hypothesis is expressed in terms of the ratio ra.
Note that as the ratio ra approaches 0, p0 approaches 1.
If one lets π0 = π1 = 1=2, one can show that
ra = Gð50Þ650 e51:05444 = ð306:32Þ50
(7.46)
= :7356:
I took the natural log of ra, used the log gamma function, and then finally used the natural
exponential function to arrive at the value of .7356, the posterior probability of the null
hypothesis. Thus, based on the 50 exponential holding times for adenine of DNA evolution,
and the prior information, one would conclude that l = 1=6, that the null hypothesis is
plausible. Recall that the value l = 1=6 was used to generate the 50 holding times included
in the list statement of WinBUGS Code 7.1.
Bayesian Inference 299
The next objective is to determine the predictive density for the holding times of the DNA
base adenine. Let t(n + 1) be the future observation for the holding time for adenine.
Note that the predictive density for t(n + 1) is
ð∞
f ðtðn + 1ÞjdataÞ = f ðtðn + 1ÞjlÞf ðdatajlÞzðlÞdl, (7.47)
0
where
X
i=n
n
−l ti
f ðdatajlÞ = l e i=1 , 0 < t1 < t2 < … < tn , (7.49)
where ti is the ith holding time and z(l) is the prior density for l.
Choosing the improper prior density
one may show that the predictive density in Equation 7.47 reduces to
" #n+1
X
i=n
f ðtðn + 1ÞjdataÞ = Gðn + 1Þ= tðn + 1Þ + ti , tðn + 1Þ > 0:
i=1
The predictive density for t(n + 1) is completely determined when the data n = 50 and
X
i=n
ti = 306:32 are substituted into Equation 7.50. WinBUGS provides a way to compute
i=1
future values from the predictive density in Equation 7.51. Refer to WinBUGS Code 7.1 and
add the command Z[i]~dexp(lamda) and execute WinBUGS Code 7.1 the usual way for the
example when I did the posterior analysis with 55,000 observations for the simulation and a
burn-in of 5,000; the first five predicted holding times are reported in Table 7.2.
TABLE 7.2
Posterior Predictive Analysis
Future Mean SD Error 2 1/2 Median 97 1/2
t(51) 6.186 6.29 0.03337 0.1463 4.21 23.26
t(52) 6.254 6.393 0.03186 0.1532 4.236 23.52
t(53) 6.226 6.343 0.03236 0.1541 4.292 23.36
t(54) 6.209 6.314 0.03075 0.148 4.264 23.48
t(55) 6.18 6.312 0.029 0.1498 4.24 23.34
300 Bayesian Inference for Stochastic Processes
Thus, the mean of the predictive distribution for the first future holding time for adenine
is 6.186 time units and a 95% predictive interval of (0.1463,23.26). I used a gamma prior
(.001,.001) for l WinBUGS Code 7.1, but the formula for the predictive density in Equation
7.51 was the improper prior in Equation 7.50; however, there will be very little difference in
the predicted future values. Note the uncertainty in the prediction implied by the long with
of the prediction intervals.
We next consider a variation of the Jukes–Cantor model called the Kimura6 model with
infinitesimal rates given by the matrix
0 1
−ðr + 2sÞ, r, s, s
B C
B r, −ðr + 2sÞ, s, s C
B C
Q=B C: (7.51)
B s, s, −ðr + 2sÞ, r C
@ A
s, s, r, −ðr + 2sÞ
Thus, the evolution remains in the base nucleotide adenine for a time with an exponential
parameter r + 2s. This model distinguishes between the substitutions a ↔ g (from purine to
purine or from pyrimidine to pyrimidine) and transversions (from purine to pyrimidine or
vice versa). Recall Section 5.7, where these two evolutionary models (Jukes–Cantor and
Kimura) were analyzed in discrete time. Thus, referring to Equation 7.51, the rate r is the
exponential time that the process remains in adenine until guanine is substituted. The rate s
is the exponential parameter for the holding time in adenine until cytosine is substituted for
adenine, and the same rate s is the exponential parameter for the holding time of adenine
until adenine is substituted by thymine.
Note that corresponding to the infinitesimal rate matrix Q in Equation 7.51, the proba-
bility transition matrix
Pij ðtÞ = 1 + e−4st − 2e−(r+s)t =4, ði, jÞ ∈ fag, ga, ct, tcg,
= 1 − 2e−4t =4, ði, jÞ ∈ fac, at, gc, gt, ca, cg, ta, tgg, (7.52)
= 1 + e−4st + 2e−2(r+s)t =4, ði, jÞ ∈ faa, gg, cc, ttg:
See page 282 of Dobrow1 for additional information about the derivation of Equation 7.52.
The three phases of Bayesian inference will be presented for the Kimura model of
molecular evolution. To that end, one must generate the holding times for the two rates r
and s and let r = 1/2 and s = 1/8; thus, the holding time for adenine until the substitution by
guanine has an average of 2 time units, while the holding time for adenine until the sub-
stitution by cytosine is 8 time units.
I generated data for the holding times T12 and T13 of adenine until substituted by guanine
and cytosine, respectively. The list statement of WinBUGS Code 7.2 contains the 15 holding
times, where the exponential parameter for T12 is l12 = 1/2; and for T13 , l13 = 1=8. WinBUGS
Code 7.2 is executed with 35,000 observations for the simulation and 5,000 for the burn-in:
Bayesian Inference 301
T13[i]~dexp(lamda13)}
# m13 is the average holding time for adenine before it is substituted by
#cytosine
mu13<-1/lamda13
T12[i]~dexp(lamda12)}
# mu12 is the average holding time for adenine before it is substituted by
#guanine
mu12<-1/lamda12
# d23 is the difference in the two holding times for adenine
d23<-mu12-mu13
}
list(T13 = c(
11.98,12.58,7.757,24.86,5.816,
8.416,2.104,18.0,3.069,7.62,
0.01324,27.58,3.004,6.996,1.003),
T12 = c(
2.996,3.145,1.939,6.215,1.454,
2.104,0.5259,4.5,0.7673,1.905,
0.003311,6.896,0.751,1.749,0.2509))
list(lamda13=.125,lamda12=.5)
The posterior analysis for the two holding times is reported in Table 7.3.
Using the posterior mean of 2.51 time units as the estimate of the average adenine
holding time until adenine is substituted by guanine, and 10.07 time units as the estimate
of the adenine holding time until substituted by cytosine, leads to a difference between
the two estimates as −7.556 time units, which in turn implies that the two are indeed dif-
ferent (because the 95% credible interval of (−14.29,−3.164) does not include zero). This is
an informal inference about the difference in two estimates, and it appears that the Kimura
model is indeed appropriate and is to be preferred to the Jukes–Cantor model.
302 Bayesian Inference for Stochastic Processes
TABLE 7.3
Posterior Analysis for the Kimura Model
Parameter Mean SD Error 2 1/2 Median 97 1/2
d23 −7.556 2.858 .01387 −14.29 −7.14 −3.164
l12 .427 .1109 .000541 .2394 .4163 .6694
l13 .1064 .0274 .000127 .05981 .1039 .1668
μ12 2.51 0.6957 0.003384 1.494 2.402 4.178
μ13 10.07 2.776 0.0133 5.996 9.62 16.72
will be presented.
Consider the posterior probability of the null hypothesis
where
ratio = N=D,
ð∞ ð∞
N = π1 r1 ðl12 , l13 Þf ðT12 jl12 Þf ðT13 jl13 Þdl12 dl13 , (7.55)
0 0
ð∞
D = π0 r0 ðlÞf ðT12 , T13 jl12 = l13 = lÞdl, (7.56)
0
!
n1 2
X
i=n1
f ðT12 jl12 Þ = l12 exp −l12 T12 ðiÞ , (7.59)
i=1
Bayesian Inference 303
and
!
n1 3
X
i=n2
f ðT13 jl13 Þ = l13 exp −l13 T13 ðiÞ : (7.60)
i=1
X
i=15 X
i=15
Note that n1 = n2 = 15, T12 (i) = 35:2014, and T13 (i) = 140:7934.
i=1 i−1
From the preceding information and assuming π0 = π1 , it can be shown that the
ratio = 403; thus, from Equation 7.54, the posterior probability that the null hypothesis
is true is p0 = :016.
This implies that the null hypothesis is not true and that l12 ≠ l13 .
Of course, this is not surprising because the T12 (i) data are generated using the expo-
nential distribution with parameter l12 = :5 and the T13 (i) data are generated using the
exponential distribution with parameter l13 = :125. The overall conclusion is that the
average holding time for adenine until substituted with guanine is different (much smaller)
from the holding time for adenine until substituted with cytosine.
Another generalization of DNA molecular evolution is described by Felsenstein and
Churchill7 with infinitesimal rate matrix
0 1
−að1 − pa Þ, apg , apc , apt
B C
B apa , −að1 − pg Þ, apc , apt C
B C
Q=B C, (7.61)
B apa , apg , −að1 − pc Þ, apt C
@ A
apa , apg , apc , −að1 − pt Þ
where the total holding time for adenine has an exponential distribution with parameter
apg + apc + apt = a(1 − pa ), or mean = 1=a(1 − pa ) until substituted with guanine, or cytosine,
or thymine. It can be shown that the stationary distribution of this chain is π = (pa , pg , pc , pt ),
where pa + pg + pc + pt = 1. Using Q and π and determining that P(t) = exp (tQ) provide the
probability transition matrix as
Pij ðtÞ = 1 − e−at pj , i ≠ j,
(7.62)
= e−at + 1 − e−at pj , i = j,
with i, j = a, g, c, t. Note that these probabilities do not depend on the initial state i and that
the effect of the scalar is to contract or expand the holding time parameter = a(1 − pa ) for
adenine; therefore, it is of interest to investigate the value of a. This will be achieved in the
special case π = (:292,:207,:207,:292), the stationary distribution for humans. The first part
of the Bayesian analysis is to estimate a by using observations for the holding time of
adenine. Of course, the holding time of any base could have been used to estimate a. I
will assume that a = 1; thus, the exponential parameter for the holding time of adenine is
(1 − pa ) = (1 − :292) = :708, which corresponds to an average holding time of 1.4124 time
units. Fifteen observations will be generated from an exponential distribution with parame-
ter .708, and then based on these observations, a Bayesian analysis will be executed in
order to estimate a. The Bayesian analysis is executed with 35,000 observations for the
simulation and 5,000 for the burn-in.
304 Bayesian Inference for Stochastic Processes
TABLE 7.4
Posterior Analysis for Felsenstein–Churchill7 Model
Parameter Mean SD Error 2 1/2 Median 97 1/2
a 0.8528 0.2202 0.001089 0.4789 0.8325 1.337
l .6038 .1559 .000770 .339 .5894 .9464
μ 1.774 0.4892 0.002441 1.057 1.697 2.95
The results of the analysis are reported in Table 7.4. The prior distribution for l is a
noninformative gamma distribution, and the 15 data values included in the first list
statement are generated with an exponential distribution with parameter .708.
Note that l is the parameter for the exponential holding time for adenine and a is the
main parameter of interest and is the scale factor for the holding time, while μ is the average
waiting time for adenine.
The main parameter of interest is a and is estimated as 0.8325 with the posterior median
and a 95% credible interval of (0.4789,1.337), which implies that it is plausible and rea-
sonable to believe that a = 1. Perhaps a more formal test of the null hypothesis
H: a = 1 versus A: a ≠ 1: (7.63)
is in order.
Bayesian Inference 305
The explanation on pages 126 and 127 of Lee5 is adopted for the Bayesian approach to
testing a point null hypothesis. The posterior probability of the null hypothesis is given by
p0 = 1=ð1 + g Þ, (7.65)
where
ð∞
g = π1 r1 ðlÞf ðtjlÞdl=π0 f ðtjl = :708Þ: (7.66)
0
In addition,
!!
X
i=n
n
f ðtjl = :708Þ = f ðtjl = :708Þ = ð:708Þ exp −:708 ti , (7.67)
i=1
X
i=n
ti = 24:869239: (7.68)
i=1
Consequently, one would not reject the null hypothesis; thus, it is plausible to believe that
a = 1 and that the holding time for adenine has a parameter of (1 − .292) = .708 or, an
average, holding time of 1.4124 time units.
Our last example for DNA evolution is a generalization of the Felsenstein–Churchill
model to the Hasegawa, Kishino, and Yano8 version for molecular evolution, with infini-
tesimal rate matrix
306 Bayesian Inference for Stochastic Processes
0 1
− apg + bpr , apg , bpc , bpt
B C
B C
B apa , −ðapa + bpr Þ, bpc , bpt C
B
Q=B C, (7.72)
C
B bpa , bpg , −ðapt + bps Þ, apt C
@ A
bpa , bpg , apc , −ðapc + bps Þ
where
pr = pc + pt , ps = pa + pg ,
and
pa + pg + pc + pt = 1:
The parameters a and b are unknown positive parameters, and the stationary distribution
of the process is π = (pa , pg , pc , pt ).
This model makes a distinction between transitions and transversions, distinguishing
between the substitutions a ↔ g, from purine to purine or from pyrimidine to pyrimidine,
and transversions, from purine to pyrimidine or vice versa, i.e., the substitutions c ↔ t.
At the time, this approach was based on a new statistical method for estimating diver-
gence dates of species from DNA sequence data by a molecular clock approach is devel-
oped. This method takes into account effectively the information contained in a set of DNA
sequence data.
The molecular clock of mitochondrial DNA was calibrated by setting the date of diver-
gence between primates and ungulates at the Cretaceous–Tertiary boundary (65 million
years ago), when the extinction of dinosaurs occurred.
Our investigation will center on the conjecture that a = b, that the Hasegawa, Kishino,
and Jano model (Equation 7.72) reduces to the Felsenstein–Churchill evolutionary process
(Equation 7.61), and that the evolutionary process does not distinguish transversions from
transitions. Thus, let the null hypothesis be
Then the null hypothesis supports the Felsenstein−Churchill process, and in order to
illustrate Bayesian inferences, the holding time data will be generated that favor the
alternative hypothesis, the Hasegawa, Kishino, Jano model. Suppose a = 2 and b = 8 and
the stationary distribution for humans, namely, pa = :292, pg = :207, pc = :207, and pt = :292,
is employed to fix the values of the first row of Q in Equation 7.72. Consider the holding
time for adenine until substituted by quinine, which is denoted by apg , and the holding
time for thymine until substituted by adenine, denoted by bpa . I used a = 2 and b = 8 to
generate the holding times for adenine (until substituted by guanine) and thymine (until
substituted by adenine), respectively, and these values appear in the list statement of
WinBUGS Code 7.4.
There is sufficient information to execute the Bayesian analysis with 35,000 observations
for the simulation and 5,000 for the burn-in.
Bayesian Inference 307
The prior distributions for the exponential parameters la and lt are noninformative
gamma (.001,.001) distributions, the conjugate prior to the exponential distribution; thus,
most of the information for the Bayesian analysis is based on the holding time observation
HTa and HTt listed in WinBUGS Codes 7.4.
Some of the posterior distributions are skewed; thus, the Bayesian estimates will be based on
the posterior median. For example, consider a with an estimate of 2.559, which in turn should
be compared with a = 2, the value used to generate the data in the list statement of WinBUGS
Code 7.4.
Also note that the posterior median of la is .538, which is the exponential parameter for
the holding time of adenine (before being substituted by guanine) and should be compared
308 Bayesian Inference for Stochastic Processes
TABLE 7.5
Posterior Analysis for the Hasegawa, Kishino, and Yano Model
Parameter Mean SD Error 2 1/2 Median 97 1/2
a 2.675 0.7658 0.004055 1.389 2.599 4.379
b 9.135 2.642 0.01419 4.736 8.858 15.04
dat −6.46 2.748 0.01492 −12.51 −6.221 −1.749
la .5538 .1585 .000839 .2876 .538 .9064
lt 2.667 0.7714 0.004143 1.383 2.587 4.392
μa 1.968 0.6191 0.003331 1.103 1.859 3.477
μt .4104 .1298 .000687 .2279 .3877 .7273
to la = :414, the value used to generate the exponentially distributed holding times. The
key parameter is dat , the difference between alpha and beta and its posterior median of
−6.221 with a 95% credible interval of (−12.51,−1.747), which implies that a ≠ b. It is left for
the student to develop a formal Bayesian test of a = b. For the Bayesian method of testing
hypotheses, see pages 126 and 127 of Lee.5 Also, as in the previous example of molecular
evolution (the Jukes–Cantor model), it is easy to derive the predictive density of a future
adenine (or thymine) holding time, and this will be left as an exercise for the student.
See Table 7.5.
corresponding to the state space S = f0, 1, 2, :::::g. The state 0 is an absorbing barrier; that is,
once the population size reaches 0, it dies out. Thus, if the population size is 1, the holding
time distribution of state 1 until the next death is the exponential parameter μ1 , while on the
Bayesian Inference 309
other hand, the holding time distribution of state 1 until a birth has an exponential distri-
bution with parameter l1 . Note that the birth rates li and death rates μi depend on the
present size of the population.
Since the process is time reversible, one can derive the stationary distribution via the local
balance equations
π1 = π0 l0 =μ1
and
π2 = π1 l1 =μ2 = π0 l0 l1 =μ1 μ2 :
X
k=∞ X
k=∞ Y
i=k
1= πk = π0 li−1 =μi , k = 0, 1, 2:::: (7.77)
k=0 k=0 i=0
k=∞ Y
X i=k
li−1 =μi < ∞, i = 1, 2:::
k=0 i=0
so that Equation 7.77 converges; then the unique stationary distribution is determined as
Y
i=k
πk = π 0 li−1 =μi , k = 0, 1, 2, …,
i=1
where
!−1
X
k=∞ Y
i=k
π0 = li−1 =μi : (7.78)
k=0 i=1
In the infinite case, notice all states are transient except the absorbing state 0.
310 Bayesian Inference for Stochastic Processes
Now consider a finite state space with infinitesimal rate matrix and state space
S = {0,1,2,3,4}:
0 1
−l0 , l0 , 0:0, 0:0, 0:00
B C
B μ1 , −ðμ1 + l1 Þ, l1 , 0, 0 C
B C
B C
B
Q = B 0, μ2 , −ðμ2 + l2 Þ, l2 , 0 C
C: (7.79)
B C
B 0, 0, μ3 , −ðμ3 + l3 Þ, l3 C
@ A
0:0, 0:0, 0:0, μ4 , −μ4
for ( i in 1:20){
# is the vector of holding times when the process is in state 1 until the
process switches to state 0
HT10[i]~dexp(mu1)
HT12[i]~dexp(lamda1)
HT21[i]~dexp(mu2)
HT23[i]~dexp(lamda2)
HT32[i]~dexp(mu3)
HT34[i]~dexp(lamda3)}
#p10 is the death rate when the population size is 1
p10<-mu1/(mu1+lamda1)
# p12 is the birth rate when the population is size 1
p12<-lamda1/(mu1+lamda1)
# p21 is the death rate when the population is size 2
p21<-mu2/(mu2+lamda2)
#p23 is the birth rate when the population is size 2
p23<-lamda2/(mu2+lamda2)
# p32 is the death rate when the population is size 3
Bayesian Inference 311
p32<-mu3/(mu3+lamda3)
#p34 is the birth rate when the population is size 3
p34<-lamda3/(mu3+lamda3)
# the following is the average holding time for the process in state 1 until
it switches to state 0
nu1<-1/mu1
#the following is the average holding time for the process in state 1 until
it switches to state 2
vu1<-1/lamda1
nu2<-1/mu2
vu2<-1/lamda2
nu3<-1/mu3
vu3<-1/lamda3
}
list(
HT10 = c(
0.4236,0.0738,0.01755,0.2506,0.1679,
0.1345,0.1335,0.2103,0.5676,0.1256,
1.25,0.08106,0.08959,0.789,0.966,
0.4133,0.01223,0.08178,0.7944,0.2417),
HT12 = c(
0.6452,0.3766,0.4237,0.8919,0.1333,
0.2981,0.4902,0.1167,0.2695,0.7278,
0.2951,3.941,1.342,0.4537,0.9498,
1.354,0.5427,0.5481,0.1861,0.8717),
HT21 = c(
0.3853,0.0437,0.05582,0.1248,0.2109,
0.2065,0.5253,0.9537,0.07334,0.01717,
0.1436,0.2864,0.7099,0.04587,0.4547,
0.2007,0.438,0.5084,0.3366,0.4267),
HT23 = c(
0.2497,0.1747,0.09605,0.08779,0.1217,
0.1621,0.1332,0.255,2.358,1.472,
0.2527,0.6953,1.937,0.191,1.772,
0.2749,0.03768,0.1866,0.41,1.134),
HT32 = c(
0.007235,0.07714,0.02351,0.3239,0.1192,
0.2329,0.3503,0.1093,0.1339,0.5003,
0.2394,0.336,0.08296,0.229,0.06038,
0.07797,0.125,0.035,0.2428,0.4869),
HT34 = c(
1.067,0.2683,0.6207,0.1697,0.1857,
0.1188,0.2984,0.03796,0.2262,0.4814,
0.5348,0.4655,0.3812,0.1125,0.00313,
0.9027,0.0557,0.4312,0.4711,0.1909))
list(mu1=2,mu2=3,mu3=4,lamda1= 1,lamda2=2,lamda3=3)
The Bayesian analysis employs the exponential distribution with parameter μi as the
likelihood function for μi and uses the noninformative prior gamma (.001,.001) for μi , while
312 Bayesian Inference for Stochastic Processes
for the birth rate parameter li , its likelihood has an exponential distribution with parameter
li and prior gamma (.001,.001). Refer to WinBUGS Code 7.5 for the statements corre-
sponding to the likelihood function and prior of li and μi , i = 1, 2, 3.
The Bayesian analysis is for the three birth rates li , i = 1, 2, 3, and death rates μi , i = 1, 2, 3.
The corresponding average holding times for the deaths are given by hi , i = 1, 2, 3, and by
ni , i = 1, 2, 3, for the births.
The transition probabilities are denoted by p10 , p12 , p21 , p23 , p32 , and p34 , and 20 expo-
nential holding times for the death and births are generated; thus, the transition proba-
bilities are based on 20 transitions to the neighboring states.
Consider the transition probability p12 from a population of 1 to a population of size 2
(because of a birth); then the corresponding posterior mean is .3188 with 95% credible
interval (.1968,.4638). On the other hand, the posterior mean of p10 is .6812 with 95%
credible interval (.5362,.8034), implying that the chances are higher for the population to
become extinct than to increase by 1. See Table 7.6.
The next inference to be considered is the estimation of the average time to extinction for
the process
0 1
−l0 , l0 , 0:0, 0:0, 0:00
B C
B μ1 , −ðμ1 + l1 Þ, l1 , 0, 0 C
B C
B C
B
Q = B 0, μ2 , −ðμ2 + l2 Þ, l2 , 0 C
C, (7.80)
B C
B 0, 0, μ3 , −ðμ3 + l3 Þ, l3 C
@ A
0:0, 0:0, 0:0, μ4 , −μ4
TABLE 7.6
Posterior Analysis for Birth and Death Process
Parameter Mean SD Error 2 1/2 Median 97 1/2
l1 1.345 0.3015 0.001345 0.8237 1.322 2
l2 1.666 0.3725 0.001656 1.016 1.637 2.475
l3 2.852 0.6333 0.002825 1.749 2.806 4.222
μ1 2.927 0.6571 0.002994 1.787 2.877 4.347
μ2 3.25 0.7288 0.003365 1.988 3.196 4.825
μ3 5.268 1.174 0.005562 3.225 5.176 7.089
h1 .3598 .08517 .0003899 .23 .3476 .5595
h2 .3239 .0763 .0003522 .2072 .3129 .50321
h3 .1997 .04686 .000214 .1281 .1932 .31
p10 .6812 .06828 .000299 .5362 .6852 .8032
p12 .3188 .06828 .000299 .1968 .31248 .4638
p21 .6575 .07082 .000335 .5092 .6612 .7852
p23 .3425 .07082 .000335 .2148 .3388 .4908
p32 .6454 .07145 .000327 .498 .6488 .7756
p34 .3546 .07145 .000327 .2244 .3512 .502
n1 .7827 .1847 .000854 .5001 .7567 1.214
n2 .6317 .1487 .000664 .4041 .6109 .9846
n3 .3689 .08655 .000398 .2369 .3564 .5718
Bayesian Inference 313
X
i=k
ai = Fij , (7.81)
i=1
where Fij is the ijth element of F. See pages 288 and 289 of Dobrow1 for a proof.
WinBUGS Code 7.6 is the WinBUGS Code for estimating the average time to extinc-
tion for the birth and death process with matrix Q in Equation 7.79. Noninformative
gamma (.001,.001) distributions were used as priors for the parameters: the death rates
μi , i = 1, 2, 3, 4, and birth rates li , i = 1, 2, 3. The Bayesian analysis is executed with 57,000
observations and 1,000 for the burn-in.
{
#prior distributions for the parameters
lamda1~dgamma(.001,.001)
mu1~dgamma(.001,.001)
lamda2~dgamma(.001,.001)
mu2~dgamma(.001,.001)
lamda3~dgamma(.001,.001)
mu3~dgamma(.001,.001)
mu4~dgamma(.001,.001)
for ( i in 1:20){
# the seven holding times for (2.79)
HT10[i]~dexp(mu1)
HT12[i]~dexp(lamda1)
HT21[i]~dexp(mu2)
HT23[i]~dexp(lamda2)
HT32[i]~dexp(mu3)
HT34[i]~dexp(lamda3)
HT4[i]~dexp(mu4)}
314 Bayesian Inference for Stochastic Processes
# the -V matrix
v[1,1]<-mu1+lamda1
v[1,2]<-(-lamda1)
v[1,3]<-0
v[1,4]<-0
v[2,1]<-(-mu2)
v[2,2]<-mu2+lamda2
v[2,3]<- (-lamda2)
v[2,4]<-0
v[3,1]<-0
v[3,2]<-(-mu3)
v[3,3]<-mu3+lamda3
v[3,4]<-(-lamda3)
v[4,1]<-0
v[4,2]<-0
v[4,3]<-(-mu4)
v[4,4]<-mu4
# F is the inverse of -V.
F[1:4,1:4]<-inverse(v[1:4,1:4])
list(
HT10 = c(
0.4236,0.0738,0.01755,0.2506,0.1679,
0.1345,0.1335,0.2103,0.5676,0.1256,
1.25,0.08106,0.08959,0.789,0.966,
0.4133,0.01223,0.08178,0.7944,0.2417),
HT12 = c(
0.6452,0.3766,0.4237,0.8919,0.1333,
0.2981,0.4902,0.1167,0.2695,0.7278,
0.2951,3.941,1.342,0.4537,0.9498,
1.354,0.5427,0.5481,0.1861,0.8717),
HT21 = c(
0.3853,0.0437,0.05582,0.1248,0.2109,
0.2065,0.5253,0.9537,0.07334,0.01717,
0.1436,0.2864,0.7099,0.04587,0.4547,
0.2007,0.438,0.5084,0.3366,0.4267),
HT23 = c(
0.2497,0.1747,0.09605,0.08779,0.1217,
0.1621,0.1332,0.255,2.358,1.472,
0.2527,0.6953,1.937,0.191,1.772,
0.2749,0.03768,0.1866,0.41,1.134),
HT32 = c(
0.007235,0.07714,0.02351,0.3239,0.1192,
0.2329,0.3503,0.1093,0.1339,0.5003,
Bayesian Inference 315
0.2394,0.336,0.08296,0.229,0.06038,
0.07797,0.125,0.035,0.2428,0.4869),
HT34 = c(
1.067,0.2683,0.6207,0.1697,0.1857,
0.1188,0.2984,0.03796,0.2262,0.4814,
0.5348,0.4655,0.3812,0.1125,0.00313,
0.9027,0.0557,0.4312,0.4711,0.1909),
HT4 = c(
0.7442,0.4533,0.07353,0.03283,0.1242,
1.001,0.1311,1.057,0.09183,0.226,
0.3407,0.1795,0.01064,0.003547,0.3841,
0.6416,0.06772,0.06674,0.2898,0.1095)))
list(mu1=2,mu2=3,mu3=4,mu4=4,lamda1= 1,lamda2=2,lamda3=3)
The posterior distributions are skewed; thus, the posterior medians should be used as
point estimators. For example, when the process is in state 4, the posterior median is .7252
time units, but if the process is in state 1, the posterior median time to extinction is .399 time
units. This seems to appear to be reasonable because closer states to the absorbing state 0
have smaller posterior medians. See Table 7.7.
Y
i=k
πk = π0 ðl=μÞ = π0 ðl=μÞk , k = 0, 1, …, (7.82)
i=1
TABLE 7.7
Posterior Analysis for Extinction
Parameter Mean SD Error 2 1/2 Median 97 1/2
a1 0.4248 0.4461 0.001472 0.2738 0.399 0.6533
a2 0.5676 1.36 .004491 0.3172 0.493 10.028
a3 0.6699 5.77 .01083 0.2741 0.4882 1.638
a4 1.063 5.77 .01919 0.3704 0.7253 2.844
316 Bayesian Inference for Stochastic Processes
Bayesian inferences will focus on estimating the rates μ and l and testing the hypothesis
that l < μ. Recall that for this process, the infinitesimal rate matrix is
0 1
−l, l, 0, 0, ::::::::::::::::
B C
B μ, −ðμ + lÞ, l, 0, 0, :::: C
B C
B C
B 0, μ, −ðμ + lÞ, l, 0, :::: C
B C
B C
B
Q = B 0, 0, μ, −ðμ + lÞ, l, 0, : C
C: (7.85)
B C
B: C
B C
B C
B: C
@ A
:
Observations for the holding times with exponential parameters l and μ will be gen-
erated, and then based on those observations, Bayesian inferences will be presented.
Suppose that l = 2 < μ = 5. The likelihood functions for l and μ are determined by the
exponential density and the 17 holding time observations denoted by HT2 for l and
HT5 for μ. Noninformative gamma (.001,.001) distributions are assumed for the two
unknown parameters. The objective of the Bayesian analysis is to estimate the stationary
distribution of the random walk and to estimate Pr (l > μjdata), thus testing the hypothesis
H: l > μ.
WinBUGS Code 7.7 is executed with 35,000 observations for the simulation and a burn-in
of 5,000. See Table 7.8 for the posterior analysis.
m2<-1/lamda
m5<-1/mu
# the pi[k] are the stationary probabilities
for( k in 0:5){
pi[k]<-(1-lamda/mu)*pow(lamda/mu,k)}
diff<-lamda-mu
#prob is the Pr (λ > μ)
Bayesian Inference 317
prob<-step(diff)
}
list(
HT2 = c(
1.155,0.1775,1.513,0.1776,0.9627,
0.602,0.05385,0.2169,0.1129,0.3904,
0.7396,0.06482,0.09624,0.1167,0.5177,
0.511,0.3539),
HT5 = c(
0.09529,0.1754,0.4323,0.04315,0.01035,
0.05834,0.05996,0.09225,0.07383,0.1131,
0.1176,0.1822,0.1276,0.2809,0.001542,
0.01506,0.2859))
list( mu=5,lamda=2)
The posterior distributions for the parameters of the random walk appear to be sym-
metric about the posterior mean, and it also appears that l < μ because the 95% credi-
ble interval for the difference l − μ excludes zero and has a negative posterior mean of
−5.66. It should be remembered that the 17 holding times were generated with the values
l = 2 < μ = 5. With such a small sample size, it is not surprising that the posterior means for
l and μ are not very close to their hypothetical values.
The hypothesis l > μ has posterior probability of 0, as measured by the posterior median;
thus, one would conclude that l < μ, further implying that the stationary distribution is
well defined in that the geometric series in Equation 7.84 converges!
TABLE 7.8
Posterior Analysis for Random Walk
Parameter Mean SD Error 2 1/2 Median 97 1/2
diff −5.66 1.985 0.01111 −9.939 −5.506 −2.185
l 2.19 0.526 0.003034 1.286 2.148 3.332
m2 .4846 .1241 .000729 .3002 .4656 .7778
m5 .1345 .03501 .000207 .08321 .1304 .219
μ 7.85 1.915 0.01085 4.567 7.671 12.01
π1 .1974 .03646 .000126 .1209 .2013 .2495
π2 .06812 .03107 .000106 .01713 .05645 .1354
π3 .02151 .01953 .000066 .00242 .01581 .07544
π4 .008273 .01373 .000046 .000341 .00442 .04181
π5 .003485 .01363 .000046 .000482 .00124 .02316
Pr (l > μ) .0001333 .01155 .000053 0 0 0
318 Bayesian Inference for Stochastic Processes
0 1
−l, l, 0, 0, 0, 0, 0, 0, 0, 0:::::
B C
B 0, −2l, 2l, 0, 0, 0, 0, 0::::::: C
B C
B C
B 0, 0, −3l, 3l, 0, 0, 0, 0, 0:::: C
B C
B C
B
Q = B: C: (7.86)
C
B C
B 0, 0, 0, 0, 0, −il, il, 0, 0, 0, :: C
B C
B C
B: C
@ A
:
Note for such a process, all states are transient and the limiting probability does not exist.
It is easily shown that the transition function is
!
j − 1 −ilt j−1
Pij ðtÞ = e 1 − e−lt , i ≤ j, t > 0, (7.87)
i−1
which is the negative binomial distribution. In particular, starting with a population of size
1, the probability the size remains at 1 at time t is given by
P11 ðtÞ = expð−ltÞ: (7.88)
{
lamda~dgamma(.01,.01)
for ( i in 1:20){
HT[i]~dexp(lamda)}
for ( t in 1:10){
p11[t]<-exp(-lamda*t)}
}
list(
HT = c(
0.9923,0.6045,0.09804,0.04378,0.1655,
1.335,0.1748,1.409,0.1224,0.3013,
0.4542,0.2393,0.01419,0.004729,0.5122,
0.8555,0.09029,0.08898,0.3865,0.146))
list(lamda=3)
Bayesian Inference 319
TABLE 7.9
Posterior Analysis for the Yule Process
Parameter Mean SD Error 2 1/2 Median 97 1/2
l 2.486 .5562 .003134 1.525 2.441 3.691
P11 (1) .096 .05049 .0002882 .02494 .08711 .2176
P11 (2) .01177 .01308 .0000755 .0006221 .007589 .04733
P11 (3) .001757 .003381 .0000201 .0000155 .000661 .0103
The results of the Bayesian analysis are reported in Table 7.9. Note that the posterior mean
of l is 2.4876 with a 95% credible interval of (1.525,3.691), and the posterior mean of P11 (1)
is .096 and that the posterior mean of P11 (t), t = 2, 3, is decreasing as it should.
It is straightforward to test hypotheses about l and to derive the formula for future
holding times with exponential parameter l. The student will be asked to perform these
inferences as problems at the end of the chapter.
where the rates μ, n, and l are positive and are the parameters of the relevant holding times,
which have an exponential distribution.
Referring to Equation 7.89, it is apparent that if the population is 0, it can increase by
one person if one person immigrates to the population. Our goal is to estimate the
parameters and to test hypotheses about those parameters. In order to perform a Bayesian
analysis, let μ = 1=2, n = 1=3, and l = 1; that is, if the population is size i (i = 1,2,...), the
average number of immigrants per day is 3, the average number of births is 1, and the
average number of deaths is 2 per day. Note the birth and death rates depend on the
present population size, but the immigration rate does not. The Bayesian analysis is rel-
atively straightforward and is executed with WinBUGS Code 7.9 with noninformative
prior gamma (.01,.01) distributions and using 35,000 observations for the simulation and a
burn-in of 5,000:
320 Bayesian Inference for Stochastic Processes
{
lamda~dgamma(.01,.01)
mu~dgamma(.01,.01)
nu~dgamma(.01,.01)
for( i in 1:16){
HTmu[i]~dexp(mu)
HTvu[i]~dexp(nu)
HTlamda[i]~dexp(lamda)}
mua<-1/mu
nua<-1/nu
lamdaa<-1/lamda
}
list(
HTlamda = c(
1.159,1.833,0.2687,0.1907,0.2907,
0.2291,0.6853,0.5028,0.6184,2.253,
0.3,3.233,0.9386,0.9576,1.274,
0.2392),
HTmu = c(
0.1633,0.3263,0.7803,0.5374,0.9227,
0.2175,0.6166,0.9843,7.635,0.8423,
0.2366,0.7924,3.172,0.6005,0.4124,
0.08125),
HTvu = c(
2.049,1.409,3.333,4.758,5.905,
0.03409,6.001,1.666,0.281,1.086,
3.418,1.319,2.271,0.4253,6.108,
5.066))
list(lamda=1,vu=.333,mu=.5)
The Bayesian analysis for the immigration model is portrayed in Table 7.10.
TABLE 7.10
Posterior Distributions for Birth and Death with Immigration
Parameter Mean SD Error 2 1/2 Median 97 1/2
l 1.07 0.2679 0.001294 0.6131 1.047 1.661
E(l) 0.9971 0.2663 0.001282 0.6002 0.9551 1.631
μ 0.8717 0.2181 0.001046 0.4999 0.8513 1.35
E(μ) 1.223 0.3249 0.001632 0.7408 1.175 2.001
n .3544 .08832 .000458 .2033 .3468 .5478
E(n) 3.008 0.7985 0.004228 1.825 2.884 4.919
Bayesian Inference 321
The main parameters of interest are the immigration rate and the average number of
immigrants per day.
With regard to the immigration rate, the posterior mean is .3544 with a 95% credible
interval (.2003,.5478), while for the average number of immigrants per day, the posterior
median is 2.884 with posterior standard deviation of 0.7985. Note the asymmetry in the
posterior distribution of E(n), which is easily seen with its posterior density. Also note that
the 95% credible interval for l includes the value 1; the 95% credible interval for μ includes
1/2, and that for n contains 1/3. What does this imply about the generated holding times
HTmu, HTnu, and HTlamda?
where S(0) + I(0) = N and b is the transmission rate, the number of contacts per unit time that
result in an infection of a susceptible individual. Pages 302–308 of Allen3 present a more
detailed account of the SI and SIS models and are an excellent reference of the general area
of stochastic epidemics.
For the stochastic version, the infinitesimal generator matrix for the number of infected
individuals with state space {0, 1, 2, …, N} is given as
0 1
−bðN − 1Þ=N, bðN − 1Þ=N, 0, 0, 0, ::::::::::::::::::::::::
B C
B 0, −2bðN − 2Þ=N, 2bðN − 2Þ=N, 0, 0, 0, ::::::::::::::::::: C
B C
B C
B 0, 0, −3bðN − 3Þ=N, 3bðN − 3Þ=N, 0, 0, ::::::::::::::::: C
B C
B C
Q=B
B:
C:
C (7.91)
B C
B: C
B C
B C
B 0, 0, 0, 0, ::::::::::::::::::::::: −bðN − 1Þ=N, bðN − 1Þ=N C
@ A
0, 0, 0, 0, :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::0, 0
The only unknown parameter is the transmission rate b, the number of contacts per unit
time of infected individuals with susceptible people resulting in an infection.
The holding time for state 1 (with one infected individual) is 2b(N − 2)=N. How should b be
estimated? Remember that g = 2b(N − 2)=N is the parameter for the holding time for one
infected individual (until the number of infected increases to 2 infected individuals) and that
322 Bayesian Inference for Stochastic Processes
holding time has an exponential distribution. Suppose that b = 3 and N = 6; then g = 4. Thus,
I will generate 16 holding times with parameter g = 4 and use those to estimate g and,
consequently, b = 3g=4. The main parameters of interest are b, the contact rate; g, the
parameter of the exponential distribution for the holding time of one infected individual; and
E(HT1), the average holding time for one infected individual. Bayesian inferences are based
on WinBUGS Code 7.10, which is executed with 35,000 observations for the simulation
and a burn-in of 5,000:
HT1[i]~dexp(gamma)}
beta<-3*gamma/4
EFT1<-1/gamma
}
# the following times were generated with an exponential distribution
with parameter 4
list(
HT1 = c(
0.3804,0.03817,0.1017,0.3212,0.2032,
0.4066,0.3085,0.4867,0.2681,0.07279,
0.1096,0.04133,0.5914,0.2417,0.1273,
0.04811))
list(gamma=4)
The values of the parameters used to generate the holding times in the list statement of
WinBUGS Code 7.11 are N = 6, g = 4, and b = 3, and these values should be compared to the
corresponding posterior means appearing in Table 7.11, the posterior analysis for the epi-
demic model. For example, the posterior mean of g is 4.272 with a 95% credible interval of
(2.452,6.621), implying informally that the generated holding times were indeed distributed
as an exponential with parameter g = 4. Note that the average holding time for one infected
individual is .2496 days as estimated by the posterior mean.
TABLE 7.11
Posterior Analysis for the SI Epidemic Model
Parameter Mean SD Error 2 1/2 Median 97 1/2
b 3.204 0.8015 0.004305 1.839 3.131 4.966
g 4.272 1.069 0.00574 2.452 4.174 6.621
E(HT1) .2496 .06625 .000362 .151 .2396 .4078
Bayesian Inference 323
Consider the example presented on pages 308 and 309 of Allen3 with b = 2, N = 100,
and g + b = 1. Our goal is to estimate b, (b + g), and R0 = b − (b + g). Note that for one
infected individual, the holding time (until a new infection) is (b=N)(N − 1) + (b + g) = 2:98
and the holding time for a population with two infected people is (2b=N)(N − 2) + 2(b + g) =
5:92.
Using the values l1 = 2:98 and l2 = 5:92 for the parameters of the exponential distribution
for the holding times for one and two infected individuals, 17 observations are generated
for both and labeled as HT1 and HT2, respectively. These holding times are in the list
statement of WinBUGS Code 7.11, which is the Bayesian analysis executed with 45,000
observations for the simulation and 5,000 for the burn-in:
WinBUGS Code 7.11
model;
{
lamda1~dgamma(.001,.001)
lamda2~dgamma(.001,.001)
for( i in 1:18){
HT1[i]~dexp(lamda1)
HT2[i]~dexp(lamda2)}
beta<-(lamda1-1)/.99
delta<-(lamda2-1.96*beta)/2
R<-beta-delta
S<-step(R)
p10<-delta/(delta+beta*.99)
}
324 Bayesian Inference for Stochastic Processes
list(
HT1 = c(
0.3496,0.9303,0.6686,0.7489,0.1625,
0.2897,0.06194,0.3293,0.1065,0.04272,
0.07717,0.2257,0.3087,0.004282,0.0615,
0.5061,0.1497,0.3919),
HT2 = c(
0.3002,0.01733,0.3756,0.02314,0.2873,
0.1072,0.2551,0.474,0.1629,0.1206,
0.4864,0.1873,0.01003,0.01907,0.3545,
0.2151,0.03929,0.007648)))
list(lamda1=2.98,lamda2=5.92)
The posterior analysis is reported in Table 7.12. One can see the effect of the data, the
holding time on the estimation of the parameters. For example, the value of b + g used to
generate the holding times is 1, but the posterior mean of this parameter is 0.3112 with a
95% credible interval (−1.696,2.224), which does indeed include 1. Also, the value of b was
set to 2 for generating the holding times; however, its posterior mean is 2.346 with a 95%
credible interval (0.0035,2.284), which does include the value 2.
Consider
the probability that the epidemic will change from one to zero infected person. It is seen that
its posterior mean is .06774 and its posterior median is .1262, implying skewness in this
posterior distribution.
TABLE 7.12
Posterior Analysis for an SIS Epidemic
Parameter Mean SD Error 2 1/2 Median 97 1/2
R=b−d 2.035 1.681 0.00784 −0.9977 1.935 5.607
Pr(R > 0) .8947 .3069 .001435 0 1 1
b 2.346 0.789 0.003505 0.9849 2.284 4.057
d =b+g 0.3112 0.9907 0.004777 −1.696 0.3269 2.224
l1 3.323 .7811 .00347 1.975 3.261 5.017
l2 5.221 1.237 .005924 3.091 5.111 7.93
p10 .06774 .392 .002323 −.8665 .1262 .6561
Bayesian Inference 325
which leads to the transition probabilities of the embedded chain. Next to be introduced is
the Kolmogorov forward and backward system of differential equations involving the
transition rate matrix Q and the derivatives of the transition probability function. The
solution to this system is the transition probability function P(t). It is demonstrated how one
may use R and the exponential function exp(tQ) to compute the transition probability
function. Next it is shown how to compute the stationary distribution (if it exists) by solving
a system of equation involving the transition rates of the infinitesimal rate matrix Q.
In Section 7.4, a CTMC with an absorbing state is considered, and this is demonstrated
with a liver disease process and R is used to determine the average time to absorption from
a transient state of the chain. Also explained are the concepts of time reversibility and global
stability, which depends on the stationary distribution of the chain.
Section 7.5 introduces several biological examples including three versions of DNA
evolution. The first to be considered is the simplest model of DNA evolution, called the
Jukes–Cantor model. One of the holding time parameters is estimated using WinBUGS
Code 7.1 and the posterior reported in Table 7.1. Also presented is a test of hypothesis
involving the holding time parameter and a derivation of the predictive density of a future
holding time. The Kimura model is a generalization of the Jukes–Cantor model and allows
one to distinguish between transversions and transcriptions of DNA substitutions. A
Bayesian test of hypothesis investigates if the Kimura model reduces to the Juke–Cantor
model, which is followed by an examination of the Felsenstein–Churchill model, which
generalizes the Kimura model. A Bayesian analysis is conducted that estimates the alpha
parameter of the generalization. WinBUGS Code 7.3 is executed to estimate alpha, and the
posterior analysis is reported in Table 7.7. Lastly considered is the DNA evolution model
referred to as the Hasegawa, Kishino, and Yano model, and a Bayesian test that the model
reduces to the Felsenstein–Churchill model is performed.
Section 7.5.2 is regarding an important class of CTMCs, namely, birth and death
processes. Its stationary distribution corresponding to the infinitesimal rate matrix Q
given by Equation 7.74 is explained, and this is followed by an example with five
states determined by the Q matrix in Equation 7.80. The Bayesian analysis depends on the
holding times generated with an exponential distribution with known parameters. Using
45,000 observations for the simulation and a burn-in of 5,000, WInBUGS Code 7.5 is executed
with the prior information defined as a noninformative gamma distribution for the holding
time parameter. Posterior analysis results are reported in Table 7.5 and consist of the char-
acteristics of the posterior distribution of the four average extinction times.
A special case of the birth and death process is the random walk with instantaneous rate
matrix Q given by Equation 7.85 from which the stationary distribution is derived. The
process depends on two infinitesimal rates: (1) the one move to the right (corresponding
birth rate) and (2) the one move to the left (corresponding to the death rate). With known
values assigned to these two rates, the corresponding holding times with exponential
distributions are generated and appear in the list statement of WinBUGS Code 7.6 with the
posterior analysis reported in Table 7.6.
Another special birth and death process is the Yule process, which is a birth process
(no deaths are possible). This implies that all states are transient and that the stationary
distribution does not exist. As with the previous examples, a particular value is assigned
to the birth rate, which allows one to generate exponentially distributed holding times
(for the various states), which are in turn used for the Bayesian analysis reported in
Table 7.8.
A generalization of the birth and death process is the birth and death process with
immigration, which allows only an increase in the population; however, births and deaths
326 Bayesian Inference for Stochastic Processes
are possible. The Bayesian analysis is executed with WinBUGS Code 7.9 and the results
appear in Table 7.5.
Section 7.5.7, the last part of Section 7.5, introduces stochastic epidemic processes,
the so-called SI model, meaning two types of individuals are followed in the epidemic,
namely, the susceptibles and those that are infected. Assigning known values to the
infinitesimal rate matrix allows one to generate exponentially distributed observations for
the Bayesian analysis executed with WinBUGS Code 7.10, and the results are reported in
Table 7.11.
A generalization of this epidemic process to the so-called SIS model is the last example of
the chapter, and the analysis is similar to that for the SI model.
Bayesian inferences for continuous-type Markov chains have been an active area of
research, and the following references should be appealing to the students who want to
contribute to the literature on the subject.
In the area of reliability, see Cano, Moguerza, and Insua,9,10 while those interested in
Markov-modulated Poisson processes should read Fearnhead and Sherlock.11 Geweke,
Marshall, and Zarkin12 studied mobility indices for CTMCs, and Scott and Smyth13 empha-
sized Bayesian inferences applicable to Markov-modulated Poisson chains. With regard to
DNA evolutionary models, refer to Suchard, Weiss, and Sinsheimer.14 But for a more com-
prehensive list of work related to Bayesian techniques with CTMCs, see pages 103 and 104 of
Insua, Ruggeri, and Wiper.2
7.7 Exercises
1. Define the Markov property and the transition probability function for a CTMC.
2. a. Define time homogeneity for a CTMC.
b. Give an example of a CTMC which is time homogenous.
3. Define the memoryless property of a CTMC. What is the distribution of the
holding time of a CTMC?
4. What is the association between the infinitesimal transition rates and the transi-
tion probabilities of the embedded chain?
5. From the infinitesimal transition rates in Equation 7.8, derive the transition
probabilities in Equation 7.9.
6. The Kolmogorov forward equations are a system of differential equations
involving the derivative P0 (t) of the transition probability function. Show that the
solution to this system is the transition probability function.
7. Using R Code 7.1, compute the probability transition function P(t) as P(t) = exp(tQ),
where Q is the matrix of instantaneous transition rates.
8. If it exists, define the limiting distribution of a CTMC.
9. Under what conditions does the unique stationary distribution of a CTMC exist?
10. Based on the infinitesimal rate matrix Q in Equation 7.19, find the unique sta-
tionary distribution given by Equation 7.14. R Code 7.2 should be employed to
find the stationary distribution.
Bayesian Inference 327
11. Use R Code 7.3 with the matrix Q specified by Equation 7.24 with state 3 (death) as
an absorbing state and starting in state 1 (cirrhosis of the liver), compute the mean
time to death.
12. Define time reversibility of a CTMC. Consider the three-state chain with proba-
bility transition matrix P of the embedded chain:
a. What is the corresponding Q matrix?
b. Is the process time reversible? Why? Explain.
13. Based on the Q matrix in Equation 7.32 of the Jukes–Cantor DNA evolution
model, derive the corresponding probability transition function.
14. Execute WinBUGS Code 7.1 with 45,000 observations for the simulation and a
burn-in of 5,000.
a. What is the posterior mean of l?
b. What is the posterior mean of μ?
c. Is this process time reversible? Why?
d. Which posterior distributions appear as symmetric about the posterior
mean?
15. Refer to the Jukes–Cantor model and test the hypothesis H: l = 1=6 versus
A: l ≠ 1=6. Show that the posterior probability of the null hypothesis is .7356.
16. Derive the predictive density in Equation 7.47 of t(n + 1) for the holding time with
exponential parameter l.
17. Refer to the Felsenstein–Churchill model with the instantaneous rate matrix Q of
Equation 7.61.
a. What is its stationary distribution?
b. What is its probability transition function matrix P(t)?
18. Refer to the Felsenstein–Churchill model for DNA evolution with matrix Q given
by Equation 7.61. In order to estimate the parameter a of the matrix Q, execute
WinBUGS Code 7.3 with 35,000 observations for the simulation and 5,000 for the
burn-in. Your results should be similar to those reported in Table 7.4.
a. What is the posterior median of a?
b. Is the posterior distribution of a symmetric about its posterior mean?
c. What is the 95% credible interval for a?
19. Refer to the birth and death process with infinitesimal rate matrix Q given by
Equation 7.74 and derive the corresponding stationary distribution in Equation
7.78.
20. Refer to the birth and death process with matrix Q given by Equation 7.80
and with states 0, 1, 2, 3, and 4, where μ1 = 2, l1 = 1, μ2 = 3, l2 = 2, μ3 = 4, and
l4 = 3.
a. With WinBUGS Code 7.5, verify the posterior analysis in Table 7.6.
b. What are the ai , i = 1, 2, 3, in the posterior analysis?
c. Assume the process is in state 3. What is the posterior mean of the average
time to extinction?
d. Is the posterior distribution of a3 symmetric about its posterior mean? Why?
328 Bayesian Inference for Stochastic Processes
21. For the birth and death process with l = 2 and μ = 5, execute WinBUGS Code 7.7
and verify the posterior analysis in Table 7.7.
a. What are the posterior mean and median of P(l > μ).
b. Display the posterior density of P(l > μ).
c. What does the posterior mean of P(l > μ) imply about this birth and death
process?
22. For the Yule process with Q matrix given by Equation 7.86, show that all states are
transient and that the stationary distribution does not exist.
23. For the Yule process with the infinitesimal rate matrix of Equation 7.86, let the
holding time parameter be l = 2. The holding time observations are in the list
statement of WinBUGS Code 7.9.
a. What is the posterior mean of l?
b. What prior distribution is used for l?
c. Name the posterior distribution of l.
d. Does the posterior analysis suggest l ¼ 2? Why?
24. For the birth and death process with immigration and the Q matrix of Equation
7.89, let μ = 1, n = 1=3, and l = 1 be the assigned values for the death, immigra-
tion, and birth rates, respectively. These values are used to generate the expo-
nentially distributed holding times appearing in the list statement of WinBUGS
Code 7.9 Execute WinBUGS Code 7.9.
a. What is the posterior mean of the immigration rate n?
b. What is the posterior median of the average number of immigrants per day?
c. Do you believe l = 1?
d. Display the posterior density of μ.
e. Specify the prior distribution for the three rates.
25. Refer to the SI epidemic with the Q matrix of Equation 7.91 for the number of
infections. Execute WinBUGS Code 7.10.
a. What is the posterior mean of b?
b. For this epidemic, what is the interpretation of b?
c. What is the average holding time for one infected individual?
d. What prior distributions did you specify for b?
References
1. Dobrow, R. P. 2016. Introduction to Stochastic Processes with R. New York: John Wiley & Sons.
2. Insua, D. R., Ruggeri, F., and Wiper, M. P. 2012. Bayesian Analysis of Stochastic Process Models. New
York: John Wiley & Sons.
3. Allen, L. J. S. 2011. An Introduction to Stochastic Processes with Applications to Biology, Second Edition.
Boca Raton, FL: Taylor & Francis.
4. Bartolomeo, P., Trerotoli, P., and Serio, G. 2011. Progression of liver cirrhosis to HCC: An
application of hidden Markov model, BMC Medical Research Methodology 11(380):1–8.
Bayesian Inference 329
5. Lee, P. M. 1997. Bayesian Statistics: An Introduction, Second Edition. New York: John Wiley & Sons.
6. Kimura, M. 1980. A simple method for estimating evolutionary rates of base substitution of
comprehensive studies of nucleotide sequences, Journal of Molecular Evolution 16(20):111–120.
7. Felsenstein, J., and Churchill, G. A. 1996. A hidden Markov model approach variation among sites
in rate of evolution, Molecular Biology Evolution 13:93–101.
8. Hasegawa, M., Kishino, H., and Yano, T. 1980. Dating of human ape splitting by a molecular clock
of mitochondrial DNA, Journal of Molecular Evolution 22(2):160–174.
9. Cano, J., Moguerza, J. M., and Insua, D. R. 2010. Bayesian reliability, availability, and maintain-
ability analysis for hardware systems described through continuous time Markov chains.
Technometrics 52:324–334.
10. Cano, J., Moguerza, J., and Insua, R. 2011. Bayesian analysis for semi Markov processes with
application to reliability and maintenance, Technical Report. Madrid: Universidad Rey Juan Carlos.
11. Fearnhead, P., and Sherlock, C. 2009. An exact Gibbs sampler for the Markov-modulated Poisson
process, Journal of the Royal Statistical Society B 68:767–784.
12. Geweke, J., Marshall, R., and Zarkin, G. 1986. Mobility indices in continuous time Markov chains.
Econometrica 54:1407–1423.
13. Scott, S. L., and Smyth, P. 2003. The Markov modulated Poisson process cascade with application
to web traffic modeling, In Bernardo, J. M., Bayarri, M. J., Berger, J. O. et al. (Eds) Bayesian Statistics
7 (pp. 1–10). Oxford: Oxford University Press.
14. Suchard, M., Weiss, R., and Sinsheimer, J. 2001. Bayesian selection of continuous time Markov
chain evolutionary models, Molecular and Evolutionary Biology 18:1001–1013.
[Link]
8
Bayesian Inferences for Normal Processes
8.1 Introduction
Previous chapters have employed Bayesian inferences for stochastic processes with discrete
time and discrete state space, and in this chapter, inferential techniques will be applied to
the most general case where time and state space are continuous. Bayesian inferential
methods of estimation, testing hypotheses, and forecasting will reveal interesting aspects of
stochastic processes that are unique. Remember that the standard course in stochastic
processes does not emphasize inference but instead focuses solely on the probabilistic
properties of the model.
Subjects to be presented are the properties of the Wiener process (the Brownian motion)
and the Bayesian estimation of its variance and covariance function. The Wiener process
and the random walk will be generalized to a continuous state space, and Bayesian testing
methods will be demonstrated with the parameters of the random walk.
The Brownian motion is a special case of normal stochastic processes where the joint
distribution of the variables of model has a mean vector and variance covariance as
parameters. The Bayesian approach uses the inverse normal–Wishart distribution as a prior
for the mean vector and precision matrix, with the result that the marginal posterior dis-
tribution of the mean vector has a multivariate t distribution. This in turn provides easily
implemented Bayesian techniques of inference.
Certain mapping or transformations of the Wiener process are of interest and have many
applications. Translations, reflections, rescaling, and inversions of the Brownian motion
will be presented and lead to such concepts as stopping times, first hitting times, and
determining the zeros of the Wiener process. Such mapping applied to the Brownian
motion produce other types of models that are amenable to Bayesian inferences and will be
implemented with WinBUGS and R.
Certain variations of the Brownian motion will be studied including the Brownian motion
with drift, the Brownian bridge, and the Ornstein–Uhlenbeck process. Bayesian inferences
are especially interesting when applied to examples from finance such as stock options and
derivatives.
The chapter is concluded with the broad subject of martingales which is a generalization
of normal processes, including the Brownian motion. Martingales offer more complex
stochastic processes that are a challenge to the Bayesian.
The reader is referred to Chapter 8 of Dobrow,1 and Chapter 6 of Insua, Ruggeri, and
Wiper2 for information that is germane to this chapter. For a good introduction to WinBUGS
and Bayesian inference see Ntzoufras.3
331
332 Bayesian Inference for Stochastic Processes
where f (y, t) represents the number of particles per unit volume at position y at time t. It can
be shown that the solution to Equation 8.1 is
pffiffiffiffiffiffiffi 2
f ðy, tÞ = 1= 2πt e−y =2t ; (8.2)
that is, the solution is the density of a normal distribution with mean 0 and variance t. Thus,
the process called the Brownian motion is a continuous-time continuous-state stochastic
process. Wiener4 investigated the properties of this process; thus, the model is sometimes
called a Wiener process, and he showed that the sample functions of the process are con-
tinuous almost everywhere, but that the process is not differentiable at any time point. The
Weiner process fB(t), t > 0g or standard Brownian motion is defined as follows:
a. For all t > 0, B(t) has a normal distribution with mean zero and variance t.
b. It has stationary increments, namely, letting s, t > 0, B(t + s) − B(s) has the same
distribution as B(t).
c. The process has independent increments; that is, for 0 ≤ q < r ≤ s < t, B(t) − B(s)
and B(r) − B(q) are independent.
d. The function B(t) is continuous with probability of 1.
Note that we use the notation that B(t) ~ N(0,t), and recall that the Wiener process can be
interpreted as the movement of a particle that diffuses randomly along a line, where at time,pffiffi
the particle location is normally distributed about the line with standard deviation t.
Wiener’s fundamental contribution to our knowledge was to prove the existence of such a
process as the Brownian motion. Bayesian inferences will be based on independent incre-
ments, because each increment B(t) − B(s) has a normal distribution with mean 0 and var-
iance t − s; for s < t, it is easy to write down the likelihood function. Independent increments
make it easier to evaluate complicated probabilities involving Brownian motion. For
example, consider finding the distribution of B(s) + B(t) when 0 < s < t.
Note that
Since 2B(s) and B(t) − B(s) are independent normal random variables, it follows that
and
Now consider the problem: Suppose the position of a particle follows a Wiener process,
and then if the position of a particle is at 2 at time 3, find the probability that it is at most 4 at
time 7.
In symbols,
> pnorm(4,0,2)
[1] 0.9772499.
The preceding formulation of the Brownian motion is called standard Brownian motion;
however, we will be concerned with the more general form fB(t), t > 0g, where B(t) e N(0, s2 t).
The goal of Bayesian inference for such a process is to estimate s2 , to test hypotheses about s2,
and to predict future values of B(t). R provides a way to simulate Brownian motion variables
B(ti ), ti = it=n, where i = 1, 2, :::, n and n is a positive integer. Now let
where Z(i) e N(0, ti − ti−1 ) = N(0, t=n) and is independent of B(ti−1 ), which leads to the recur-
sive relation involving X(i), i = 1, 2, :::, n of independent N(0,1) random variables. Thus,
pffiffiffiffiffiffiffiffiffiffiffi
Bðti Þ = Bðti−1 Þ + ðt=nÞXðiÞ, i = 1, 2, ::, n
or
" # (8.8)
pffiffiffiffiffiffiffiffiffiffiffi Xi=n
Bðti Þ = ðt=nÞ X ði Þ :
i=1
R Code 8.1 code shows how to generate standard Brownian motion variables over the
interval [0,50], with adjacent observations one unit apart (Figure 8.1):
334 Bayesian Inference for Stochastic Processes
10
5
x
0
–5
–10
0 10 20 30 40 50
t
FIGURE 8.1
Fifty standard Brownian motion variables over [0,50].
R Code 8.1
t<-1:50
sig2<-1
x<-rnorm(n=length(t)-1,sd=sqrt(sig2))
x<-c(0,cumsum(x. t))
plot(t,x,type= "1", ylim=c(-10,10)
In the preceding code, sig2 is the variance of process which is one for the standard
Brownian motion, and the corresponding standard deviation is listed as sd. Brownian
motion-generated values are designated by the vector x, and the plot command has an
abscissa range from 1 to 50 with time units of length one and with the ordinate range from
−10 to 10.
R Code 8.2 generates 30 Wiener variables with s2 = 4.
R Code 8.2
t<-0:50
sig2<-4
x<-rnorm(n=length(t)-1,sd=sqrt(sig2))
x<-c(0,cumsum(x. t))
plot(t,x,type= "1", ylim=c(-8,8))
where the B(i) are the 30 Wiener values generated with R Code 8.2; then the X(i) are the
independent increments and are distributed as
XðiÞ e Bð2iÞ − Bð2i − 1Þ e Bð1Þ e N 0, s2 : (8.10)
The 15 observed increments are in the list statement of WinBUGS Code 8.1. The Bayesian
analysis is executed with 45,000 observations and a burn-in of 5,000. Noninformative prior
distributions are assigned to μ and t.
list( X=c(-4.4847,-.8083,-.14687,1.3305,.11646,-1.5493,
-1.344,1.91076,.87553,-.06959,1.03599,.4367,
.9903,-1.2077,2.63931))
list(tau=.24,mu=0)
Table 8.1 reports the analysis for the Brownian motion with 30 observations displayed in
Figure 8.2.
The parameter μ is the mean of Brownian motion and should be zero. Is there sufficient
evidence to declare that μ = 0? The 95% credible interval for μ is (−.9842,.9512) and implies
that indeed μ = 0.
TABLE 8.1
Posterior Analysis for Wiener Process
Parameter Mean SD Error 2 1/2 Median 97 1/2
2 3.497 1.557 .00878 1.609 3.148 7.458
s
t .3333 .1245 .000727 .1341 .3177 .6215
μ −.0204 .4877 .002738 −.9824 .01989 .9512
336 Bayesian Inference for Stochastic Processes
5
0
x
–5
0 5 10 15 20 25 30
t
FIGURE 8.2
Brownian motion with n = 30.
The estimate of s2 is 3.497 with the posterior mean. Remember that the value s2 = 4 was
used to generate the Brownian motion values, and this estimate appears reasonable with a
95% credible interval (1.609,7.458).
Let us test in a formal Bayesian way the null hypothesis
Recall from pages 126–128 of Lee5 that the posterior probability of the null hypothesis is
where
with
ð∞
f1 ðxÞ = r1 ðμÞf ðxjμÞdμ, (8.14)
−∞
r1 ðμÞ = 1, μ ∈ R,
and
n h n=2 io −n=2
f ðxjμ = 0Þ = Gðn=2Þ= ð2πÞn=2 ðn − 1Þs2 1 + nðxÞ2 =ðn − 1Þs2
Bayesian Inferences for Normal Processes 337
and
n h n=2 io −n=2
f ðxjμÞ = Gðn=2Þ= ð2πÞn=2 ðn − 1Þs2 1 + nðx − μÞ2 =ðn − 1Þs2
and
n n=2 opffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi qffiffiffiffiffiffiffiffiffi2
f1 ðxÞ = Gððn − 1Þ=2Þ= ð2πÞ ðn − 1Þs2 ðn − 1Þπ= n=s , (8.15)
where x = (x(1), x(2), :::, x(n)) is the vector of observations appearing in the list statement
of WinBUGS Code 8.1.
Assuming π0 = π1 = 1=2 (the prior probability of the null hypothesis is the same as that of
the alternative), and computing the sample mean as x = −:057 and the sample variance as
s2 = 2:9632, it can be shown that f1 (x) = 0 and that r = 0; consequently, the posterior prob-
ability of the null hypothesis H is p0 = 1. The evidence implies that μ = 0 and that the
Brownian motion values generated by R Code 8.2 have the desired mean of 0.
Is the Wiener process a Markov process? If so, it should satisfy the Markov property of a
stochastic process {X(t), t ≥ 0}, which is defined as follows: Select time points s, t ≥ 0 and real
state y, then the process is Markov if
In addition, the process is time homogenous if the probability in Equation 8.16 does not
depend on s; that is,
One intriguing property of the Wiener process is that its realizations are continuous but
nowhere differentiable. These two properties can be demonstrated with the aid of measure
theory, and pages 181–184 of Feller6 provide a convincing account.
Given realizations from a stochastic process, can one show statistically that it is a Markov
satisfying Equation 8.16? This is left as an exercise at the end of the chapter.
t = 0, 1, 2::: with S(0) = 0, and then the process {S(t), t = 0, 1, 2, …} is a symmetric random walk
with moments E[S(t)] = 0 and Var[S(t)] = t for t = 0, 1, 2, …. Notice that for large t, S(t) is
approximately normally distributed and that the process has independent increments. To see
the latter assertion, note that for 0 < q < r < s < t,
338 Bayesian Inference for Stochastic Processes
and because the Y(t) are independent, the two increments are also independent. In addition,
the process has the time homogeneity property, namely, that the distribution of S(t) − S(s) is
that of S(t − s), and the process has stationary increments. The process represented by
Equation 8.18 is in discrete time; therefore, the pertinent question is how is it extended to
continuous time. One way is to base the generalization with the function as follows:
and ½t is the floor function defined as the largest integer less than or equal to t. If k is a positive
integer with k ≤ t ≤ k + 1, then S(t) is the linear interpretation between the two points (k, S(k))
and (k + 1, S(K + 1)). Also, it follows from Equation 8.19,
E½SðtÞ = 0
and
(8.20)
VarfSð½tÞ + Xð½t + 1Þðt − ½tÞg = VarSð½tÞ + ðt − ½tÞ2 VarðXð½t + 1ÞÞ
= ½t + ðt − ½tÞ2 ≈ t, 0 ≤ t − ½ t < 1
Now it should be stressed that the development of a symmetric random walk can be
based on any i.i.d. sequence Y(1), Y(2),… with mean 0 and variance 1, and let
X
i=n
SðnÞ = YðiÞ:
i=1
and
pffiffiffi pffiffiffi
lim g S tn= n = lim max SðtnÞ= n
n!∞ n!∞,0<t<1
pffiffiffi (8.21)
= lim max SðkÞ= n = gðBðtÞÞ,
n!∞,0<k<n
where g is the maximum value function and {B(t), t > 0} is the Brownian motion. The result
(Equation 8.21) is the so-called invariance principle.
Of course, the function g can be any continuous function.
Bayesian Inferences for Normal Processes 339
The following R Code computes the maximum of a symmetric random walk (Equation
8.19) using 100 replications where the generating process is the sequence of binary random
variables with values of +1 and −1 with equal probability:
n<-50
sim<-replicate(50,
max(cumsum(sample(c(-1,1),n, replace =T))))
max(sim)
mean(sim)
sd(sim)
s<-seq(1,50,1)
plot(s,sim)
where the sample mean and standard deviation are x = 5:56 and s2 = 4:35, respectively, and
the maximum is max = 19. Refer to Figure 8.3, which is a plot of the random walk values
versus time.
The generated random walk values are only approximately distributed as the Brownian
motion and should have a mean of 0 and standard deviation of 1. Do the generated values
support the hypothesis that they are the realization from a Brownian motion process? The
answer to this question is left as an exercise for the student.
15
10
sim
5
0
0 10 20 30 40 50
FIGURE 8.3
Symmetric random walk.
340 Bayesian Inference for Stochastic Processes
If Tv is thought of as the stopping time, then the process begins with the translated
process at time v.
For the standard Brownian motion at time t, the process is equally likely to be above zero
as to be below zero. Assume v > 0, and then for the process beginning at time v, at any time
t > v, the process is equally likely to be above the horizontal line v unit above the line y = 0.
In symbols
ð∞ pffiffiffiffiffiffiffi
P½Tv < t = 2P½BðtÞ > v = 2 1= 2πt exp − x2 =2t dt
v
(8.24)
ð∞ pffiffiffiffiffiffiffi
=2 1= 2πt exp −x2 =2 dx :
pffi
v= t
There are some surprising aspect to the hitting time Tv . For example,
= 2ð1=2Þ = 1;
For this general process, it is easily shown that the mean and variance of the first hitting
time to target n are
EðTv Þ = v=μ
and (8.27)
VarðTv Þ = vs2 =μ3 ,
respectively.
Based on a realization of the general Brownian motion with unknown mean and variance,
the goal of the Bayesian approach will be to estimate these two parameters as well as the
preceding moments and to test hypotheses about μ and s2 .
R Code 8.3 generates 1000 values of the Brownian motion with a mean of ½ and a
standard deviation of 1 and target of 10 over the interval (0,80] with a time interval of length
.016 units. The objective is to estimate the average time to hit the value 10.
R Code 8.3
mu<-1/2
sig<-1
v<-10
simlist<-numeric(1000)
for( i in 1:1000){
t<-80
n<-5000
bm<-c(0, cumsum(rnorm (n,0,sqrt(t/n))))
xproc<-mu*seq(0,t,t/n)+sig*bm
simlist[i]<-which(xproc >= v)*(t/n)
mean(simlist)
var(simlist)
}
The command mean(simlist) computes the average time to hit the target 10, while the
command var(simlist) computes the sample variance of the time to hit the target with the
result mean(simlist) = 19.96 and var(simlist) = 73.128.
The first 30 values of xproc of the Brownian motion values with mean ½ and variance 1
are reported in the following. Using Bayesian methods, these values will be used to estimate
the mean and variance of the Brownian motion:
0
–2
–4
bm
–6
–8
–10
–12
0 20 40 60 80
u
FIGURE 8.4
Simulation of 100 Brownian motions for hitting time to 10.
Based on 5000 xproc values, we have mean(xproc) = 15.884 and var(xproc) = 146.556.
I generate Figure 8.4 with the following R command:
In order to estimate μ and s2 , the Bayesian analysis will be based on the 15 independent
increments corresponding to the first 30 observations of xproc generated with R Code 8.3.
The increments are i.i.d normally distributed with mean 0 and variance s2 . Based on
the 15 increments, I computed the sample mean as x = −:02078 and sample variance as
s2 = :0327212. This seems reasonable because the actual theoretical variance of the inde-
pendent increments is .016.
Using noninformative prior distributions for μ and t, namely, μ e N(0, :001) and t e gamma
(:001,:001), respectively, the Bayesian analysis is executed with WinBUGS Code 8.2 using
35,000 observations for the simulation and a burn-in of 5,000. The list statement of
WinBUGS Code 8.2 includes the 15 increments.
vu<-mu+.5
sigmasq<-1/tau
list(X=c(.02877,-.17274,-.14443,-.21777,.0249,-.13757,.1533,.15497,
-.000181,-.10597,.182633, -.135482,-.01353,.20413,.09401))
list(mu=0,tau=1)
The posterior analysis for the hitting time is reported in Table 8.2. Note that s2o is the
variance of Brownian motion and s2 is the variance of the increments. Also, n is the mean of
Brownian motion, but μ is the mean of the corresponding increments.
The actual average time to hitting target level 10 is 20, which should be compared to the
posterior mean of 20.37, implying excellent agreement with the true value. It is a different
story with the variance of the hitting time which is estimated as 51.13 with the posterior
median. The actual value of the variance is 80, and the difference can be attributed to the fact
that the estimate is based on the first 30 Brownian motion values (or the 15 corresponding
increments). The actual value of the mean is 1/2, which is estimated as .4942 with the pos-
terior mean, which is why the posterior mean of E(T10 ) is very close to the actual value of 20.
The 95% credible interval for μ is (−.08468,.0738), which implies that informally, the μ = 0,
but on the other hand, the 95% credible interval for s2 is (.0108,.05005), which does include
the value s2 = 0:016.
I would expect that a formal Bayesian test of the hypothesis s2 = :016 would not be
rejected in favor of the alternative s2 ≠ :016.
If one is testing hypotheses, I would expect to not reject the hypothesis that n = 1=2 versus
the alternative n ≠ 1=2 (or equivalently μ = 0 versus μ ≠ 0), and I would expect not to reject
the hypothesis that s2 = :016 in favor of the alternative that s2 ≠ :016.
s2o is the variance of Brownian motion which is 1, and the posterior analysis gives a 95%
credible interval of (0.6753,3.129), implying that the hypothesis that the null hypothesis
s2o = 1 would not be rejected.
Consider a test of the null hypothesis:
where s2 is the variance of each increment. Using the precision in lieu of the variance,
Equation 8.28 is equivalent to testing
TABLE 8.2
Posterior Analysis for Hitting Time to Target 10
Parameter Mean SD Error 2 1/2 Median 97 1/2
E(T10 ) 20.37 1.69 .009435 17.43 20.23 24.08
Var(T10 ) 127.8 76.13 .4626 51.13 108.6 315.7
μ −.00583 .03997 .000224 −.08468 −.00579 .0738
s2 .02349 .01046 .000058 .0108 .02114 .05009
t 49.63 18.68 0.1084 19.96 47.3 92.55
n .4942 .03997 .000224 .4153 .4942 .5738
s2o 1.468 0.6529 0.00394 0.6753 1.321 3.129
344 Bayesian Inference for Stochastic Processes
where
and
h pffiffiffii
f ðxjtÞ = tðn−1Þ=2 =ð2πÞðn−1Þ=2 n exp −tðn − 1Þs2 =2 (8.32)
and
ð∞
f1 ðxÞ = f ðxjtÞr1 ðtÞdt : (8.33)
0
Suppose the prior probabilities of the null and alternative hypotheses are π0 = π1 = 1=2,
then knowing that n = 15 and s2 = :0232717, there is sufficient information to calculate r = 0
and the posterior probability of the null hypothesis as p0 = 1. Thus, there is insufficient
information to reject the null hypothesis that t = 62:5, and of course, this was implied by the
95% credible interval for t reported in Table 8.2.
The student will be asked to derive the predictive distribution of future Brownian motion
values.
pffiffiffiffiffiffi
zr,t = ð2=πÞarccos r=t , 0 ≤ r < t: (8.35)
In terms of the Brownian motion, B(t) = 0 for some t ∈ (0, e) with probability of 1. Over the
interval (0, 1) and based on Equation 8.35, the distribution function is
pffiffi
FðtÞ = ð2=πÞarccos r, 0<t<1
The random variable Lt , the time to the last 0, is now shown to be related to an interesting
experiment in coin tossing with two players 1 and 2. If the coins lands heads, player 1 pays
$1, and if tails occurs, player 2 pays player 1 $1. If the coin is flipped a large number of times,
when would you expect the players are even?
R Code 8.4 code generates 10,000 tosses of a fair coin, and the histogram is the last time
the two players are even. Of course, this is related to the number of zeros occurring over a
given time interval.
R Code 8.4
trials<-10000
simlist<-numeric(trials)
for ( i in 1:trials){
rw<-c(0, cumsum (sample(c(-1,1), (trials-1),
replace = T)))
simlist[i]<-tail(which(rw==0),1)
}
hist (simlist)
This is interesting in that it is more likely that the two players are even with a fewer (closer
to 1) number of tosses and a larger number (nearer to 10,000). Is this what you would
expect? Why does the histogram appear similar to the arcsin distribution (Equation 8.38)?
What type of inferences should be made for the coin-tossing experiment?
346 Bayesian Inference for Stochastic Processes
Consider the Bayesian estimation of the random walk which should approximately
follow the Brownian motion process fB(t), t > 0g, where E½B(t) = 0 and Var½B(t) = t. Note
that the increments X(i) = B(i + 1) − B(i), i = 1, 2, …, are i.i.d. and normally distributed with
mean of 0 and variance of 1.
Figure 8.5 is the graph of the random walk values versus time.
Forty random walk values are listed in the following and will be the basis for Bayesian
inferences about the mean and variance of the increment process:
rw = (−4, −5, −6, −5, −4, −3, −2, −3, −4, −3, −4, −5, −6, −5, −4, −3, −4, −5, −4, −5,
−4, −3, −2, −1, −2, −3, −4, −3, −2, −3, −4, −3, −4, −3, −2, −1, 0, 1, 2, 3)
X = (−1,1,1,−1,1,−1,1,1,−1,−1,1,1,−1,1,−1,1,1,1,1,1)
FIGURE 8.5
Random walk for coin-tossing experiment.
Bayesian Inferences for Normal Processes 347
TABLE 8.3
Posterior Analysis for Coin-Tossing Experiment
Parameter Mean SD Error 2 1/2 Median 97 1/2
μ .299 .2334 .001394 −.1609 .2989 .7621
s2 1.072 0.3925 0.002341 0.5537 0.9948 2.05
t 1.043 0.3387 0.001977 0.4877 1.005 1.806
where s > 0, μ is any real number, and fB(t), t > 0g is the standard Brownian motion. It can
be demonstrated that Equation 8.39 is a normal process with mean μt and variance s2 and
that the process has independent and stationary increments ½X(t + s) − X(t) with mean μs
and variance s2 s, where s, t > 0.
Consider the following application of the Brownian motion with a drift explained on pages
346–347 of Dobrow,1 where the objective is to estimate the home field advantage by
determining the probability that the home team leads by y points after a fraction t (0 < t < 1)
of the game is played. To evaluate this probability, let X(t) denote the difference in scores
between the home time and the visiting team after 100t% of the game is played. This
approach is presented by Stern7 with a Brownian motion process fX(t), 0 < t < 1g } where μ
denotes the magnitude of the home field advantage.
348 Bayesian Inference for Stochastic Processes
The probability that the home team wins, conditional on the fact that they have a y point
lead at time t, is
R Code 8.5
t <- seq(0,1,.01) # time
sig2 <- 15.82*15.82
## first, simulate a set of random deviates
x <- rnorm(n = length(t) - .01, sd = sqrt(sig2))
## now compute their cumulative sum
x <- (c(0, cumsum(x)))
y<-x+4.87
The 100 Brownian motion values with drift appear in the following.
{
mu~dnorm(0,.001)
tau~dgamma(.001,.001)
for ( i in 1:50){
X[i]~dnorm(mu,tau)
}
# mu is the mean of the independent increments
#sigmasq is the variance of the increments
sigmasq<-1/tau
y<-0
t<-.5
d<-sqrt(sigmasq)*sqrt(1-t)
a<-n/d
n<-sqrt(t)*(y+vu*(1-t))
#posterior probability of the lead time at time t and lead y.
probability<-step(y-m)
# vu is the mean of the original Brownian motion values
vu<-4.87+mu
m~dnorm(0,t)
}
list(X=c(7.905,16.035,1.5288,7.7472,6.8094,36.8066,
.386,-1.0249,-29.9257,7.047,-6.6081,9.9861,1.9598,
.6958,-1.6726,19.0165,23.6914,46.7164,9.6126,
-5.3584,2.9793,-3.432,-3.218,-10.0563,-7.2254,
-10.3726,21.7138,9.2199,3.8507,11.2905,-11.1,
-9.5426,-2.215,3.884,-17.5295,-17.1796,-9.6132,
-4.6995,-8.7003,32.4128,4.4762,-14.19,28.4822,
-16.8423,4.6145,9.3081,5.3556,9.5262,-8.3677,
5.2556))
list(mu=4.86,tau=.00428)
350 Bayesian Inference for Stochastic Processes
TABLE 8.4
Posterior Analysis Home Team Advantage: y = 0, t = .5
Parameter Mean SD Error 2 1/2 Median 97 1/2
μ 2.964 2.091 0.009762 −1.199 2.977 7.077
Prob .5025 .5 .001791 0 1 1
s2 220.7 46.54 0.2216 147.8 214.5 328.4
t .004725 .000955 .000045 .003045 .004661 .006766
n 7.834 2.091 0.009762 3.671 7.847 11.95
TABLE 8.5
Probabilities the Home Team Wins
Lead y
Time t 0 2 10
0 .62
.25 .61 .66 .84
.5 .59 .65 .87
.75 .56 .66 .92
.9 .54 .69 .98
1.0 1.0 1.0
The Bayesian analysis for the parameters of the home team advantage example appears in
Table 8.4. Note that the time is .5 (half way through the game) and the lead at this time is 0.
The parameter n is the mean of the original Brownian motion values generated by R Code
8.5, and s2 is the variance of the increments appearing in the list statement of WinBUGS
Code 8.4.
The posterior mean of the probability of winning the game half way through the game
when the teams are tied is .5025, with a standard deviation of .5 for the posterior distri-
bution of the probability.
The probabilities of the home team winning for a given time t and lead y is computed
directly using Equation 8.40 and is reported in Table 8.5. When y = 0 and time = .5, the value
computed is .59 compared to .5025 determined with Bayesian analysis executed with
WinBUGS Code 8.4. Why the difference in these two values? The reader will be asked to
answer this question in the exercises at the end of the chapter.
Notice that for a given time, the probability that the home time wins increases as the lead
increases, as it should.
versatility of the process. For example, with the geometric Brownian motion where the
example presented is from finance.
and moments
Var(ln(G(t)) = s2 t (8.44)
It is obvious that the mean of the process exhibits exponential growth with growth rate of
(μ + s2 =2).
The goal is to develop Bayesian inferences for the parameters of the geometric Brownian
motion using an example about stock prices.
Realizations for the geometric version are easily generated by transforming standard
Brownian motion.
It is often the case that the geometric process can be expressed as the product of random
multipliers. Let s, t ≥ 0 and consider the ratio
Because the underlying Wiener process fX(t), t > 0g has stationary independent incre-
ments, the ratios G(t)/G(0) and
Now let
Then this sequence consists of i.i.d. random variables, and an alternative representation of
the geometric process can be expressed as
The representation of the process as ratios or products (Equation 8.48) is often employed
when analyzing stock prices and options. See pages 352–356 of Dobrow1 for additional
insights into the geometric process.
Consider the following example of geometric Brownian motion with parameters μ = 1
and s2 = :5, then the corresponding Brownian motion with drift has mean μt and variance
s2 t, where 0 ≤ t ≤ 1. R Code 8.6 generates realizations from a geometric Brownian motion
process.
R Code 8.6
{
t <- seq(0,365,1) # time
sig2 <- 0.5
## first, simulate a set of random deviates
x <- rnorm(n = length(t) - 1, sd = sqrt(sig2))
## now compute their cumulative sum
x <- c(0, cumsum(x))
y<-x+.1 g<-.01*exp(y)}
The following y values are the Brownian motion values with drift parameter μ = 1 and
s = .5.
Using the 30 values, the corresponding 15 increments will be the foundation for the
Bayesian analysis.
Recall that the initial value of the geometric Brownian motion process is .001, which is
portrayed in Figure 8.6, and notice the explosive growth beginning at day 275. The geo-
metric Brownian motion values in the figure mimic the Brownian motion value with drift
depicted in Figure 8.7.
Using these 30 values, the corresponding 15 increments will allow one to estimate these
two parameters and to estimate the probability
150
100
y
50
0
FIGURE 8.6
Three geometric Brownian motion processes.
10
5
x
0
–5
FIGURE 8.7
Geometric Brownian motion.
354 Bayesian Inference for Stochastic Processes
where μ and s are estimated based on the increments. The Bayesian approach is to deter-
mine the posterior distribution of Equation 8.49, and it is executed by WinBUGS Code 8.4
with 35,000 observations for the simulation and 5,000 for the burn-in, where the main
parameter is prob in the WinBUGS Code.
The parameter mu is the mean of the increments, which hypothetically is 0. The variance
of each increment is designated by sigma in the code.
Note the noninformative prior distributions for μ, which is assigned a normal (0,.001)
distribution, and t, which is assigned a gamma (.001,.001) distribution.
for ( i in 1:15){
X[i]~dnorm(mu,tau)}
sigma<-1/tau
a<-exp(mu*281+sigma*6.92001681)
# prob is the probability (8.49)
prob<-step(6-a)
list(X=c(-.05001,.49098,.36946,-.64969,.14803,
-.43292,-.37262,-.51434,.21965,-.62951,
-.21283,-.54647,-.35664,-.01231,.11429))
list( mu=.1,tau=2)
The Bayesian analysis for the geometric Brownian motion example is reported in Table 8.6.
The main parameter of interest is the probability
where t = 281 and X(281) = 6.92 and is estimated as .944 with the posterior mean. Upon
inspection of Figure 8.6, does this appear as a reasonable estimate? It will be left to the
student to discuss this question.
TABLE 8.6
Posterior Distribution for Geometric Brownian Motion
Parameter Mean SD Error 2 1/2 Median 97 1/2
μ −.1628 .1053 .000591 −.3704 −.1627 .04698
Probability .9444 .2295 .001371 0 1 1
2 .1629 .07254 .000409 .07486 .1456 .3475
s
t 7.154 2.693 0.01562 2.878 6.818 13.34
Bayesian Inferences for Normal Processes 355
ð∞ ð∞
f ðyjxÞ = f ðyjμ, tÞf ðxjμ, tÞrðμ, tÞdμ dt, (8.50)
0 −∞
h i
f ðyjμ, tÞ = tm=2 =2πm=2 e−ðt=2Þ½mðμ−yÞ +ðm−1Þsy ,
2 2
(8.52)
Under these assumptions, it can be shown that the predictive density of y given x is
where
iðm+n−1=2Þ
ðm+n−1Þ=2
pffiffiffiffiffiffiffiffiffiffiffiffih 2 2
f1 ðyjxÞ = fGððm + n − 1Þ=2Þg= ð2πÞ m + n ðm − 1Þsy + ðn − 1Þsx
and
n h ioðm+n−1Þ=2
f2 ðyjxÞ = 1= 1 + mnðy − xÞ2 =ðm + nÞ ðm − 1Þs2y + ðn − 1Þs2x :
Also, note that the sample means for the future and past observations are y and x,
respectively, and the corresponding sample variances are s2y and s2x , respectively.
The density of the future sample mean y is recognized as a t density with parameters mean
μ= x, degrees of freedom n = (m + n − 3)=2, and precision t = mn(m + n − 3)=2(m + n)½(m −
1)s2y + (n − 1)s2x . See page 279 of Insua, Ruggeri, and Wiper2 for the form of the t density.
356 Bayesian Inference for Stochastic Processes
E ½ X ðt Þ = 0 (8.54)
Also, it can be shown that
Var½XðtÞ = t: (8.56)
In conclusion, a Brownian bridge process acts like a standard Brownian motion, which is
anchored at 0 at the end points 0 and 1.
The process is a special case of the process defined by the normal process fB(t), t ≥ 0g,
where B(t1 ) = a and B(t1 ) = b, and B(t) is standard Brownian motion with mean and
covariance given by
and
Refer to pages 348 and 349 of Dobrow1 for the R Code that simulates the Brownian bridge
process which appears here as R Code 8.7:
Bayesian Inferences for Normal Processes 357
R Code 8.7
mu<-0
sig<-1
n<-1000
t<-seq(0,1, length =n)
bm<-c(0,cumsum(rnorm(n-1,0,1)))/sqrt(n)
x<-mu*t+sig*bm
bb<-x-t*x[n]
The Brownian bridge values are plotted in Figure 8.8. Note how the realization is anchored
at the end points of [0,1]. The time interval length is .001 over [0,1] for a total of 1000 values.
The Bayesian analysis will be based on the 15 increments corresponding to the first 30
Brownian bridge values generated by R Code 8.7.
The Bayesian analysis is executed with WinBUGS Code 8.6 with 35,000 observations for
the simulation and 5,000 for the burn-in. Noninformative prior distributions were assigned
to t and μ.
30
25
20
g
15
10
5
0
FIGURE 8.8
Plot of 1000 Brownian bridge values over [0,1].
358 Bayesian Inference for Stochastic Processes
The Bayesian analysis for the Brownian bridge example appears in Table 8.7.
The posterior distribution of t appears to be nonsymmetric as does that for s2 . The esti-
mates for μ and s2 are very reasonable. For example, the hypothetical value of s2 should be
.001 (the interval length between observations of the Brownian bridge values) and the pos-
terior median is .001847 with a 95% credible interval of (.00092,.00454). Also, the hypothetical
value of μ is zero, and its posterior median is −.00089 with a 95% credible interval of (−.02504,
.023590).
It would be interesting to test the hypothesis H: μ = 0 and t = 1000 versus the alternative
A that H is not true.
Recall that the posterior probability of the null hypothesis is
where
where
ð∞ ð∞
f 1 ðx Þ = f ðxjμ, tÞr1 ðμ, tÞdμdt,
0 −∞
nh i o
f ðxjμ, tÞ = tn=2 =2π exp −ðt=2Þ nðμ − xÞ2 + ðn − 1Þs2x dμ dt,
TABLE 8.7
Posterior Analysis for Brownian Bridge
Parameter Mean SD Error 2 1/2 Median 97 1/2
μ −.00089 .01228 .000074 −.02504 −.00089 .02359
s2 .002071 .000972 .000005 .00092 .001847 .00454
t 570.1 222.9 1.311 220 541.4 1086
Bayesian Inferences for Normal Processes 359
where x = −0:00082 and s2x = 0:001481, and π0 = π1 = 1=2 is the prior probability of the null
and alternative hypotheses. Also, the improper prior is assigned as
In addition,
h i
f (xjμ = 0, t = 1000) = (1000)15=2 =(2π)15=2 exp − 500(10:367) ∼ 1012 (8.62)
and f1 (x) = :000419561; thus, the posterior probability of the null hypothesis in Equation
8.60 is p0 ∼ 1, and there is not enough evidence to reject the null hypothesis.
For additional information about Brownian bridge processes, see the book by Revuz
and Marc.9
8.8 Martingales
The martingale class of stochastic processes conveys the idea of a fair game in the sense
that after n plays of gambling, if your winnings are z, your future earning on average will
be z, regardless of the past history of the gamble. To be more precise, a stochastic process
fY(t), t ≥ 0g is a martingale if for all t ≥ 0,
An interesting property of martingales is that the expectation for all times is the same;
that is,
It is often useful to know that the following extension involving the idea of a stochastic
process is a martingale with respect to another process; hence the process fY(t), t > 0g is a
martingale with respect to fX(t), t > 0g if for all t > 0,
Examples of such a situation are demonstrated when Y(t) is a function g of X(t), say,
Y(t) = g(X(t)). Consider the quadratic martingale
Is the process a martingale with respect to Brownian motion? If it is, one needs to show
that
E½YðtÞjBðrÞ, 0 ≤ r ≤ s = YðsÞ
= B 2 ðsÞ − s
and that
E½jYðtÞj < ∞ :
This will be left as an exercise for the reader. See the problems at the end of the chapter.
The next example returns to the geometric Brownian motion and an application to pricing
options in finance. Suppose
GðtÞ = Gð0ÞexpXðtÞ
is a geometric Brownian motion where fX(t), t ≥ 0g is Brownian motion with drift μ and
variance s2 and suppose r = μ + s2 =2, then e−rt G(t) is a martingale with respect to standard
Brownian motion.
The following proof can be found on page 359 of Dobrow.1
Let 0 ≤ s < t, then consider
E e−rt GðtÞ BðrÞ, 0 ≤ r ≤ s = e−rt E Gð0Þeμt+sBðtÞ BðrÞ, 0 ≤ r ≤ s
= e−rt eμs+sBðsÞ E½Gðt − sÞ
(8.69)
= e−sðμ+s =2Þ Gð0Þeμs+sBðsÞ
2
= e−rs GðsÞ,
which shows that the process fe−rs G(s), s ≥ 0g is a martingale with respect to Brownian
motion.
The geometric Brownian motion is often used to model stock and option prices and can be
applied to the Black–Scholes10 model for pricing options. It provides a way to price options
and other financial instruments such as derivatives, which soon developed into a giant
global market for trading even more complicated financial options. There are some objec-
tions to this model: (1) the prices follow the geometric Brownian motion and (2) the
expected rate of return should be risk free such as, for example, government bonds.
Suppose r is the risk-free interest rate, and P is the initial investment, then in t years, one
would expect to accumulate P(1 + r)t ; thus, after a long period under continuous com-
pounding, one could accumulate a future value of F = Pert dollars. On the other hand, and
under the same circumstances, suppose in the future, one would accumulate F dollars; then to
know its present value by discounting the future amount by e−rt gives the present value (the
Bayesian Inferences for Normal Processes 361
price of the instrument) as P = e−rt F. This is the basis for using the geometric Brownian motion
for the price of the option.
Let G(t) denote the price of the instrument t years from now, then the present price is
e−rt G(t). The model is risk free, which implies that the discounted instrument is a fair game,
and the return is a martingale; that for times 0 < s < t, the average present value at time t
should be the same as it was up to the past time s. In symbols, this is represented as
E e−rt GðtÞ GðyÞ, 0 < y < s = e−rs GðsÞ: (8.70)
If Equation 8.70 holds, then it can be shown that r = μ + s2 =2 or μ = r − s2 =2, then the
Black–Scholes formula for the price of the instrument is
h pffiffii h pffiffii
Price = E e−rt maxfGðtÞ − k, 0g = Gð0ÞP Z > ða − stÞ= t − e−rt KP Z > a= t , (8.71)
where
a = lnðK=Gð0ÞÞ − r − s2 =2 t =s: (8.72)
Consider the following example, where G(0) = 80, K = 100, s2 = :25, t = 90/365, and
interest rate r = .02., which determines a = :498068. (Note that μ = r + s2 =2 = :145.) Based on
the Black–Scholes price (Equation 8.71), the price is computed as $2.426.
Bayesian inferential techniques will be based on 30 observations generated from a geo-
metric Brownian motion process using R and parameter values s2 = :25 and μ = :145, and
then based on the 15 corresponding increments, determine the posterior distribution of μ
and s2 , and the main objective of the posterior distribution of the price of the option, given
by Equation 8.72. This implies that the posterior distribution of P will have a posterior
standard deviation and credible interval that project the uncertainty in making inferences
about the price. The value of $2.426 was computed on page 361 of Dobrow1 by direct
substitution into the formula for the price (Equation 8.72); however, the Bayesian approach
is much more realistic because it is based on data which reflect the uncertainty in investing
in financial instruments.
R Code 8.8
t <- 1:365 # time
sig2 <- 0.25
## first, simulate a set of random deviates
x <- rnorm(n = length(t) - 1, sd = sqrt(sig2))
## now compute their cumulative sum
x <- c(0, cumsum(x))
y<-x+.145
# g values are Geometric Brownian motion values
g<-exp(y)
Using noninformative prior distributions for μ and s2 , and based on 15 increment values
appearing in the list statement, the Bayesian analysis is executed with WinBUGS Code 8.7
using 35,000 observations for the simulation and 5,000 for the burn-in.
list(X=c(1.6666,-.17607,-.28964,-.12208,.06593,
.08236,.03905,.0671,.02531,.43813,.63526,
-.28224,.75282,2.48986,-.17967))
list(mu=0, tau=4)
The Bayesian analysis for estimating the stock price appears in Table 8.8. Note that the
main parameter of interest is the stock price which has a posterior mean of $1.924 compared
to $2.42 dollars directly by substitution in Equation 8.71.
TABLE 8.8
Posterior Analysis for Price of Stock
Parameter Mean SD Error 2 1/2 Median 97 1/2
Price 1.925 34.54 .1011 −19.51 −10.51 80
a −.04975 .06678 .000204 −.1806 −.04954 .08162
μ .3473 .2184 .000681 −.08876 .3474 .7798
s2 0.7167 0.3183 0.00104 0.3293 0.6488 1.525
t 1.627 0.6152 0.00199 0.6559 1.551 3.037
Bayesian Inferences for Normal Processes 363
The data generated for the analysis induce a mean for the increments as zero, but
the Bayesian analysis for μ has a posterior mean of .3473 and a 95% credible interval of
(−.08876,.7798). The interval barely includes the number 0, implying weakly that the mean
is indeed 0. Also, the value for s2 used to generate the data was .25 compared to its posterior
median .6488, and its 95% credible interval is (0.3293,1.525), which does not include the
value of .25. Of course, one should not be surprised that the Bayesian estimates do not agree
with the values used to generate the data. If another set of 30 generated values had been
used for the Bayesian analysis, the posterior results would differ from those reported in Table
8.9. The sampling variability in choosing the data set induces variability in the posterior
estimates of the parameters reflected by the posterior standard deviations and credible
intervals.
where
b = ½lnðk=Gð0Þ − tμÞ=s :
Notice the similarity in the expected payoff of an option given by Equation 8.73 and the
price of stock given by the Black–Scholes approach given by Equation 8.71. The two
parameters μ and s2 are the drift and variance of the geometric Brownian motion process,
respectively. R Code 8.9 generates 365 values for the stock process with parameters
s2 = .25 and μ = .1 for the underlying Brownian motion process.
364 Bayesian Inference for Stochastic Processes
R Code 8.9
t <- 1:365 # time
sig2 <- 0.25
## first, simulate a set of random deviates
x <- rnorm(n = length(t) - 1, sd = sqrt(sig2))
## now compute their cumulative sum
x <- c(0, cumsum(x))
y<-x+.1
g<-exp(y)
Forty values of the underlying Brownian motion process are given value, and they
include values 256–304:
The Bayesian posterior analysis is executed with WinBUGS Code 8.8 with 35,000 obser-
vations for the simulation and burn-in of 5,000. Information for the analysis consists of the
20 increment values corresponding to the 40 geometric Brownian values generated with
R Code 8.9. Such values were generated assuming s2 = .25 and μ = .1. Note the non-
informative prior distributions, namely, a normal (0,.001) for μ and a gamma (.001,.001) for t.
mu~dnorm(0,.001)
tau~dgamma(.001,.001)
for ( i in 1:20){
X[i]~dnorm(mu,tau)}
sigma<-1/tau
# current value of stock
g0<-90
# striking value
k<-110
t<-80/365
# p is the payoff
p<-p1-p2
Bayesian Inferences for Normal Processes 365
p1<-g0*(exp(t*(mu+sigma/2))*step(Z-(beta-sqrt(sigma)*t))/sqrt(t))
p2<-k*step(Z-beta/sqrt(t))
Z~dnorm(0,1)
beta<-(log(k/g0)-t*mu)/sqrt(sigma)
}
# the 20 increment values are given below in the list
list(X=c(-.3507,-.3016,-.06998,.12274,-.55404,
-.54297,1.27865,.28206,-.27495,1.02443,
.14147,-.44845,.900205,-.532307,.14566,
.294189,-.13073,.29245,-.2204,.44691))
list(mu=0,tau=4)
The main parameter is the payoff with a posterior mean of $57.34 for an option that
expires in 90 days, with a current value of $80 and a striking value of $110 (Table 8.9).
The simulation of the geometric Brownian motion values appears reasonable, and the
increments have hypothetical mean of 0 and variance of .25. Also, 95% credible intervals for
μ and s2 include 0 and .25, respectively, indicating that the posterior inferences for these
parameters are not misleading.
Lastly, it is worth mentioning the subject of fractional Brownian motion, a subject that will
not be developed here, but will be left to the student in the exercises at the end of Chapter 8.
Such processes are examples of long-term processes, and Beran11 should be read for
additional information.
The fractional Brownian motion fBH (t), t ∈ ½0, Tg is a Gaussian process with mean value
of 0 and covariance function
where H is the Hurst index. When H = 1/2, the process is a standard Brownian motion,
while when H > 1/2, one may show that the correlation between observations is positive,
but on the other hand, when H < 1/2, the correlation is negative.
TABLE 8.9
Posterior Analysis for Option Price
Parameter Mean SD Error 2 1/2 Median 97 1/2
b .3428 .07432 .000469 .1998 .3411 .4926
μ .0746 .1255 .000724 −.1755 .0746 .3233
Payoff 57.34 76.95 0.4676 0 0 208
P1 88.24 99.81 0.5969 0 0 212
P2 25.9 46.67 0.2622 0 0 110
s2 .3146 .1145 .000694 .1622 .2916 .5992
366 Bayesian Inference for Stochastic Processes
with drift and are used to evaluate the probability that the home team will win, given that
the home team score was y ahead of the other team at a given fraction time t of the game.
R Code 8.5 generated 100 Brownian motion values with drift parameters μ = 4:87 and s =
15:82, and then based on the 50 corresponding increment values, with WinBUGS Code 8.4,
a Bayesian analysis estimates the probability (Equation 8.40) that the home team wins, and
the posterior analysis is reported in Table 8.5 for y = 0 (the teams are tied) and t = 1/2 (half
time). Some exercises at the end of the chapter expand on the Bayesian analysis for home
team advantage.
Next to be considered in Section 8.7 is an extension of Brownian motion referred to as the
geometric Brownian motion, where the process is defined (Equation 8.41), and several
examples are given. Recall that the geometric version is defined as the exponential function
with exponent of a regular Brownian motion process X(t) ~ N(μt, s2 t), with moments
expressed with formulas in Equation 8.45.
The main parameter of interest is P[G(281) < 6] (Equation 8.49), and the Bayesian analysis
is executed with WinBUGS Code 8.5. Note that the sample information is the 15 increment
values corresponding to the 30 values of the geometric process. Noninformative prior
distributions are assigned to the parameters, and the posterior results are reported in
Table 8.6. The next example involves several geometric processes plus the underlying
exponent for a regular Brownian motion. See Figure 8.6 for a plot of these three geometric
processes. R Code 8.8 generates the geometric values with various values of μ and s2 of the
underlying Brownian motion. A Bayesian analysis executed with WinBUGS Code 8.7
based on the 15 increments of the underlying Brownian motion is completed. Table 8.7
reports the posterior analysis for estimating μ and s2 , and separately, the predictive dis-
tribution for a future value from a Geometric Brownian motion process is derived and
appears in Equation 8.53.
Still another generalization is described in Section 8.7.2, the so-called Brownian bridge,
which is a Brownian motion over [0,1], where B(1) = 0. Moments of the process are
expressed by Equations 8.54 and 8.55, and the Brownian bridge is generalized as a normal
process anchored at arbitrary time points s and t with s < t and B(s) = a and B(t) = b. As in the
previous section, R Code 8.0 generates values from the Brownian bridge with parameters
μ = 0 and s2 = 1 and the increments used as data for the Bayesian analysis. Remember that
the increment process has mean of 0 and variance of .001.
Lastly, a formal Bayesian test of H: μ = 0 and s2 = :001 is performed using the 15 incre-
ment values, and the posterior probability of the null hypothesis calculated as p0 ≈ 1.
A generalization of Brownian motion is the stochastic process called a martingale defined
by Equation 8.63 that has the property that its expectation is the same for all time. Many
functions of the Brownian motion are martingales, for example, the process Y(t) = B2 (t) − t
and the process X(t) = e−rt G(t), where G(t) is a geometric Brownian process is a martingale.
Also presented is the Black–Scholes model of pricing a financial instrument such as a stock,
where observations for this process are generated by R Code 8.10, and using the observa-
tions for data, a Bayesian analysis is conducted and reported in Table 8.9, with the main
parameter being the price of financial instrument.
A similar example is provided by Bayesian inferences for the payoff of buying a stock
option. In order for the option to be exercised, one must know the current price of the
option, the price of the option, the length of the option, and the striking value of the option.
The value of the underlying stock follows a geometric Brownian motion whose 40 values
are generated via R Code 8.11, and the Bayesian analysis is executed with R Code 8.8. The
average payoff of the option is the main parameter of interest with its posterior distribution
reported in Table 8.9.
368 Bayesian Inference for Stochastic Processes
8.11 Exercises
Assume that μ = 2 and s2 = 4, a= b=3, then R Code 8.10 generates the following
30 observations from Brownian motion with μ = 2 and s2 = 4.
R Code 8.10
t <- 1:30 # time
sig2 <- 4
mu<-2
## first, simulate a set of random deviates
x <- rnorm(n = length(t) - 1, sd = sqrt(sig2))
## now compute their cumulative sum
x <- c(10, cumsum(x))
mu~dnorm(0,.001)
tau~dgamma(.001,.001)
for ( i in 1:15){
y[i]~dnorm(mu,tau)}
sigma<-1/tau
p<-p1/(p2-p3)
a<-3
b<-3
p1<-1-exp(2*newmu*b/sigma)
p2<-exp(-2*newmu*a/sigma)
p3<-exp(2*newmu*b/sigma)
newmu<-mu+2
}
list(y=c(-13.2683,-2.3697,-2.794,-.8144,1.2816, .9637,.7493,
1.9197,.2776,3.4823,3.0725, -1.666,1.798,2.7291,-.1102))
TABLE 8.10
Posterior Analysis for Hitting Times
Parameter Mean SD Error 2 1/2 Median 97 1/2
μ −0.3205 1.142 0.005827 −2.568 −0.3198 1.945
Newmu 1.68 1.142 0.005827 −0.5682 1.68 3.945
p .6415 .09599 .000493 .4626 .639 .8327
s2 19.25 8.616 0.04959 8.853 17.33 40.95
t .06056 .02283 .000129 .02442 .0577 .113
Bayesian Inferences for Normal Processes 373
References
1. Dobrow, R. P. 2016. Introduction to Stochastic Processes with R. New York: John Wiley & Sons.
2. Insua, D. R., Ruggeri, F., and Wiper, M. P. 2012. Bayesian Analysis of Stochastic Process Models. New
York: John Wiley & Sons.
3. Ntzoufras, I. 2009. Bayesian Modeling. New York: John Wiley & Sons.
4. Wiener, N. 1923. Differential space, Journal of Mathematics and Physics/Massachusetts Institute of
Technology 2:131–174.
5. Lee, P. M. 1997. Bayesian Statistics, An Introduction, Second Edition. London: Arnold.
6. Feller, W. 1950. An Introduction to Probability Theory, Volume 1. London: John Wiley & Sons.
7. Stern, H. S. 1994. A Brownian motion model for the progress of sports scores, Journal of the
American Statistical Association 89(427):1128–1134.
8. Revuz, D., and Yor, M. 1999. Continuous Martingales and Brownian Motion, 12th Edition. New York:
Springer-Verlag.
9. Black, F., and Scholes, M. 1973. The pricing of options and corporate liabilities, Journal of Political
Economy 81(3):637–654.
10. Beran, J. 1994. Statistics for Long Term Processes. Boca Raton, FL: Chapman & Hall.
[Link]
9
Queues and Time Series
9.1 Introduction
This chapter presents Bayesian inferences for two types of stochastic processes, queues
and time series. For example, the first process to be studied is the M/M/1 queue, and then
the chapter proceeds to more complex queues. Next to be presented is an introduction to
time series models, including the autoregressive, the moving average, the autoregressive
moving average processes, and the regression models with residuals that are correlated
time series.
As in previous chapters, in order to simulate the various stochastic processes where the
parameters of the processes are known, R is implemented. Then using those observations
generated by R as the sample information and assuming that the parameters are now not
known, a Bayesian analysis will be executed with WinBUGS. This allows one to make
Bayesian inferences about those unknown parameters. Bayesian inferences consist of three
phases: estimation, testing hypotheses, and prediction of future observations. It is important
to remember that Bayesian inferences depend on prior information about the unknown
parameters, the sample information expressed by the likelihood function, and the resulting
posterior distribution about those parameters. Of course, all Bayesian inferences are based
on the posterior distribution.
375
376 Bayesian Inference for Stochastic Processes
being served, the time it takes to complete being served. This section will employ R to
generate observations for the queuing model, such as the arrival time of the customers
entering the queue and the service time of those doing their transactions. Based on those
observations generated by R with known parameters for the queuing model, Bayesian
inferences for those parameters (now assumed unknown) will be implemented with
WinBUGS. This section on queuing will closely follow Chapter 7 of Insua, Ruggeri, and
Wiper.1
In what is to follow, the fundamental properties of a general queuing model is described,
and then focus is centered on the special case of the M/M/1 system, followed by expla-
nations of non-Markov processes.
Generally speaking, a queuing system is a family of several stochastic processes
describing the waiting and service times of the people in the queue. They arrive according
to some process (which can be represented by deterministic or stochastic mechanisms), and
then they have to wait, if required, before being attended to by one or more servers.
S is the service time. For our purposes, the preceding variables will be considered random
and with distributions that, in reality, are difficult to know. A key concept in the study of
queues is that of the stability of the system (what happens in the long run), which is defined
for a G/G/c queue as follows.
Consider a G/G/c process with general interarrival time distribution, as well as a
general service time distribution and c servers, infinite capacity and customer population,
Queues and Time Series 377
r = lEðSÞ=c, (9.2)
where l is the average interarrival time, and E(S) is the average service time. Note that
when r > 1, it appears that the interarrival time average is greater than the mean service
time, and consequently, the size of the queue will increase over time, and the stability of
the system is in doubt. On the other hand, when r < 1, that stability occurs in the sense
that the distributions of N(t), the total number in the system at time t, and W(t) approach
stability defined as
and (9.3)
lim P½W ðtÞ < w = P½W < w:
t!∞
EðN Þ = lEðW Þ
and (9.4)
EðNb Þ = lEðWq Þ:
r = l=μ; (9.5)
Hence, the system is stable if the arrival rate is less than that of the service rate. From
previous considerations, the equilibrium distributions exist, and according to Gross et al.,3
the limiting distribution for the number of people in the system is geometric:
r e Geð1 − pÞ (9.6)
378 Bayesian Inference for Stochastic Processes
with mean E½N = r=(1 − r), and that for the number of clients in the queue waiting for
service has mass function of
h i
P Nq = n = P½N = 0 + P½N = 1, n = 0
(9.7)
= P½N = n + 1, n ≥ 1:
In addition, the limiting distribution for the time W spent by an arriving customer in the
system is
W e expðμ − lÞ (9.8)
and that for the idle period time J of a server has density of
The purpose of a Bayesian analysis will be to provide inferences for the unknown
parameters μ and l. Remember that in practice, one would have data organized as follows:
For each customer, the time of arrival to the queue is recorded, the waiting time is also
recorded, and the service time for that client would be noted. For the statistician, a distri-
bution needs to be assigned to the waiting times and service times. These are determined
empirically with goodness-of-fit tests etc., and then classical inferences such as maximum
likelihood made for parameters μ and l.
For the M/M/1 process, one is assuming that the interarrival times and service times are
exponential, but one must remember that this assumption needs to be justified. For this
case, Bayesian inferences are quite simple. Suppose one has the following information: the
total time ta taken for the first na arrivals and the total time ts taken to service the first ns . It is
obvious that the likelihood function is
Prior distributions must be assigned to l and μ; thus, consider the improper prior
and then the posterior distribution of l is gamma (na , ta ) and that of μ is gamma (ns , ts ), and
l and μ are independent. Thus, Bayesian inferences are somewhat straightforward if one
knows the sufficient statistics na , ta , ns , and ts ; however, it should be remembered that these
are computed from the individual waiting and service times.
Suppose it is assumed that the arrival rate to the queue is Poisson with l = 2, and the
service rate is Poisson with μ = 4; then WinBUGS Code 9.1 generates 32 interarrival times
with parameter l = 2 and 24 service times with μ = 4, where the data so generated are in the
list statement of WinBUGS Code 9.1. The vector y comprises the 32 interarrival times, while
the vector x denotes the 24 service times.
Queues and Time Series 379
y[i]~dexp(2)
}
for( j in 1:24){
x[j]~dexp(4)}
}
list(
x = c(
0.3089,0.05381,0.2722,0.3297,0.1448,
0.2653,0.4153,0.1016,1.147,0.2276,
0.2444,0.1064,0.01524,0.2323,0.2039,
0.529,0.1551,0.1974,0.8159,0.2866,
0.04165,0.1458,0.009616,0.4576),
y = c(
0.9452,1.375,0.1224,0.265,0.4189,
0.3082,0.0874,0.02587,0.002924,0.7175,
0.1315,0.5326,0.1267,0.6279,0.1355,
2.008,0.1355,0.3271,0.5271,0.1954,
0.1059,1.266,0.5406,0.1794,0.7701,
0.4849,0.3033,0.2122,1.159,0.4769,
1.773,0.01511))
Using the observations generated by WinBUGS Code 9.1, and tacitly assuming that the
two parameters are unknown, the posterior distribution for l, μ, and r = l=μ is executed
with 35,000 observations for the simulation and 5,000 for the burn-in. Noninformative
gamma priors are assigned to the two parameters.
for( i in 1:32){
y[i]~dexp(lamda)
}
for( j in 1:24){
x[j]~dexp(mu)}
# the following is the posterior probability of the null hypothesis
prob<-step(1-rho)
380 Bayesian Inference for Stochastic Processes
}
list(
x = c(
0.3089,0.05381,0.2722,0.3297,0.1448,
0.2653,0.4153,0.1016,1.147,0.2276,
0.2444,0.1064,0.01524,0.2323,0.2039,
0.529,0.1551,0.1974,0.8159,0.2866,
0.04165,0.1458,0.009616,0.4576),
y = c(
0.9452,1.375,0.1224,0.265,0.4189,
0.3082,0.0874,0.02587,0.002924,0.7175,
0.1315,0.5326,0.1267,0.6279,0.1355,
2.008,0.1355,0.3271,0.5271,0.1954,
0.1059,1.266,0.5406,0.1794,0.7701,
0.4849,0.3033,0.2122,1.159,0.4769,
1.773,0.01511))
list(lamda=2,mu=4)
TABLE 9.1
Posterior Analysis for M/M/1 Queue
Parameter Mean SD Error 2 1/2 Median 97 1/2
should be used as an estimate of E(N) because of the asymmetry in its posterior distri-
bution. In a similar fashion, the posterior distribution of the average time spent by an
arriving customer has an exponential distribution with mean of E(W) = 1/(μ − l), which
has a posterior median of 1.6221. Again because of the asymmetry in its posterior dis-
tribution, I recommend the posterior median as an estimator of E(W).
R Code 9.1 to execute a simulation of an M/M/1 queue was downloaded from https://
[Link]/simulating-a-queue-in-r/.
This example assumes that the arrival rate is Poisson with l = 2, and with the service
time, exponentially distributed with parameter μ = 4, which are the values used to generate
the data in R Code 9.1.
R Code 9.1
0 10 20 30 40 50 60 70
Timer
FIGURE 9.1
Queue size versus time.
Queues and Time Series 383
WinBUGS Code 9.2 is totally Bayesian and based on the data of exponential arrival and
service times generated in WinBUGS Code 9.1.
EðXÞ = 1=l
and (9.14)
2
V ðXÞ = 1=nl ,
respectively.
As was seen earlier, the traffic intensity is r = l=μ, where the service times have an
exponential distribution with parameter μ. It is easy to see that the Erlang distribution is a
gamma distribution with parameters a = n and b = nl; thus, the traffic intensity can be
expressed as
r = a=μb: (9.15)
A Bayesian analysis is presented, assuming that a = 2 and b = 4 for the interarrival times
of the gamma distribution or, equivalently, in terms of the Erlang n = 2 and l = b=a = 2.
Also, the arrival rate is b=a = 1=l = 2, and finally, the service time exponential distribution
is assigned the parameter μ = 4; hence, the traffic intensity is r = a=μb = 1=2.
WinBUGS Code 9.3 generates the 32 interarrival times X with a gamma (2,4) distribution,
while the 24 service times Y have a distribution that is exponential with parameter of 4.
0.3969,0.1987,0.4238,0.3841,0.311,
0.556,0.3274,0.5975,0.2693,0.1435,
0.4527,0.8288,1.002,0.2473,1.051,
1.672,0.7948),
y = c(
0.4112,0.1581,0.1171,0.2083,0.03417,
0.1366,0.0466,1.242,0.0858,0.1086,
0.03962,0.1377,0.1301,0.1286,0.2874,
0.0092,0.2794,0.3757,0.002431,0.1671,
0.04103,0.6679,0.06998,0.05484))
Now based on the observations for the interarrival times and service times generated in
WinBUGS Code 9.3, WinBUGS Code 9.4 is executed for the Bayesian analysis with 35,000
observations for the simulation and 5,000 for the burn-in. One is tacitly assuming that
the parameters μ and b are unknown. The main goal is to provide Bayesian inferences
for a,b,μ,r, and P½r < 1jdata. Noninformative gamma (.001,.001) prior distributions are
assigned to a, b, and μ:
TABLE 9.2
Posterior Analysis of G/M/1
Parameter Mean SD Error 2 1/2 Median 97 1/2
The Bayesian analysis will be based on observations generated from the appropriate
gamma distribution, namely, 32 observations from the gamma(2,4) for the interarrival
times, and for the 24 service times, the gamma(2,8). Using 35,000 for the simulation and a
burn-in of 5,000, WinBUGS Code 9.5 generates the appropriate interarrival X and service Y
times.
0.2072,0.1701,0.8705,0.3998,0.1295,
0.2305,0.3799,0.2855,0.6025,0.5822,
0.1772,0.6122,0.1712,0.3514,0.2978,
0.25,0.4489,0.5986,1.262,0.6811,
0.4534,0.2926,0.3596,1.104,0.201,
0.2574,0.2824,0.7037,0.3016,0.1991,
1.147,0.1383),
y = c(
0.6385,0.4613,0.168,0.2391,0.1547,
0.2135,0.2841,0.3483,0.7737,0.07918,
0.1383,0.2535,0.3224,0.1256,0.2765,
0.23,0.5598,0.1059,0.1343,0.3265,
0.0195,0.1944,0.1163,0.4366))
The purpose of the Bayesian analysis is to estimate the unknown parameters aa ,ba ,as ,bs ,μ,
and l and the posterior probability P½r < 1jdata.
WinBUGS Code 9.6 is executed with 35,000 observations for the simulation and a burn-in
of 5,000. Noninformative gamma priors were assigned to aa ,ba ,as , and bs .
for ( j in 1:24){y[j]~dgamma(alphas,betas)}
rho<-(betaa/alphaa)/(betas/alphas)
prob<-step(1-rho)
lamda<-betaa/alphaa
mu<-betas/alphas
}
list(
x = c(
0.2072,0.1701,0.8705,0.3998,0.1295,
0.2305,0.3799,0.2855,0.6025,0.5822,
0.1772,0.6122,0.1712,0.3514,0.2978,
0.25,0.4489,0.5986,1.262,0.6811,
Queues and Time Series 387
0.4534,0.2926,0.3596,1.104,0.201,
0.2574,0.2824,0.7037,0.3016,0.1991,
1.147,0.1383),
y = c(
0.6385,0.4613,0.168,0.2391,0.1547,
0.2135,0.2841,0.3483,0.7737,0.07918,
0.1383,0.2535,0.3224,0.1256,0.2765,
0.23,0.5598,0.1059,0.1343,0.3265,
0.0195,0.1944,0.1163,0.4366))
list( alphaa=2,betaa=4,alphas=2,betas=8)
The posterior analysis is displayed by Table 9.3, and the posterior distributions appear to
be symmetric about the posterior mean. Consider first the traffic intensity r, which has a
95% credible interval of (.4365, .9032), implying informally that the process is stable, which
is also implied by the posterior probability P½r < 1jdata, which has a posterior mean of
.9935.
The values of aa = 2 and ba = 4 were used to generate the interarrival times of the clients,
and it is noted that the posterior mean of aa is 2.616 with a 95% credible interval of
(1.54,4.02), which indeed includes the value 2.
In fact, the values used to generate the interarrival and service time data do in fact contain
those values with the corresponding 95% credible interval. The per unit arrival rate for
clients is estimated as 2.262, while the per unit time service rate is 3.638 clients.
This section has presented three examples of queues with one server, what do they have
in common? This will be further investigated in the problems at the end of the chapter. For
additional information about the Bayesian analysis of the M/G/1 queue, see pages 183–187
of Insua, Ruggeri, and Wiper,1 who in turn refer to Ausin and Lopes,4 and for additional
information about the Bayesian analysis of G/M/1 queues, see Wiper.5
TABLE 9.3
Posterior Analysis for the G/G/1 Queue
Parameter Mean SD Error 2 1/2 Median 97 1/2
R Code 9.2 downloads the data and plots the time series.
R Code 9.2
data(AirPassengers)
AP<-AirPassengers
AP
plot(AP, ylab="Passenger (1000's)")
FIGURE 9.2
Monthly international air passenger information.
390 Bayesian Inference for Stochastic Processes
One can see the overall trend and seasonal (annual variation) variation, where the trend
appears linear, and the annual variation has the same pattern from year to year. A statistical
analysis would propose mathematical models to account for the trend and seasonal variation.
There are a number of features in the plot that are common to many time series. Generally
speaking, a deterministic change in the series that is not periodic is referred to as trend, and
the most elementary change is linear. A repeating pattern annually is called seasonal,
although the term is also pertinent to a pattern that repeats itself over a fixed period.
The seasonal variation in the air passenger data reveals that bookings were higher during
the summer months and lowest in November and February. What is a reasonable expla-
nation for the overall increasing trend? As proposed by Cowpertwait and Metcalfe, the
overall increasing prosperity after World War II, the availability of more aircraft, and
cheaper tickets because of competition are seen to be reasonable causes. With a better view
of the overall trend, the data can be aggregated, which for the present example is executed
with R Code 9.3:
R Code 9.3
layout(1:2)
plot(aggregate(AP))
One sees the absence of seasonal variation and a clear linear increasing trend displayed in
Figure 9.3. Additional information can be achieved by aggregating over the years and
computing the box plot for each month as displayed in Figure 9.4. The graph in this figure
accounts for the overall trend after aggregating over the 12 years and for the variation
within the 12 years.
where x(t) is the observed series, m(t) is the trend, and s(t) is the seasonal effect, and z(t) is an
error term which is a sequence of correlated random variables. Now the principal problem is
extracting information about the trend and seasonal effects. When the seasonal effect
increases with an increasing trend, a reasonable representation is
5000
2000
Time
FIGURE 9.3
Aggregated air passenger data.
Queues and Time Series 391
600 500
Bookings (thousands)
300 400200
100
1 2 3 4 5 6 7 8 9 10 11 12
Month
FIGURE 9.4
Box plot of air passenger data.
and the errors z(t) are a correlated sequence of normally distributed random variables with
mean of 0 and variance s2 .
In R, the function decompose estimates trend and seasonal effects with a moving average
method. For example, consider the air passenger data and use the command
plot(decompose(AirPassengers))
sd d
ðtÞ = xðtÞ − m ðtÞ, (9.21)
and if the model is multiplicative, see Equation 9.18, the seasonal effect is
392 Bayesian Inference for Stochastic Processes
500
Observed
300
150 250 350 450 100
Trend
40
Seasonal
0
60 –40
Random
0 20
–40
FIGURE 9.5
Decomposition of air passenger information.
sd d
ðtÞ = xðtÞ=m ðtÞ: (9.22)
These estimates of trend (via the moving average) and seasonal effects (via Equations 9.20
or 9.21) are reflected in Figure 9.5, the graphical representation of decomposition of the
series via R.
for the mean value function, and for the variance function,
Many time series are correlated and are an important parameter to estimate in a statistical
analysis and defined in terms of the covariance
as
pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
r½XðsÞ, XðtÞ = Cov½XðsÞ, XðtÞ= Var½XðsÞVar½XðtÞ,
where
where
s2 = Var½XðtÞ (9.27)
is the constant variance function. It is important to know that the autocorrelation function
does not depend on t, only on k.
As an example, a minimum of 60 water levels of the Nile River were measured, in mil-
limeters, in a gauge near Cairo. This appears to be a process with a constant mean level, and
the first 31 values are plotted in Figure 9.6. There does not appear to be a trend in the
observations; thus, the autocorrelation function will be plotted, and the autocorrelation
values, computed for a few lags. Can a pattern be discerned in this information about the
minimum values of the Nile River for 60 years?
The autocorrelation function is plotted in Figure 9.7 and show a large positive correlation
at lag 0, which had the required value 0, while at lag 1, the positive correlation is com-
puted as .08699, and at lag 2, a small negative value of −.1895, etc. For example, use the
R function acf(nile) for the autocorrelation function and acf(nile)$acf[2] for the
lag 1 correlation.
As will be seen, the pattern of how the autocorrelations die out is quite useful in the
identification of the appropriate model. The acf plot of Figure 9.7 is referred to as the
correlogram.
The command plot(nile[1:59],nile[2:60]) is a plot of the lag 1 values, that is,
the pairs [X(i − 1), X(i)], i = 2, 3, …, 60, where the graph should approach a straight line with
394 Bayesian Inference for Stochastic Processes
1400
1300
1200
Nile
1100
1000
0 10 20 30 40 50 60
Timer
FIGURE 9.6
Nile River data.
Series Nile
1.0
0.8
0.6
ACF
0.4
0.2
0.0
–0.2
0 5 10 15
Lag
FIGURE 9.7
Autocorrelation function of Nile River levels.
Queues and Time Series 395
slope 1 when the lag 1 autocorrelations approach 1. The reader will be asked to execute this
command as an exercise at the end of this chapter.
of variables W(1), W(2), :::, W = (n), which are independent and identically distributed with
mean of 0, constant variance of s2 , and, of course, cor½W(i), W(j) = 0, i ≠ j. In addition, if
W(i) e N(0,s2 ), the noise is referred to as Gaussian or normal white noise.
R is useful to simulate time series, and this will be done for the basic stochastic models,
such as white noise, random walks, and random walks with drift. Consider the scenario
where a fitted time series can be used to simulate data. As has been seen throughout this
book, simulation is used for a variety of reasons. In R, simulation is a simple operation
where most of the well-known distributions are simulated with an R function. For example,
for a simulation of normal random variables, rnorm(100) generates 100 standard normal
variables. Now consider, the code
R Code 9.4
[Link](1)
w<-rnorm(100)
time<-seq(1,100,1)
plot(time,w)
that generates 100 white noise values, and the plot abscissa has a unit of one. One should
check to see how well the random number generator simulates white noise. For example,
the sample mean(w) = .10887, sample standard deviation sd(w) = .8067, the lag 1 correlation
is acf(w)$acf[2] = −.00365, and, finally, the lag 2 is given by acf(w)$acf[3] = −.02707. Of
course, one should also use the command acf(w) to plot the autocorrelation function of the
w series. The command hist(w) generates the default histogram of the w-purported white
noise series and is valuable in detecting departures from a normal distribution. Such
evaluations are necessarily subjective, in that, another individual might detect different
deviations from normality.
396 Bayesian Inference for Stochastic Processes
where fW(t), t = 1, 2, :::g is a white noise process. Another representation of the random
walk is an infinite series
and since the series begins at some point, say, t = 1, it can be expressed as
One may show that the first and second moments are
μðtÞ = E½XðtÞ = 0,
and are a function of t; thus, the process is not covariance stationary. Also, the autocorre-
lation is
pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
rk ðtÞ = Cov½XðtÞ, Xðt + kÞ= ts2 ðt + kÞs2
pffiffiffiffiffiffiffiffiffiffiffiffiffiffi (9.32)
= 1= 1 + k=t;
R Code 9.5
x<-w<-rnorm(1000)
for ( t in 2:1000) x[t]<-x[t-1]+ w[t]
time<-1:1000
plot(time,x)
The plot of the random walk values over 1000 time points is shown in Figure 9.8. I
computed the following autocorrelations: the lag 2 as acf(x)$acf[3] = .9901 and lag 28 as
acf$acf[29] = .87105, which follows from Equation 9.32. The student will be asked to display
the autocorrelation function with the code acf(x). The random walk values start at 0,
increase to 9, and then rapidly fall to an average value of −25. The average value of the 1000
values is −10.92, which is reasonable after looking at Figure 9.8.
Consider a random walk model with drift, namely,
10
0
–10
x
–20
–30
FIGURE 9.8
Random walk from 1 to 1000.
One hundred values for this random walk with drift of z = 3 and variance of s2 = 1 is
simulated with R Code 9.6:
R Code 9.6
delta=3
x<-w<-d<-rnorm(100)
for (t in 2:100) {x[t]<-x[t-1]+ delta+w[t]
d[t]<-x[t]-x[t-1]}
time<-1:100
plot(time,x)
The goal is to estimate the drift and variance based on the following differences:
TABLE 9.4
Posterior Analysis for Random Walk with Drift
Parameter Mean SD Error 2 1/2 Median 97 1/2
Recall that the value of μ used to simulate the differences d(t) is 3 (the drift) and that for t
is 1. Thus, according to Table 9.4, it seems that the simulated values are believable. For
example, the posterior mean of μ is 3.104 with a 95% credible interval of (2.887,3.321), which
includes 3. In a similar way, the posterior mean of s2 is 1.204 with a 95% credible interval of
(0.91,1.597), which includes the value 1!
The next class of basic time series models is the autoregressive process AR(p) defined as
i=p
X
Y ðt Þ = q i Y ðt − i Þ + W ðt Þ (9.35)
i=1
Also, fW(t), t > 0g is Gaussian white noise with variance s2 and qi , i = 1, 2, :::, p, is a
sequence of unknown autoregressive parameters.
It should be observed that the random walk is a special case of the AR(1) process with
q1 = 1, and the class is called autoregressive because Y(t) is regressed on past terms of the
same process.
AR processes can be stationary or not, depending on the roots of the characteristic
equation Fp (B) = 0. Treat the operator B as a real or complex number, and then if the roots
of the characteristic equation all lie outside the unit circle, then the process is stationary.
Note that the characteristic equation
Fp ðBÞ = 0 (9.36)
Fp ðBÞ = 1 − q1 B − q2 B2 − ::: − qp Bp
is a pth-order polynomial in B.
400 Bayesian Inference for Stochastic Processes
1. The AR(1) process Y(t) = (1/2)Y(t − 1) + W(t) is stationary because the root of
1 − B/2 = 0 is B = 2, which is greater than 1! And more generally, the AR(1) process
is stationary if jq1 j < 1.
2. Also, the AR(2) process Y(t) = Y(t − 1) − (1/4)Y(t − 2) + W(t) is stationary because
the roots of the characteristic equation (1=4)(B − 2)2 = 0 has two roots, which are
both B = 2.
3. On the other hand, the AR(2) process Y(t) = (1/2)Y(t − 1) + (1/2)Y(t − 2) + W(t) is
not stationary. This is left as an exercise for the reader.
For the AR(1) model, Y(t) = qY(t − 1) + W(t), the first two moments are μ(t) = 0 and
covariance function with lag k = 1, 2, …,
g k = qk s 2 = 1 − q2 , (9.37)
and with autocorrelation function
rk = qk , jqj < 1: (9.38)
It is obvious from Equation 9.38 that the autocorrelations are nonzero and decay expo-
nentially with k. Another important second-order property of the AR(p) process is the
partial correlation function at lag k, which is the correlation that results after removing the
effects of correlations of terms with lags less than k.
R Code 9.7 is given on page 81 of Cowpertwait and Metcalfe,11 which executes 100 values
from the AR(1) process with autoregression coefficient q = :6. The autocorrelation function
is acf while that for the partial autocorrelation is pacf.
R Code 9.7
[Link](1)
y<-w<-rnorm(100)
for( t in 2:100) y[t]<-.6*y[t-1]+w[t]
time <- 1:100
plot(time,y)
acf(y)
pacf(y)
The first 50 values are labeled by the vector y = ( −0.62645381, −0.19222896, −0.95096599,
1.02470121, 0.94432850,
X
t=n
lðqjyÞ = ðt=2πÞn=2 exp −ðt=2Þ ½yðtÞ − qyðt − 1Þ2 , (9.39)
t=2
where y is the vector of observations y = (y(1), y(2), :::, y(n)) and jqj < 1. Suppose the prior
density of q is uniform
zðqÞ = 1,
and for t,
" #,
X
t=n X
t=n
where n = y(t)y(t − 1) y2 (t). This is the density of a t distribution with n − 1
t=2 t=2
degrees of freedom, mean of n, and precision of l = (n − 1)=c, where
" #2 ,
X
t=n
2
X
t=n X
t=n
c= y ðt Þ − yðtÞyðt − 1Þ y2 ðt − 1Þ :
t=1 t=2 t=2
X
t=n
y2 ðtÞ = 46:617288,
t=1
X
t=n
y2 ðt − 1Þ = 46:22491,
t=2
and
X
t=n
yðtÞyðt − 1Þ = 28:87423;
t=2
where fW(t), t > 0g is Gaussian white noise with variance s2, and then its mean is 0 and the
autocovariance function is
g ðkÞ = qk s2 = 1 − q2 , (9.42)
v~dgamma(.01,.01)
theta~dbeta(6,4)
tau[1:50,1:50]<-inverse(Sigma[,])
for(i in 1:50){Sigma[i,i]<-v/(1-theta*theta)}
for(i in 1:50){for(j in i+1:50){Sigma[i,j]<-
v*pow(theta,j)*1/(1-theta*theta)}}
for( i in 2:50){ for(j in 1: i-1){Sigma[i,j]<-v*pow(theta,i-
1)*1/(1-theta*theta)}}
}
list(theta=.6,v=1)
Queues and Time Series 403
TABLE 9.5
Posterior Analysis for AR(1) Process
Parameter Mean SD Error 2 /12 Median 97 1/2
> [Link]<-ar(y,method="mle")
> [Link]$order
[1] 1
The following command estimates the coefficient q via maximum likelihood as .52311:
> [Link]$ar
[1] 0.5231187
> [Link]$ar+c(-2,2)*sqrt([Link]$[Link])
( 0.3521863, 0.6940510).
Note the difference in the MLE of .523 compared to the posterior mean of .5993. Why the
difference? This is left as an exercise at the end of this chapter.
A model is linear if
where Y(t) is the observation of the dependent variable at time t; Xi (t) is the observation of
the ith independent variable at time t; and, finally, Z(t) is the error term at time t. The errors
Z(t), t = 1, 2, :::, n, are assumed to have mean of 0, have a constant variance, and are
autocorrelated. Our goal is to compute Bayesian inferences for the m regression coefficients
bi and the unknown parameters of the error process.
As a first example, consider the linear regression model
R Code 9.8
> [Link](1)
> u<-w<-rnorm(100,sd=10)
> for ( t in 2:100) u[t]<-.6*u[t-1]+w[t]
> time<-1:100
> y<-50+3*time+u
> plot(time, y)
Y=( 46.73546, 54.07771, 49.49034, 72.24701, 74.44328, 65.46129,
74.35106, 83.39388, 88.39414, 83.78260, 100.38737, 100.33086,
91.38611, 71.28467, 93.82011, 96.84273, 100.14373, 112.92460,
120.56697, 124.07920, 130.63729, 134.40374, 130.78789, 109.17922,
123.50579, 126.54219, 128.56736, 117.83289, 122.51823, 135.49036,
153.88101, 151.50073, 156.17715, 155.76824, 143.49035, 146.94426,
150.42366, 157.06106, 173.83689, 181.73389, 178.39510, 176.70344,
186.39170, 192.00165, 184.11343, 180.39311, 190.08168, 201.13434,
200.15714, 210.70536)
A plot of the simple linear regression-dependent variables versus time over 50 days
appears in Figure 9.9, and the linear trend is obvious. What is the posterior mean of the
intercept, slope, and autocorrelation?
It appears that the observation begins at 50 starting at time 0.
A goal of the Bayesian analysis is to estimate the regression coefficient and the auto-
correlation q. In the statements of WinBUGS Code 9.9, beta0 is the intercept and beta1 is the
slope of the regression model with autocorrelation theta. The 20 observations is a vector
with a multivariate normal distribution with mean vector consisting of 20 values of 50 + 3t,
t = 1, 2, …, 20, and a 20 × 20 precision matrix, which is the inverse of the variance–
covariance matrix with components specified by Equation 9.42, the variance–covariance
matrix of an AR(1) error process.
Queues and Time Series 405
350
300
250
200
y
150
100
50
0 20 40 60 80 100
Time
FIGURE 9.9
Simple linear regression with autocorrelated errors.
for( i in 1:20){mu[i]<-beta0+beta1*i}
tau[1:20,1:20]<-inverse(Sigma[,])
for(i in 1:20){Sigma[i,i]<-v/(1-theta*theta)}
for(i in 1:20){for(jin i+1:20){Sigma[i,j]<-
v*pow(theta,j)*1/(1-theta*theta)}}
for(i in 2:20){ for(j in 1: i-1){Sigma[i,j]<-v*pow(theta,i-
1)*1/(1-theta*theta)}}
}
TABLE 9.6
Posterior Analysis for Regression Model
Parameter Value Mean SD Error 2 1/2 Median 97 1/2
The posterior analysis for the AR(1) regression model appears in Table 9.6.
The second column is the value of the parameter used to generate the independent
variable of the regression model, and it appears that there is good agreement between those
values and the posterior means. For example, the posterior mean of the slope b1 is 3.483
compared to the value 3 used to generate the data, and all 95% credible intervals do include
the values employed to generate the data.
Our next example is taken from pages 101–105 of Cowpertwait and Metcalfe11 and
concerns a model with trend and seasonal effect where the data are based on the model
where W(t) are autocorrelated with coefficients q = :6 and s2 = :25, and n = 120. Note that
the model is a linear model with a quadratic trend and seasonal effects represented by
sinusoidal waves with very small amplitudes and frequencies of 1, 2, and 3 cycles per unit
time. R Code 9.9 generates 120 values for the dependent variable given by Equation 9.46,
and these are in the list statement of WinBUGS Code 9.10.
R Code 9.9
[Link](1)
time<- 1:(10*12)
w<-rnorm(10*12, sd=.5)
Trend<- 0.1+.005*time+.001*time^2
Seasonal<- sin(2*pi*time/12)+0.2*sin(2*pi*2*time/12)+
0.1*sin(2*pi*4*time/12)+0.1*cos(2*pi*4*time/12)
x<-Trend+Seasonal+w
where bi , i = 0, 1, :::, 6, are unknown regression coefficients and W(t) is a sequence of errors
which are correlated. The Bayesian analysis is based on the 30 values of the dependent
variable of the model in Equation 9.46, and the goal is to estimate the bi , i = 0, 1, :::, 6, the
autocorrelation coefficient q, and variance s2 . WinBUGS Code 9.10 is executed with 45,000
observations for the simulation and 5,000 for the burn-in. Note that the vector of 30
observations is specified as a multivariate normal distribution with 30 × 1 mean vector
Queues and Time Series 407
(Equation 9.46) and precision matrix t, which is the inverse of the variance–covariance
matrix of an AR(1) process with correlation q. The parameters of the model are given
noninformative prior distributions. See WinBUGS Code 9.10 for the specifications.
theta~dbeta(6,4)
v~dgamma(.001,.001)
Y[1,1:30]~dmnorm(mu[],tau[,])
for( t in 1:30){
mu[t]<-beta0+beta1*t+beta2*t*t+beta3*sin(2*3.1416*t/12)
+beta4*sin(4*3.1416*t/12)+beta5*sin(8*3.1416*t/12)+
beta6*cos(8*3.1416*t/12)}
#Sigma is the variance covariance matrix of an AR(1)
tau[1:30,1:30]<-inverse(Sigma[,])
for(i in 1:30){Sigma[i,i]<-v/(1-theta*theta)}
for(i in 1:30){for(j in i+1:30){Sigma[i,j]<-
v*pow(theta,j)*1/(1-theta*theta)}}
for( i in 2:30){ for(j in 1: i-1){Sigma[i,j]<-v*pow(theta,i-
1)*1/(1-theta*theta)}}
}
list(Y =structure(.Data=c( 0.50258072, 1.10844961, 0.80618569,
1.66306326, 0.50494626, -0.14423419, 0.13752215, -0.25626051,
-0.38610932, -0.90532214, 0.22208296, 0.59892162, 0.73318733,
0.16127800, 2.06246546, 1.14295606, 0.65609725, 1.08591811,
0.67641822, 0.06752780, 0.20548869, 0.08244021, -0.02852513,
-0.09867585, 1.86972050, 1.78056357,
1.98610225,.01804667,1.03711735,1.45897078),.Dim=c(1,30)))
list(
theta=.6,v=.25,beta0=.1,beta1=.1,beta2=.2,beta3=.2,beta4=.2,beta5=.2,
beta6=.1)
The posterior analysis for the model with quadratic trend and seasonal effects is reported
in Table 9.7.
The values used to generate the data are listed in the second column and should be com-
pared to their corresponding posterior means. For example, the value of b3 used for the
408 Bayesian Inference for Stochastic Processes
TABLE 9.7
Posterior Analysis for Seasonal Effects
Parameter Value Mean SD Error 2 1/2 Median 97 1/2
simulation is 1 compared to its posterior mean of 0.7606 and 95% credible interval of
(.4304,1.09), which indeed includes 1! The posterior mean for s2 is very close to its nominal
value of 0.25 used to generate the data, and its 95% credible interval does indeed include .25!
where, b0 and b1 are unknown parameters, and the residuals Z(t) on the log scale form an
AR(1) process with autocorrelation q. R Code 9.10 is taken from pages 113 and 114 of
Cowpertwait and Metcalfe11 and generates 100 observations from the nonlinear model with
b0 = 1, b1 = :05, q = 0:6, and s = 2.
R Code 9.10
[Link](1)
w<-rnorm(100,sd =2)
z<-rep(0,100)
for ( t in 2:100) z[t]<-0.6*z[t-1]+w[t]
Time<-1:100
f<- function(x) exp(1+0.05*x)
x<-f(Time)+z
The first 50 values of the simulation R Code 9.10 appear as components of the vector y:
The Bayesian analysis is based on 30 observations generated by R Code 9.10 and will
focus on the estimation of the unknown parameters b0 , b1 , q, and s2 and is executed with
WinBUGS Code 9.11 using 35,000 observations for the simulation and 5,000 for the burn-in.
The 30 observations are the components of a vector Y, which has a multivariate normal
distribution with mean vector given by Equation 9.48 and precision matrix, which is the
inverse of the variance–covariance matrix of an AR(1) process with correlation q.
TABLE 9.8
Posterior Analysis for Nonlinear Model
Parameter Value Mean SD Error 2 1/2 Median 97 1/2
b0 1 1.407 .1794 .00945 1.021 1.41 1.757
b1 .05 .0327 .0077 .00040 .0170 .0328 .0484
q .6 .6349 .1513 .00269 .3218 .6455 .891
s2 4 2.449 1.056 0.01645 0.8932 2.303 4.932
410 Bayesian Inference for Stochastic Processes
example s2 , with a posterior mean of 2.449, which is also very close to its nominal value of 4.
What about the other parameters?
½Yðt1 Þ, Yðt2 Þ, :::, Yðtn Þ ∼ ½Yðt1 + hÞ, Yðt2 + hÞ, :::, Yðtn + hÞ (9.49)
where W(t), W(t − 1), :::, W(t − q) is a sequence of independent white noise random variables
with variance s2 ; and the bi , i = 1, 2, :::, q, are unknown real parameters. It is obvious that
the mean value function of the process is 0, the variance is
i=q
!
2
X 2
Var½YðtÞ = s 1+ bi , (9.51)
i=1
i=q−k
X i=q
X
rðkÞ = bi bi+k = b2i : (9.52)
i=0 i=0
where b1 = :8 and s2 = 1.
Queues and Time Series 411
R Code 9.11 generates 1000 observations from the MA(1) process (Equation 9.53):
R Code 9.11
[Link](1)
b<-c(.8)
x<-w<-rnorm(1000)
for ( t in 2:1000){
for ( j in 1:1) x[t]<-w[t]+b[j]*w[t-j]}
Based on these 20 values, the Bayesian analysis will estimate the parameters of the MA(1)
process (Equation 9.53), and the posterior analysis is executed with WinBUGS Code 9.12
with 35,000 observations for the simulation and a burn-in of 5,000. Noninformative prior
distributions are used for the following parameters: b1 is normal(.8,.01), and that for s2 it is
gamma(.001,.001). Note that it is assumed that the data vector of 20 observations has a
multivariate normal distribution with mean vector of 0, and a variance–covariance matrix is
given by Equations 9.51 and 9.52, respectively.
for( t in 1:20){mu[t]<-0}
Y[1,1:20]~dmnorm(mu[],tau[,])
for( i in 1:20){Sigma[i,i]<-v*(1+pow(beta,2))}
for ( i in 1:19){Sigma[i,i+1]<-v*beta}
for ( i in 1:18){for ( j in i+2: 20) {Sigma[i,j]<-0}}
for ( i in 2:20){Sigma[i,i-1]<-v*beta}
for( i in 3:20){ for ( j in 1:i-2 ){Sigma[i,j]<-0}}
tau[1:20,1:20]<-inverse(Sigma[,])
}
list(Y=structure(.Data=c(-0.626453811, -0.317519724, -0.688713953,
0.926777912, 1.605732414, -0.556862167, -0.168945655,
1.128267947, 1.166441116, 0.155236694, 1.267470459,
1.599268171, -0.309365991, -2.711692352, -0.646828992,
0.855011125, -0.052137150, 0.930884000, 1.576290164,
1.250878277),.Dim=c(1,20)))
list(v=1, beta=.8)
412 Bayesian Inference for Stochastic Processes
TABLE 9.9
Posterior Analysis for MA(1) Process
Parameter Value Mean SD Error 2 1/2 Median 97 1/2
The posterior analysis for the MA(1) process is reported in Table 9.9.
Note that the posterior 95% credible intervals for the parameters include the values of the
parameters used to generate the 20 observations used for the data and in the list statement
of WinBUGS Code 9.12. Additional details of the posterior analysis for the MA(1) process is
left as several exercises for the student.
Before leaving the MA model, the MA(1) process will serve as errors for a regression
model
R Code 9.12
[Link](1)
b<-c(.8)
y<-x<-w<-rnorm(20)
for ( t in 2:20)
{for ( j in 1:1) x[t]<-w[t]+b[j]*w[t-j]}
{for( t in 1:20)y[t]<-1+2*t+3*t^2+x[t]}
Y=( 5.373546, 16.682480, 33.311286, 57.926778, 87.605732,
120.443138, 161.831054, 210.128268, 263.166441, 321.155237,
387.267470, 458.599268, 533.690634, 614.288308, 705.353171,
801.855011, 901.947863, 1009.930884), 1123.576290, 1242.250878)
Of course, the goal of the Bayesian analysis is to estimate the unknown regression
parameters g i , i = 1, 2, 3, the moving average coefficient b, and Gaussian noise variance s2 .
Using the above 20 values generated by R Code 9.12 according to the model in Equations
9.54 and 9.55, WinBUGS Code 9.13 is executed with 35,000 observations for the simulation
and 5,000 for the burn-in. The vector Y of 20 observations are normally distributed with
mean vector given by Equation 9.54 and variance–covariance matrix appropriate to the MA
(1) errors with moving average parameter b.
WinBUGS Code 9.13
model;{
beta~dnorm(.8,1)
v~dgamma(.1,.1)
Queues and Time Series 413
g0~dnorm(1,1)
g1~dnorm(2,1)
g2~dnorm(3,1)
for( t in 1:20){mu[t]<-g0+g1*t+g2*t*t}
Y[1,1:20]~dmnorm(mu[],tau[,])
for( i in 1:20){Sigma[i,i]<-v*(1+pow(beta,2))}
for ( i in 1:19){Sigma[i,i+1]<-v*beta}
for ( i in 1:18){for ( j in i+2: 20) {Sigma[i,j]<-0}}
for ( i in 2:20){Sigma[i,i-1]<-v*beta}
for( i in 3:20){ for ( j in 1:i-2 ){Sigma[i,j]<-0}} tau[1:20,1:20]<-
inverse(Sigma[,])
}
list(Y=structure(.Data=c(5.373546, 16.682480, 33.311286,
57.926778, 87.605732, 120.443138,161.831054, 210.128268,
263.166441, 321.155237, 387.267470, 458.599268, 533.690634,
614.288308, 705.353171, 801.855011, 901.947863, 1009.930884,
1123.576290, 1242.250),.Dim=c(1,20)))
list(v=1, g0=1,g1=2,g2=3, beta=.8)
where
TABLE 9.10
Posterior Analysis for Regression Model with MA(1) Errors
Parameter Value Mean SD Error 2 1/2 Median 97 1/2
b 0.8 1.184 0.5182 0.01273 0.375 1.182 2.318
g0 1 0.9514 0.733 0.02000 −0.4733 0.9477 2.393
g1 2 2.026 0.1849 0.00681 1.622 2.029 2.381
g2 3 3.001 0.0093 0.00033 2.982 3.001 3.018
s2 1 0.7069 0.411 0.00804 0.1643 0.637 1.679
414 Bayesian Inference for Stochastic Processes
R Code 9.13
[Link](1)
b<-c(.8)
y<-x<-w<-rnorm(100,0,.1)
for ( t in 2:100){
for ( j in 1:1) x[t]<-w[t]+b[j]*w[t-j]}
{for( t in 1:100)y[t]<-1+sin(2*pi*t/12)+0.2*sin(4*pi*t/12)+0.1*sin(8*pi*t
/12)+0.1*cos(8*pi*t/12)+x[t]}
The 100 values generated from the harmonic seasonal regression model are contained in
the vector Y:
Based on the first 20 values generated from the regression model with harmonic seasonal
effect, and using noninformative priors for the regression coefficients g i , i = 0, 1, 2, 3, 4,
moving average parameter b, and variance of the Gaussian noise s2 , the Bayesian analysis is
executed with WinBUGS Code 9.14 using 35,000 observations for the simulation and 5,000
for the burn-in.
g1~dnorm(0,.01)
g2~dnorm(0,.01)
g3~dnorm(0,.01)
g4~dnorm(0,.01)
v~dgamma(.01,.01)
beta~dbeta(8,2)
for( t in 1:20){mu[t]<-g0+g1*sin(2*3.1416*t/12)+g2*sin(4*3.1416*t/
12)+g3*sin(8*3.1416*t/12)+g4*cos(8*3.1416*t/12)}
Y[1,1:20]~dmnorm(mu[],tau[,])
for( i in 1:20){Sigma[i,i]<-v*(1+pow(beta,2))}
for ( i in 1:19){Sigma[i,i+1]<-v*beta}
for ( i in 1:18){for ( j in i+2: 20) {Sigma[i,j]<-0}}
for ( i in 2:20){Sigma[i,i-1]<-v*beta}
for( i in 3:20){ for ( j in 1:i-2 ){Sigma[i,j]<-0}}tau[1:20,1:20]<-
inverse(Sigma[,]
}
list(Y=structure(.Data=c(1.647162240, 1.870875972, 2.031128605,
1.822100655, 1.350765620, 1.044313783, 0.692913056, 0.283403931,
0.216644112, 0.012895725, 0.316939425, 1.259926817, 1.678871022,
1.631458709, 2.035317101, 1.814923976, 1.184978664, 1.193088400,
0.867436637, 0.295664964),.Dim=c(1,20)))
list( g0=1,g1=1,g2=.2,g3=.1,g4=.1,beta=.8,v=.01))
Table 9.11 reports the results of the posterior analysis for the regression model with
moving average errors.
Comparing the actual values of the parameters to their corresponding posterior means
reveals that the estimates are very close. In fact, the 95% credible intervals contain the actual
values of the parameters used to generate the data in the list statement of WinBUGS Code
9.14, the sample information used for the Bayesian analysis.
One way to generalize the moving average and autoregressive processes is to combine the
two into the ARMA(p,q) process defined as
i=p
X j=q
X
Y ðt Þ = ai Yðt − iÞ + W ðtÞ + bj W ðt − jÞ, (9.58)
i=1 j=1
TABLE 9.11
Posterior Analysis for Harmonic Seasonal Effects with MA(1) Errors
Parameter Value Mean SD Error 2 1/2 Median 97 1/2
b .8 .7756 .1064 .00047 .5367 .7862 .9542
g0 1 1.046 0.039 0.00016 0.9682 1.046 1.124
g1 1 0.9134 0.0533 0.00021 0.8077 0.9132 1.019
g2 .2 .1414 .0475 .00018 .0475 .1413 .2363
g3 .1 .1043 .0273 .00010 .0500 .1043 .1589
g4 .1 .0946 .0284 .00011 .0382 .094 .1511
s2 .01 .0094 .0040 .00002 .0044 .0085 .0196
416 Bayesian Inference for Stochastic Processes
R Code 9.14
[Link](1)
x<-[Link](n=10000, list(ar=.5,ma=0.5))
coef(arima(x, order =c(1,0,1)))
The first 24 observations from the ARMA (1,1) process are the components of the vector Y:
Based on the preceding sample information and prior information for the unknown
parameters b, q, and s2 , the Bayesian analysis is executed with 35,000 observations for the
simulation and a burn-in of 5,000.
Queues and Time Series 417
Bayesian inferences for the parameters of the ARMA(1,1) model are reported in Table 9.12.
Comparing the posterior means to the actual value of the parameter reveals that the
Bayesian analysis is providing sound inferences. For example, consider b with actual value
of .5 and posterior mean of .4979, then one would conclude that indeed, the Bayesian
analysis is quite accurate, at least in this case.
TABLE 9.12
Posterior Distribution for ARMA(1,1)
Parameter Value Mean SD Error 2 1/2 Median 97 1/2
9.5 Exercises
8. Refer to Section 9.3.1 and write a two-page essay on the Bayesian inferences used
in time series analysis.
9. Using R Code 9.2
a. Duplicate Figure 9.2, a plot of the monthly airline passenger data for 12
years.
b. Using R Code 9.3., duplicate Figure 9.3, a plot of the aggregation of the
monthly airline passenger data.
10. Refer to Section 9.3.3.
a. Describe the trend, seasonality, and errors of a time series.
b. Using the R Code command plot(decompose(AirPassengers)), duplicate
Figure 9.5, a plot of the decomposition of the airline passenger data.
11. Given a time series, define the mean value function, the variance function, and the
autocorrelation function. See Equations 9.23 and 9.24.
12. a. Duplicate the plot of the Nile River level information in Figure 9.6.
b. Verify the acf plot of the Nile River data portrayed in Figure 9.7.
c. What is the lag 1 and lag 2 autocorrelations?
13. a. Define the AR(p) model.
b. For an AR(1) model, what is the autocorrelation function?
c. Given a uniform prior density for q, jqj < 1, derive the posterior distribution
q given by Equation 9.40.
d. Using WinBUGS Code 9.8, execute the Bayesian analysis for the AR(1)
model with 35,000 for the simulation and 5,000 for the burn-in.
e. Verify the posterior analysis of the AR(1) model reported in Table 9.8. What
is the posterior median of q? Does the 95% credible interval for q include the
value .8?
14. Refer to the regression model with autocorrelated errors defined by Equation 9.44
and consider the simple linear regression model with AR(1) errors of Equation
9.45.
a. Use R Code 9.8 to generate 100 observations from the regression model
(Equation 9.45), where q = :5 and s = 10.
b. Based on these 100 observations generated with R Code 9.8, execute a
Bayesian analysis using WinBUGS Code 9.8 with 45,000 observations for the
simulation and 5,000 for the burn-in.
c. Verify the posterior analysis of Table 9.6.
d. What is the 95% credible interval for b1 ?
Queues and Time Series 421
15. Refer to Equation 9.46, a regression model with quadratic effects for trend and
including harmonic seasonal effects with q = :6 and s = 0:5.
a. Use R Code 9.9 to generate 120 observations from Equation 9.46.
b. Using WinBUGS Code 9.10, perform a Bayesian analysis to estimate the
parameters of the model in Equation 9.47.
c. What prior distributions are used for the parameters of this regression
model (Equation 9.47)?
d. What is the mean vector and covariance matrix of the 30 × 1 vector of
observations?
e. Verify the posterior analysis reported in Table 9.7. What is the posterior
median of b3 ?
16. a. Refer to Equation 9.50 and define an MA(q) process.
b. Derive the autocorrelation function (Equation 9.52) of an MA(q) process.
c. Use R Code 9.11 to generate 1000 observations from an MA(1) process with
parameters b = :8 and s2 = 1.
d. Using the first 20 observations generated by R Code 9.11, execute the
Bayesian analysis given by WinBUGS Code 9.12 with 35,000 observations
for the simulation and 5,000 for the burn-in.
e. Verify the Bayesian analysis of Table 9.9.
f. What is the posterior mean of b and is it reasonable?
17. a. Define an ARMA(p,q) time series.
b. For an ARMA(1,1) model with parameters q, b, and s2 , derive the auto-
correlation function in Equation 9.61.
c. Use R Code 9.14 to generate 10,000 observations from an ARMA(1,1)
process with q = :5, b = :5, and s2 = 1.
d. Based on the first 24 observations generated by R Code 9.14, use WinBUGS
Code 9.15 to execute a Bayesian analysis with 45,000 observations for the
simulation and burn-in of 5,000.
e. What prior distributions are used for the Bayesian analysis?
f. What is the posterior mean of b?
g. What is the 95% credible interval for q?
422 Bayesian Inference for Stochastic Processes
References
1. Insua, D. R., Ruggeri, F., and Wiper, M. P. 2012. Bayesian Analysis for Stochastic Process Models.
New York: John Wiley & Sons.
2. Little, J. D. C. 1961. A proof of the queuing formula L = lW. Operations Research 9:383–387.
3. Gross, D., Shortle, J. F., Thompson, J. M., and Harris, C. M. 2008. Fundamentals of Queuing Theory,
Third Edition. New York: John Wiley & Sons.
4. Ausin, M. C., and Lopes, H. 2007. Bayesian estimation of ruin probabilities with heterogeneous
and heavy-tailed insurance claim size distribution, Australian and New Zealand Journal of Statistics
49:415–452.
5. Wiper, M. P. 1998. Bayesian analysis of Er/M/1 and Er/M/c queues, Journal of Statistical Planning
and Inference 69:65–79.
6. Broemeling, L. D. 1984. Bayesian Analysis of Linear Models. New York: Marcel Dekker.
7. Smith, J. O. 1987. A generalization of Bayesian steady forecasting model, Journal of the Royal
Statistical Society, Series B 41(3):375–387.
8. Pole, A., West, M., and Harrison, J. 1994. Applied Bayesian Forecasting and Time Series Analysis. Boca
Raton, FL: Chapman and Hall.
9. Barber, D., Cemgil, A. T., and Chippa, S. (Editors). 2011. Bayesian Time Series Models. Cambridge,
UK: Cambridge University Press.
10. Petris, G., Pertrone, S., and Campagnoli, P. 2009. Dynamic Linear Models. New York: Springer-
Verlag.
11. Cowpertwait, P., and Metcalfe, A. V. 2008. Introduction to Time Series Analysis with R. New York:
Springer-Verlag.
Index
A overview, 35–36
posterior information, 42–46
Abscissa for spatial Poisson, 248t binomial distribution, 42
Absorbing states, Markov chain, 121, 163–166 normal distribution, 43–44
Accessibility, particular state, 146–154 Poisson distribution, 44–46
irreducible chains, 148–150 predictive inference, 55–59
overview, 146–148 binomial population, 55–57
transient and recurrent states, 150–154 forecasting for normal population, 57–59
Accident rates overview, 55
for intersections, 257, 258 prior information, 38–42
posterior distribution for, 254–255 binomial distribution, 38–41
Adenine, 13–14, 205–212, 219, 295–308 normal distribution, 41–42
Alleles, defined, 5, 173 for time reversibility of social mobility, 159
Alternative hypothesis Bayesian inferences
positive probability for, 140–141 DTMC, see Discrete-time Markov
posterior probability, 162 chain (DTMC)
predictive mass function under, 209 Markov chains
prior density, 246, 298 in biology, see Markov chains in biology
prior probability, 162, 297, 298, 344, 359 in continuous time, see Continuous-time
Aperiodic chain, 120, 158, 291 Markov chains (CTMCs)
ARMA (moving average and autoregressive) methods, for Gaussian processes, 17–23
process, 28, 29, 30, 32, 33t, 415–417 normal processes, see Normal processes,
Autocorrelated errors, simple linear Bayesian inferences for
regression with, 405–406 queues, see Queuing models
Autocorrelation, of time series, 392–395, 396 statistical fundamentals, 1–2
Autoregressive process (AR), 25–26, 27, time series, see Time series
399–410, 415–417 Bayes theorem
components, 35, 38–42
B overview, 1, 36–37
posterior Dirichlet distribution, 207
Backshift operator, defined, 399 Beta-binomial, defined, 56, 126
Backward Kolmogorov equation, 101, 288–289 Beta distribution, 1, 55, 122, 136, 207, 217
Bayes factor, 50, 51, 52 Biased coins, example of DTMC, 121–122
Bayesian analysis, 35–68 Binomial distribution
Bayes theorem, 36–37 posterior information, 42
checking model assumptions, 59–63 prior information, 38–41
multinomial assumption, testing, 62–63 Binomial population, 35, 39, 55–57
overview, 59–60 Birth process
Poisson population, 60–61 CTMC, 98–99, 101, 102–103
sampling from exponential defined, 218
distribution, 60 with immigration, 319–321
Wiener process, 61 logistic growth process, 190–191, 192, 194
computing algorithms, 63–68 Markov chains in biology, example,
MCMC technique, 64–68 184–190
overview, 63–64 Poisson process, 9
for earthquakes in Italy, 243, 244t time reversibility, 308–315
inference, 47–55 Birth rates, thinning and superposition, 239–241
estimation, 49–50 Black–Scholes model, 22, 23, 360, 361, 363
overview, 47–49 Brownian bridge, 17, 21, 331, 350–351, 356–359,
testing hypotheses, 50–55 367
423
424 Index
A Poisson process is a specific type of renewal process where the times between events, known as interarrival times, are exponentially distributed. In contrast, a general renewal process can involve any distribution for these interarrival times, not limited to the exponential. The Poisson process is characterized by having stationary increments and independent increments, which makes it suitable for modeling random events occurring continuously and independently over time. It is commonly utilized in contexts like modeling the number of occurrences of a particular event within a fixed period, such as the arrival of customers. Unlike general renewal processes, the Poisson process simplifies both theoretical and practical analysis due to its specific mathematical properties .
Bayesian methods contribute significantly to estimating parameters in stochastic models by integrating prior knowledge with observed data. In models like Poisson or renewal processes, Bayes' theorem is used to update beliefs about model parameters as new data becomes available, providing a comprehensive framework for parameter estimation. For instance, if the observed data pertains to count data in a Poisson process, prior distributions for parameters such as the rate of occurrence can be updated to posterior distributions, reflecting evidence from the data. This leads to better predictions and decision-making in fields like queueing theory and reliability studies, where these models are often applied .
The key difference between a homogeneous Poisson process and a nonhomogeneous Poisson process lies in how the rate of occurrence, denoted by λ(t), varies over time. In a homogeneous Poisson process, λ(t) is constant, implying that events are equally likely to occur at any time. In contrast, a nonhomogeneous Poisson process allows λ(t) to be a function of time, meaning the event rate can increase or decrease over intervals, which models scenarios where occurrences are more or less likely during certain periods. This distinction is crucial for applications that require modeling dynamic and time-dependent phenomena, such as varying traffic patterns throughout a day or fluctuating arrival rates in seasonal contexts .
In a Markov chain, a state is classified as recurrent if it is expected to be revisited infinitely often, meaning from such states, the chain will eventually return no matter its current state. Conversely, a transient state may be visited a finite number of times before the chain moves to a recurrent state, never to return to the transient state. The classification between transient and recurrent states affects the chain's long-term behavior significantly; the chain will remain in recurrent states indefinitely after reaching them, which determines the steady-state or limiting distribution of the chain. This classification is crucial for predicting the chain's behavior over time and making decisions based on these predictions .
A stochastic process is a collection of random variables indexed by a parameter (e.g., time) from a certain set T, where each random variable assumes real values. When the index set T includes discrete intervals such as 0, 1, 2, etc., the stochastic process can model sequences like a random walk. A random walk is thus a specific type of stochastic process where the outcomes at different times are random but follow a joint probability distribution, often representing the independent evolutions of random steps like coin toss outcomes .
In Bayesian inference, the posterior distribution of interarrival times provides a probabilistic assessment of the time between customer arrivals within a queuing process. By analyzing the posterior distribution, managers can identify the most likely interarrival times and variability, facilitating data-driven decisions regarding resource allocation and service improvements. Understanding these times allows for optimizing personnel scheduling or infrastructure, predicting peak periods, or designing better customer service strategies. For example, if the posterior distribution indicates high variability, resources might be allocated to reduce waiting times and enhance service quality during anticipated congestion, improving overall efficiency and customer satisfaction .
Stationary independent increments imply that the increments of a Wiener process over different time intervals are not only independent but also identically distributed, having the same statistical properties regardless of when the interval occurs. This feature greatly simplifies mathematical modeling and analysis, as it ensures that past movements do not influence future paths, and future increments possess consistent variance scaling with time. Consequently, modeling becomes more straightforward, as properties hold irrespective of the starting point, making the Wiener process an ideal candidate for representing random continuous trajectories like financial assets or physical motion under random forces. It contrasts with non-stationary processes where statistical properties change over time, complicating predictions and analysis .
The Bayesian approach enhances the understanding of the gambler's ruin problem by providing a probabilistic framework to update beliefs about the parameters governing the process. By using observed data, Bayesian methods allow for estimating the average duration of a gambler's game until ruin or reaching a target wealth, incorporating prior distributions and observations to derive posterior distributions. This method adds robustness to parameter estimation and improves predictions of outcomes like duration of survival in games of chance, creating a comprehensive model that accounts for uncertainty directly. Such probabilistic inferences are crucial for effective decision-making in scenarios modeled by the gambler's ruin problem .
Independent increments are a fundamental property of Brownian motion, indicating that increments of the process over non-overlapping intervals are statistically independent. This characteristic is significant because it simplifies the mathematical treatment of Brownian motion, facilitating its analysis and simulation in modeling continuous random processes. Independent increments imply that past movements of the process do not influence future movements, aligning with the property of "memorylessness" observed in Brownian motion. This property is pivotal for applications requiring modeling of physical phenomena like diffusion or financial processes such as stock prices, where current fluctuations are independent of past paths .
Stationarity in a stochastic process implies that its statistical properties are time-invariant, which is a crucial assumption for many practical applications like communication theory, signal processing, astronomy, biology, and economics. In these fields, assuming stationarity often simplifies the analysis and modeling of processes, allowing for predictions and inferences under stable conditions. In economics, for instance, stationarity might involve analyzing fluctuations in financial markets assuming constant statistical properties over time, facilitating the use of historical data to predict future trends. Similarly, in astronomy, a stationary model might help in studying the time-invariant behavior of celestial phenomena .