Henson - Mathematical Modeling in Biology-Chapman and Hall - CRC (2023)
Henson - Mathematical Modeling in Biology-Chapman and Hall - CRC (2023)
in Biology
Mathematical Modeling in Biology: A Research Methods Approach is
a textbook written primarily for advanced mathematics and science
undergraduate students and graduate-level biology students. Although
the applications center on ecology, the expertise of the authors,
the methodology can be imported to any other science, including
social science and economics. The aim of this book, beyond being a
useful aid to teaching and learning the core modeling skills needed
for mathematical biology, is to encourage students to think deeply
and clearly about the meaning of mathematics in science and to
learn significant research methods. Most importantly, it is hoped that
students will experience some of the excitement of doing research.
Features
The right of Shandelle M. Henson and James L. Hayward to be identified as authors of this work
has been asserted in accordance with sections 77 and 78 of the Copyright, Designs and Patents
Act 1988.
All rights reserved. No part of this book may be reprinted or reproduced or utilised in any form
or by any electronic, mechanical, or other means, now known or hereafter invented, including
photocopying and recording, or in any information storage or retrieval system, without permission
in writing from the publishers.
For permission to photocopy or use material electronically from this work, access www.copyright.
com or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers,
MA 01923, 978-750-8400. For works that are not available on CCC please contact
[email protected]
DOI: 10.1201/9781003265382
Typeset in Minion
by codeMantra
To our parents
Audrey Gackenheimer Henson and
John William Henson III
Jane Watson Hayward and James Lloyd Hayward, Sr.
Contents
ACKNOWLEDGMENTS xvii
FOR PROFESSORS AND STUDENTS xix
AUTHORS xxi
vii
viii ■ Contents
3.5 LINEARIZATION 62
3.5.1 Linearization of Functions 62
3.5.2 Linearization of Discrete-Time Maps 64
3.5.3 Linearizing the Ricker Map 67
3.6 THE RICKER NONLINEARITY 70
3.7 EXERCISES 71
BIBLIOGRAPHY 74
Section V Appendix
Index 307
Acknowledgments
xvii
For professors and
students
xix
xx ■ For professors and students
xxi
I
Introduction to Modeling
1
CHAPTER 1
Mathematical Modeling
DOI: 10.1201/9781003265382-2 3
4 ■ Mathematical Modeling in Biology
ds
= −gt, (1.2)
dt
where s(t) is the distance traveled by the object. The differential
equation model (1.2) is a continuous-time model.
Some physical and biological processes are better described by
discrete-time models. For example, if each individual in a population
of annual plants produces b seeds per year, a fraction p of which
germinate, then the number of individual plants the next year is
Once the variables have been identified, they must be linked together
with equations. Constructing model equations always involves making
simplifying assumptions about the real system; for example, the object
is close to the surface of the planet; the force of gravity at the surface
of the planet is constant; gravity is the only force acting on the object
(no friction). Mathematical models do not perfectly describe the “real
world”; they are simplifications that capture the main mechanisms
driving the observed patterns. A major goal of modeling and the art of
modeling is to construct a simple, mechanistic, low-dimensional (few
state variables) model that describes enough of the observed variability
so that the leftover, “higher-order” variability is relatively small and
can be described statistically as noise (random effects). We can add
more and more mathematical complications (for example, the force due
to friction on the falling object) to a model in an attempt to make it
more realistic, but at some point the model becomes unwieldly and
intractable. There is little advantage in replacing a real system that is
too complicated to understand with a mathematical model that is too
complicated to understand. An important modeling mantra is therefore
KISS (keep it simple stupid). On the other hand, if the assumptions
oversimplify the problem, the mathematical model will not be able to
Mathematical Modeling ■ 7
1.2.1.3 Parameterization
whether the results correspond to extant data, and whether the model
can accurately predict new data. If not, then we will need to revise the
model and “go around the loop again” (Figure 1.1).
A good model not only describes and explains, but also predicts. The
best way to further test a validated model is to make a priori
predictions and then collect data to test those predictions. Ideally, the
predictions should be unusual or unexpected. A successful test of such
predictions makes a strong case that the model really does capture the
essential behavior of the system.
1.3 BIOLOGY
of the brain. Mathematical modeling may not be able to answer all the
interesting questions a biologist might ask.
Evolutionary biologists and population geneticists have long taken
advantage of mathematical modeling. This is because people like G. H.
Hardy, Sir Ronald Fisher, Sewell Wright, and J. B. S. Haldane, trained
in mathematics, turned their attention to solving biological problems.
Biologists in other subdisciplines have also discovered the power of
modeling.
At the most basic level, mathematical modeling provides biologists
with a way to qualitatively and quantitatively describe the behavior of
living systems. At a higher level, modeling provides a tool to identify
factors that drive living systems. Finally, once these factors have been
identified, biologists can test predictions about how these systems will
function in the future.
Our interest and experience concern ecological modeling. Because
many of the examples used in this book come from ecology, we now
provide a brief description of this subdiscipline.
1.3.1 Ecology
Ecologists are concerned with interactions among organisms and their
environments. Both organisms and environments are very complex;
moreover, they constantly undergo change. Ecologists thus face
significant challenges as they try to uncover ecological patterns.
An interesting challenge that faces all ecologists is the problem of
scale. Patterns apparent at one scale may disappear at higher or lower
levels of organization, and new patterns may emerge at these levels.
Patterns at some scales exhibit emergent properties. This is another
way of saying the whole often seems more than the sum of the parts—
qualities emerge at higher levels that might not be predicted on the
basis of the known properties of lower levels. Emergent properties are
not magical, however. They are the result of the properties of entities
at smaller scales and all of their interactions at the larger scale.
Ecologists view ecosystems as consisting of progressively more
inclusive scales:
1.4 MATHEMATICS
where the double arrow means “implies.” In words, if the inputs are
the same, then the outputs must be the same. Said another way, you
can’t get two different outputs from the same input. Algebra students
learn this as the “vertical line test.” Functions are deterministic. (By
contrast, a relation in which you can get two different outputs from
the same input is called stochastic; we will turn our attention to
stochasticity in the next section.)
In modeling dynamical systems, we are interested in the state of
the system (call it x) as a function of time t. That is, we are interested
in the behavior of x(t) as t changes. We can list the corresponding
values of x and t in a table, and we can also graph x vs. t. This list
of pairs of numbers (or its graph) is called a time series. You will
see many times series graphs in later chapters (e.g., Figures 4.2 and
8.2). If there are two state variables for the system of interest, say x(t)
and y(t), we must show two time series graphs together: x vs. t and
y vs. t.
In general, the two state variables x and y may be coupled, that
is, may depend on each other, so the two time series graphs must be
interpreted together. This is a visually difficult task. A better visual
tool in this case is that of state space, or phase space, in which the
state variables are graphed against each other in the x-y plane. The
current state of the system is represented by a point (x(t), y(t)) that
moves around in the plane as time progresses, tracing out an orbit.
You can see an example of orbits in a state space graph in Figure 9.1.
The arrows indicate the movement of the point (x(t), y(t)) in time.
Calculus provides us with many powerful tools for studying systems
whose state changes more or less continuously throughout time. The
main tool, of course, is the derivative dx/dt, which is the instantaneous
rate of change of x(t) with respect to time t.
14 ■ Mathematical Modeling in Biology
Here, N (t) is the population size at time t, and r, K > 0 are constant
parameters. A solution N (t) of the logistic model is a constant solution
if and only if it satisfies
dN
=0
dt
for all time t. Thus, the equilibria are the roots of the equilibrium
equation
Ne
0 = rNe 1 − ;
K
that is, the equilibria are
Ne = 0, K.
For a discrete-time example of equilibria, consider the plant
population model (1.3). A solution of this difference equation is a
constant solution Ne if and only if it satisfies
Nt+1 = Nt = Ne
for all time t. Thus, the equilibra are the roots of the equilibrium
equation (or fixed point equation)
Ne = pbNe .
1 dN
.
N dt
For example, suppose a population’s growth rate is proportional to
the square root of the population size N , and inversely proportional
to the temperature T . A mathematical model that describes this
system is √
dN N
=a .
dt T
For another example, suppose a population’s per capita growth rate
is inversely proportional to the square of the population size. A
mathematical model that describes this system is
1 dN a
= 2,
N dt N
that is,
dN a
= .
dt N
1.5 STATISTICS
Deterministic models are approximations of real systems; a good model
captures the signal (main deterministic trend) in the data. Neverthe-
less, the data likely will deviate somewhat from the model prediction.
This deviation from the signal is called noise or stochasticity. The
two main types of noise in biological data are process error and
measurement error (observational error ). The process error occurs
because the real system is more complicated than the mathematical
model. The measurement error occurs because the real system cannot
be measured exactly. Stochasticity in ecological data can be handled
with statistical methods, several of which will be addressed in this
book.
There are two main types of process error in ecology: environmental
stochasticity and demographic stochasticity. Stochastic events in a
population can be likened to the toss of a fair coin. Imagine that
Mathematical Modeling ■ 17
(PDF) is given by
1 1 x−µ 2
f (x) = √ e− 2 ( σ ) . (1.4)
σ 2π
Here, f (x) is not the probability of observing x birds. Rather, the
probability that the observational count X will fall between the values
a and b is the area under the normal curve that lies between the vertical
lines x = a and x = b; that is,
Z b
P [a ≤ X ≤ b] = f (x) dx.
a
The total area under the normal curve gives the probability that the
count lies between −∞ and +∞, which is, of course, equal to one.
Therefore, it must be true that (Exercise 10)
Z ∞
P [−∞ < X < +∞] = f (x) dx = 1. (1.5)
−∞
spread of the distribution about the mean µ. The square of the standard
deviation, σ 2 , is called the variance of the distribution.
You may have noticed that we have assumed X to be a continuous
random variable, while in the bird counting example, it is actually a
discrete random variable. That is, you can count only an integer number
of birds, while the normal distribution allows x to be any real number.
We could have used a bell-shaped histogram for the distribution
of a discrete random variable, but we often simplify problems with
continuous approximations.
Notice that if the first two statements are true, then we all agree
that the conclusion is guaranteed to be true. Deductive arguments are
conclusive. However, if one (or both) of the first two statements is false,
then the conclusion is not guaranteed to be true; it might be true or it
might be false.
Induction infers a general conclusion from a set of particular
statements or observations:
All the adult male northern cardinals I have observed are red.
Therefore, all adult male northern cardinals are red.
1.7 EXERCISES
1. Consider the population model
dx
= (b − d) x.
dt
dx
= 2x(1 − x)(2x − 4)2 .
dt
Find all the equilibria.
dx
= rx.
dt
Is the extinction equilibrium xe = 0 asymptotically stable,
neutrally stable, or unstable? Hint: Consider the cases r < 0,
r = 0, and r > 0 separately.
Mathematical Modeling ■ 25
12. Prove that the inflection points of the normal curve (1.4) occur
at x = µ ± σ.
13. Suppose you want to count a very large group of objects. Assume
the number of objects is fixed in time. There are so many objects
26 ■ Mathematical Modeling in Biology
25. Consider Figure 1.4. Can the epistemologies of the outer levels
ever be utilized legitimately at the inner levels? For example,
28 ■ Mathematical Modeling in Biology
BIBLIOGRAPHY
Levin, S. A. 1992. The problem of pattern and scale in ecology. Ecology
73:1943–1967. DOI: 10.2307/1941447. [Classic paper on scale in ecology,
presented as the Robert H. MacArthur Award Lecture in 1989 in Toronto,
Canada. Every student of ecology and mathematical biology should read
this paper.]
DOI: 10.1201/9781003265382-3 29
30 ■ Mathematical Modeling in Biology
2.2.1 Data
Gull chicks hatch in late June and early July on Protection Island.
Many chicks die from predation, overheating, and dehydration, or are
Avian Bone Growth: A Case Study ■ 31
x = Age in days
f (x) = Length of humerus in cm.
(A1a) The length of the humerus increases linearly with age until
the chick reaches some critical age, at which point the bone
abruptly ceases to grow.
K
b = 11.96923077.
intervals [0, 4] , [5, 9] , [10, 14] , . . . , [35, 39] , [40, 44] (Data Set 2.2).
Our goal is to randomly select half of the data from each bin.
4. Consider the random sequence for the first bin: 17, 12, 16, 2, 15,
8, 16, 13, 12, 6, 3, 3, . . . Put data point number 17 into data set I,
number 12 into data set II, number 16 into data set I, number 2
into data set II, number 15 into data set I, number 8 into data set
II, (skip over the 2nd occurrence of number 16), number 13 into
data set I, (skip over the 2nd occurrence of number 12), number
6 into data set II, etc. Skip over any random number that has
already occurred in the sequence. Do this for each bin. The data
are now divided into two sets (I and II as shown in Data Set 2.3).
Notice that if a bin had an odd number of data points, then data
set I will always have one more data point than data set II, which
is not a problem.
5. Flip a (two-sided) coin for Bin 1. “Heads” means data set I for
that bin goes into the estimation data; “tails” means it goes into
the validation data. Do this for each bin. Such a procedure yielded
the data sets in Data Set 2.4.
The data are now divided. The estimation and validation data are
graphed together in Figure 2.1. Make sure you can reconstruct Data
Set 2.4 from the original Data Set 2.1, given the sequences of random
numbers in Data Set 2.3 (Exercise 6).
Our next goal is to use the estimation data to estimate the
parameters (other than K). In what follows, we discuss two methods
for doing this.
38 ■ Mathematical Modeling in Biology
Figure 2.1: Estimation and validation data shown as length vs. age.
1 1 res 2
√ e− 2 ( σ ) .
σ 2π
Equation (2.8) is called the likelihood function. Note that for equation
(2.2), L is a function of three parameters, L(a, b, c). For simplicity,
we will continue to write L (a, b) in the explanation that follows. The
goal is to maximize L (a, b) as a function of the parameters a and b.
We want to find the maximizer, that is, the pair of parameters b a, bb
that maximizes the function L (a, b) . These maximizing parameters are
called the maximum likelihood (ML) parameter estimates.
Note that a maximizer for L will also be a maximizer for ln L, and
vice versa (Exercise 8). The properties of logarithms allow us to write
the log-likelihood function as (Exercise 9):
q 1 X 2
ln L (a, b) = −q ln σ − ln (2π) − 2 (res) . (2.9)
2 2σ
data
Thus, the ML parameter estimate b
a, bb is the parameter vector that
maximizes ln L (a, b) .
Model a
b b
b cb
A1a 0.2475 37.92 N/A
A1b 2.872 0.005402 1.661
The best way to understand all this is to work through sample code.
For codes similar to the ones you will write in the exercises concerning
the current example, see Appendix C.
Which of the two alternative models, (2.1) or (2.2), best describes the
data? The two models have different numbers of parameters. A curve
with many parameters is more flexible and easier to fit to data than
one with few parameters. Indeed, an overparameterized model can fit
just about any data, but has little explanatory power. Thus, the model
with more parameters should be penalized for overfitting. To do this,
Avian Bone Growth: A Case Study ■ 43
(a)
(b)
(c)
researchers often use a tool from information theory called the Akaike
information criterion (AIC) to select the best model (Burnham and
Anderson 2002). The AIC is defined as
AIC = − ln L
b + 2κ, (2.11)
44 ■ Mathematical Modeling in Biology
where Lb is the maximized value for the likelihood function and κ is the
number of estimated parameters in the model. Model comparison is
based on the rank of the AIC values for the suite of alternative models.
The least AIC indicates the best model. The first term in equation
(2.11) is smallest for the model with the largest likelihood, but this is
discounted by the second term, which is largest for the model with the
most parameters.
In our current example, the residuals are Gaussian with mean zero
and constant variance σ 2 . In such a situation, it is possible to show that
ranking the AIC values (2.11) is equivalent to ranking the values of
AIC* = q ln RSS
d + 2κ, (2.12)
Model q b2
σ κ AIC* ∆ AIC
A1a 40 0.005266 3 −203.9 0.0000
A1b 40 0.006106 4 −195.9 8.000
Avian Bone Growth: A Case Study ■ 45
where ϕ (lx ) denotes the mean of the transformed data. For our current
example, we have
P √ p 2
data lx − f (x)
R2 = 1 − P √ √ 2 ,
data lx − lx
√
where lx denotes the mean of the square roots of the humerus length
measurements.
Note that it is always true that R2 ≤ 1. The closer R2 is to one,
the better the model fit. Although R2 is usually between zero and one,
it can also be negative (Exercise 15).
The R2 values for model (2.13) on the two data sets are given
in Table 2.3 (Exercise 17). Successful validation is supported because
the R2 values are about the same. The predictions of model (2.13) are
shown in Figure 2.2a and c with the estimation and the validation data,
respectively. Visually, note that the model appears to fit the validation
data about as well as it fits the estimation data set upon which it was
parameterized.
2.7 EXERCISES
1. Work through the self-guided linear algebra tutorial in Appendix
A.
M x2
y= ; x ∈ [0, ∞); a, M > 0. (2.15)
a2+ x2
(K − b) x2
f (x) = + b.
a2 + x2
6. Make sure you can reconstruct Data Set 2.4 from the original
Data Set 2.1, given the sequences of random numbers in Data
Set 2.3. You don’t need to show any work for this problem, but
indicate whether or not you were successful in reproducing Data
Set 2.4.
13. Stochastic models are important for two reasons. First, they
are necessary for parameterization because they specify how the
residuals are distributed. Second, they can be used to simulate
the real (noisy) system. Write a program to produce a simulated
data set of humerus lengths using the stochastic model (2.14).
Avian Bone Growth: A Case Study ■ 49
N (t) = 3t − 7.
16. Reproduce all the values in Table 2.2. Attach your programs,
input files, and screen shots of your output.
18. If the residuals for each of the alternative models are independent
and Gaussian with mean zero and constant variance, prove that
ranking the AIC values from equation (2.11) is equivalent to
ranking the values of
AIC* = q ln RSS
d + 2κ,
(K − b) x2
f (x) = + b.
a2 + x2
Use the same binning procedure as in Data Set 2.2, and use the
same sequences of random numbers in Data Set 2.3, but work
through all the details. Present your work in a complete, precise,
and organized fashion.
a. Divide the humerus data in Data Set 2.1 into two sets: data
set AB (consisting of all the A and B chick data) and data
set C (consisting of all the C chick data).
b. Estimate the LS parameters for model (2.1) on the AB data
set. Record the parameter values and the RSS. Compute σb2
2
and R .
Avian Bone Growth: A Case Study ■ 51
BIBLIOGRAPHY
Burnham, K. P. and Anderson, D. R. 2002. Model Selection and Multi-Model
Inference: A Practical Information-Theoretic Approach, 2nd ed. Springer,
New York. [This is a practical, user-friendly book that shows scientists
how to make valid inferences from empirical data within an information-
theoretic framework.]
53
CHAPTER 3
Discrete-Time Maps
DOI: 10.1201/9781003265382-5 55
56 ■ Mathematical Modeling in Biology
Inflows are due to births and immigration. Outflows are due to deaths,
emigration, harvesting, etc. (Figure 3.1).
In general, compartmental models state that the net rate of change
of the quantity in a compartment is equal to the sum of its inflow rates
minus the sum of its outflow rates:
X X
Net rate of change = Inflow rates − Outflow rates.
∆xt+1 = xt+1 − xt .
Figure 3.1: Flows into and out of a population may be due to births,
immigration, deaths, and/or emigration.
Discrete-Time Maps ■ 57
produced seeds each autumn, and you wanted to track the population
size. The model time step might be one year, measured in the autumn
after the seeds were produced in order to take advantage of the natural
reproductive pulse in the system.
(A3) The only flows into or out of the population are due to births
and deaths.
We need a parameter for the per capita birth rate. Let
Since the per capita birth rate is b, the total population birth rate will
be b times the number of individuals in the population:
xt+1 − xt = bxt − xt
or simply
xt+1 = bxt . (3.3)
58 ■ Mathematical Modeling in Biology
That is, the population size at time t + 1 is the per capita birth rate b
times the population size xt at time t.
Suppose the number of individuals at time t = 0 is x0 = p ≥ 0.
The statement x0 = p is called the initial value or initial condition for
equation (3.3). The population size is therefore modeled by the initial
value problem corresponding to assumptions (A1)–(A3):
xt+1 = bxt
x0 = p.
The difference equation xt+1 = bxt is called linear because the state
variable x appears linearly in the equation.
Suppose a petri dish culture initially consists of ten cells, and that
each cell divides into two daughter cells every hour. Then p = 10 and
b = 2, so the culture can be modeled by the initial value problem
xt+1 = 2xt
x0 = 10,
x0 = 10 = 20 (10)
x1 = 2x0 = 21 (10)
x2 = 2x1 = 2 [2 (10)] = 22 (10)
x3 = 2 (2 [2 (10)]) = 23 (10)
..
.
xt = 2t (10) .
is (Exercise 4)
xt = pbt . (3.5)
Note that the extinction state x = 0 is an equilibrium of model (3.4),
since it satisfies the equilibrium equation
xe = bxe .
(A1) The average per capita birth rate is a constant b > 0 offspring
per individual per unit time.
(A3) The average per capita death rate is a constant d deaths per
individual per unit time, with 0 < d < 1.
(A4) The only flows into or out of the population are due to births
and deaths.
Then the population birth rate is bxt offspring per unit time and
the population death rate is dxt deaths per unit time. Thus,
or
xt+1 − xt = bxt − dxt .
We can write the model in several equivalent forms to aid in various
interpretations. For example, we can write
xt+1 = bxt + (1 − d) xt
New census = Recruits + Survivors.
xt+1 = (b + 1 − d) xt ,
that is,
xt+1 = rxt ,
where we define the new parameter r to be r = b + 1 − d. Note that
r > 0 since b > 0 and d < 1. This example is completed in Exercise 5.
(A1) The average per capita birth rate is a constant b > 0 offspring
per individual per unit time at low populations sizes (i.e., if there
are no crowding effects).
(A2) Because of crowding effects, the average per capita birth rate
is reduced by the factor e−cxt , where c > 0 quantifies the strength
of the crowding effect. (Note that 0 < e−cxt ≤ 1.)
By assumptions (A1) and (A2), the per capita birth rate in the
presence of xt individuals is be−cxt ; therefore, the population birth
rate is be−cxt xt offspring per unit time, and the model is
xt+1 = bxt e−cxt (3.6)
x0 = p
with parameters b, c > 0. Model (3.6) is the famous Ricker model ,
historically used in fisheries (Ricker 1954; Ricker 1975). It is called
nonlinear because the state variable x appears in a nonlinear way. This
simple deterministic model can have incredibly complex dynamics, as
we shall see in Chapter 4.
Let’s find the equilibrium states of the Ricker model. The
equilibrium equation is
xe = bxe e−cxe .
̸ 0. If we divide
Note that xe = 0 is a equilibrium solution. Suppose xe =
both sides by xe , we have
1 = be−cxe ,
which yields a nontrivial equilibrium solution xe = (ln b) /c.
It is often useful to graph the equilibria as a function of one of the
parameters. In this case, we graph the two equilibria xe = 0, (ln b) /c as
a function of b (Figure 3.2). Note that the nontrivial equilibrium xe =
(ln b) /c is positive if and only if b > 1. The value b = 1 at which the two
equilibrium branches cross is called a bifurcation value or bifurcation
point. The graph of xe vs b (Figure 3.2) is called a bifurcation diagram,
and b is called the bifurcation parameter.
A model such as xt+1 = bxt e−cxt is really a collection of infinitely
many models, one for each specific pair of values of b and c. When
looking at a bifurcation diagram such as Figure 3.2, one must remember
that any particular system has a fixed value of b, for example, b =
1.5. Its equilibria are given by the values of the equilibrium branches
directly above that specific value of b. Another way to say it is that
any particular system “lives on a vertical line” in Figure 3.2.
What are the stabilities of the two equilibria xe = 0, (ln b) /c of the
Ricker map? Do their stabilities depend on the value of b? Clearly, we
need to find a way to quantify and study stability in nonlinear maps.
To this end, we now turn to one of the most important subjects in
applied mathematics, the subject of linearization.
62 ■ Mathematical Modeling in Biology
Figure 3.2: Bifurcation diagram for the Ricker map shows the
equilibria xe as a function of the parameter b. The two equilibrium
branches are xe = 0 and xe = (ln b) /c. Here, c = 1.
3.5 LINEARIZATION
3.5.1 Linearization of Functions
Suppose f (x) is a function whose graph passes through the point
(a, f (a)). Close to the point (a, f (a)), we can approximate the graph of
f with its tangent line, that is, the line that is tangent to the graph of
f at the point (a, f (a)). What is the equation of this line? Recall that
the slope m of a line is the “rise over run.” Given a nearby point (x, y)
on the line (Figure 3.3), the rise from (a, f (a)) to (x, y) is y − f (a) ,
while the run is x − a. The slope is therefore
y − f (a)
m= ,
x−a
and so
y − f (a) = m (x − a) ,
which is the “point-slope” formula for a line from high school algebra.
From calculus, we know that the slope m of the line tangent to f
at the point (a, f (a)) is the derivative of f evaluated at x = a:
df
m= (a) .
dx
Discrete-Time Maps ■ 63
Figure 3.3: The equation of the tangent line at point (a, f (a)) is y =
f (a) + f ′ (a)(x − a).
df
= 3x2 − 8x + 7.
dx
Thus,
2
f (a) = f (2) = 23 − 4 (2) + 7 (2) − 1 = 5
and
df df 2
(a) = (2) = 3 (2) − 8 (2) + 7 = 3.
dx dx
Hence, the linearization of f at x = 2 is
df
y = f (2) + (2) (x − 2)
dx
= 5 + 3 (x − 2)
= 3x − 1,
f (x) ≈ 3x − 1 for x ≈ 2,
that is,
x3 − 4x2 + 7x − 1 ≈ 3x − 1 for x ≈ 2,
which is a neat result.
xt+1 = ax2t .
Discrete-Time Maps ■ 65
xt+1 = f (xt )
≈ xe + λ (xt − xe ) for xt ≈ xe ,
and hence
xt+1 − xe ≈ λ (xt − xe ) for xt ≈ xe . (3.9)
We can restate equation (3.9) in words: As long as the system is in
the neighborhood of the equilibrium, the displacement of the system
state from equilibrium at time t + 1 is approximately the number λ
times the displacement of the system from equilibrium at time t. That
is, xt+1 is about λ times as far from the equilibrium as xt was. You can
66 ■ Mathematical Modeling in Biology
see that if −1 < λ < 1, this is good news for the stability of equilibrium
xe , because the distance between the system state and the equilibri-
um is shrinking as time goes on—in fact, it appears that the equilibrium
xe would be asymptotically stable. If λ > 1 or λ < −1, however, the
distance between the system state and the equilibrium grows whenever
the system is near the equilibrium, and so it appears that xe would be
unstable.
We now clean up the notation a bit and state these observations in
a theorem. Define the displacement, or variation, of the system state
from equilibrium to be
z t = xt − x e . (3.10)
Using this as a change of variables, we can rewrite equation (3.9) as
Note that the change of variables (equation 3.10) simply shifts the
equilibrium to zero.
The equation
zt+1 = λzt for zt ≈ 0
is called the variation equation. The variation equation approximates
the dynamic change in displacement z when the system is close to its
equilibrium. Note that the variation equation is linear, and its solution
is
zt = z0 λt .
Thus, the displacement of the population from equilibrium grows or
decays exponentially when the population size is near its equilibrium
value. Whether the displacement grows or decays depends on whether
the eigenvalue λ is greater than or less than one in absolute value, that
is, whether |λ| > 1 or |λ| < 1.
zt+1 = λzt ,
where
df
λ= (xe ) .
dx
ln b
xe = 0 and xe = .
c
Let’s linearize the Ricker map about each of its equilibria. In both
cases, we will need the derivative of f with respect to x:
df
= be−cx (1 − cx) .
dx
68 ■ Mathematical Modeling in Biology
df
λ= (0) = be0 (1 − 0) = b,
dx
and so the linearization at xe = 0 is
zt+1 = bzt .
zt+1 = (1 − ln b) zt ,
and so
ln b
|1 − ln b| < 1 =⇒ xe = is asymptotically stable (3.11)
c
ln b
|1 − ln b| > 1 =⇒ xe = is unstable.
c
In order to obtain simple conditions on b for stability, we need to do
the algebra necessary to remove the absolute values. Recall that
ln b
1 < b < e2 =⇒ xe = is stable (3.13)
c
ln b
0 < b < 1 =⇒ xe = is unstable
c
ln b
b > e2 =⇒ xe = is unstable.
c
Figure 3.4: Bifurcation diagram for the Ricker map showing stability
of equilibria. Dotted equilibrium branches are unstable (u); solid are
stable (s). Here, c = 1.
70 ■ Mathematical Modeling in Biology
Now let’s consider what happens during one time step of the model.
This time period is composed of m = 1/∆t successive times of duration
∆t. The probability that a juvenile survives all of the adults during this
time is the product
m
Y A Am
(1 − c∆t) = (1 − c∆t)
i=1
A/∆t
= (1 − c∆t) .
3.7 EXERCISES
1. Use inequalities (3.11) and (3.12) to obtain inequalities (3.13),
keeping in mind that b > 0.
a. How can the fecundity be 120.3? That is, what does 0.3
seeds mean?
b. Write down the population model (the initial value
problem).
c. Find the closed-form solution of the initial value problem.
d. Will the population grow or decline? Explain.
e. Is the extinction state stable or unstable?
f. According to the model, how many plants will there be at
year t = 5?
g. How many years will it take for the population to grow to
75 plants, according to the model?
h. How many years will it take for the population to double
its initial size, according to the model? This is called the
doubling time.
i. Explain why the doubling time in this model does not
depend on the initial population size.
xt+1 = (b + 1 − d)xt
x0 = p > 0,
b < d =⇒ lim xt = 0
t→∞
b > d =⇒ lim xt = ∞
t→∞
b = d =⇒ xt = p for all t.
bxt
xt+1 =
1 + cxt
x0 = p≥0 (3.16)
b, c > 0.
xt+1 = rxt (1 − xt )
0 < x0 < 1 (3.17)
0 < r < 4.
BIBLIOGRAPHY
Beverton, R. J. H. and Holt, S. J. 1957. On the dynamics of exploited
fish populations. Fishery Investigations (II) 19:1–533. [Introduces the
Beverton-Holt mathematical model.]
DOI: 10.1201/9781003265382-6 75
76 ■ Mathematical Modeling in Biology
and that
ln b
1 < b < e2 =⇒ xe = is stable
c
ln b
0 < b < 1 =⇒ xe = is unstable
c
ln b
b > e2 =⇒ xe = is unstable.
c
We summarized this information in a bifurcation diagram, shown again
here as Figure 4.1.
The equilibrium analysis of the Ricker map begs the question,
“What happens to solutions if b > e2 ?” For these values of
b, nonequilibrium solutions cannot equilibrate, for there are no
stable equilibria for them to approach. Some exploratory computer
simulations are in order.
Let c = 0.01 and x0 = 75. Let’s set b at various values and inspect
the resulting time series. Figure 4.2 shows the time series generated
for b = 0.5, b = 1.3, b = 3.6, and b = 5.7. If b = 0.5, solutions
Figure 4.2: Time series for the Ricker map with b = 0.5, 1.3, 3.6, 5.7.
In each case, c = 0.01.
Figure 4.3: Ricker time series for b = 8, 14, 14.6, 17. In each case,
c = 0.01.
Figure 4.4: Bifurcation diagram for the Ricker map with c = 0.01.
80 ■ Mathematical Modeling in Biology
Figure 4.5: Two time series of the Ricker map with b = 17 and c =
0.01. The solid curve has initial condition x0 = 75, and the dashed
curve has initial condition x0 = 75.1. The two solutions soon diverge,
showing sensitivity to initial conditions.
exploring them. Thus, we see from this example that complex results
do not necessary imply complex causes. Very simple rules can generate
extraordinarily complicated results.
4.5 EXERCISES
In this set of exercises, you will need a program that draws bifurcation
diagrams for discrete maps. An example is the freeware program E&F
Chaos (see bibliography entry for URL). Alternately, you can write
your own code (Exercise 1).
xt+1 = bxt (1 − xt )
0 < x0 < 1
0 < b<4
5. In this problem, you will use the computer to further explore the
bifurcation diagram of the Ricker model
BIBLIOGRAPHY
Costantino, R. F., Desharnais, R. A., Cushing, J. M., and Dennis, B.
1997. Chaotic dynamics in an insect population. Science 275:389–391.
DOI: 10.1126/science.275.5298.389. [“Announcement” paper heralding the
documentation of chaos in a laboratory insect population. A follow-up
paper gave the details. See Dennis et al. (2001) below. Both theoretical
and empirical: models connected to data.]
Gleick, J. 1987. Chaos: Making a New Science. Viking, New York. [This
popular book was a finalist for the Pulitzer Prize in 1987.]
Higher-Dimensional
Discrete-Time Models
∂f
= 2x + 0 + y 3 3x2
∂x
∂f
= 0 + 2y + x3 3y 2 .
∂y
If this is your first experience with partial derivatives, work a few
problems in a calculus book to get comfortable with them.
DOI: 10.1201/9781003265382-7 85
86 ■ Mathematical Modeling in Biology
The main idea in this chapter is to learn how to solve and analyze
linear systems, and then to apply those techniques to nonlinear systems
through the method of linearization.
The matrix
0 bp
M=
(1 − µJ ) (1 − µA )
or
This system is called linear because the equations are linear in the
state variables x1 , x2 , . . . , xn . It can be written as a matrix equation:
x1 (t + 1) a11 a12 ··· a1n x1 (t)
x2 (t + 1) a21 a22 ··· a2n x2 (t)
= .
.. .. .. .. ..
. . . . .
xn (t + 1) an1 an2 · · · ann xn (t)
x (t + 1) = Mx (t) ,
where
x1 a11 a12 ··· a1n
x2 a21 a22 ··· a2n
x = and M = .
.. .. .. ..
. . . .
xn an1 an2 · · · ann
f1 f2 · · · fn
x1 (t + 1) p1 0 · · · 0 x1 (t)
x2 (t + 1) x2 (t)
. .. ..
= 0 p2 . .
.. ..
. .
.
.. 0 . ..
xn (t + 1) 0
xn (t)
0 0 pn−1 pn
The matrix
f1 f2 · · · fn
p1 0 · · · 0
. .. ..
0 p2
M = .
.. . ..
. 0 0
0 0 pn−1 pn
is called a Leslie matrix . The birth rates are in the first row, while the
survivorships are on the subdiagonal.
92 ■ Mathematical Modeling in Biology
What are the equilibria of this system? The fixed point equations, or
equilibrium equations, are
x = 3x + 2y
.
y = 12 x + 3y
The first of these implies that y = −x. The second, however, implies
that y = −x/4. This is a contradiction unless x = y = 0. Thus, the
only equilibrium is the extinction state (xe , ye ) = (0, 0). Because the
given initial condition (x0 , y0 ) = (0, 2) is different from the equilibrium,
we know that the system is not initially at equilibrium, and so the
population size must change over time. How will it change? Will it tend
toward the extinction equilibrium? In order to answer this question, we
will find the closed-form solution of system (5.3).
Recall that the closed-form solution to the one-dimensional linear
difference equation
xt+1 = bxt
is
xt = cbt ,
where c is the initial condition. We might expect that the solution of
system (5.3) will be similar. Therefore, let’s look for nontrivial solutions
(solutions that are not constantly zero) of the form
xt = v1 λt (5.4)
t
yt = v2 λ ,
The proposed solution (5.4) is called the Ansatz , a German word for
“approach.” Because it is a noun in German, Ansatz is capitalized.
If we plug our proposed solution (5.4) into the dynamical system
(5.3), we arrive at the following equations:
(3 − λ) 2
1 = 0.
2 (3 − λ)
λ2 − 6λ + 8 = 0,
which is to say
(λ − 4) (λ − 2) = 0.
94 ■ Mathematical Modeling in Biology
Note that these last two equations are indeed multiples of each other;
their graphs in the v1 -v2 plane are coincident lines. Thus, there
are infinitely many solutions (v1 , v2 ) . However, these solutions are
constrained by the relationship
v1 = −2v2 .
Clearly, this system has the extinction state (x, y) = (0, 0) as a solution.
In fact, the only equilibrium is (0, 0) as long as the determinant of the
coefficient matrix is nonzero, that is, as long as
a b
̸= 0.
c d
xt = v1 λt (5.8)
t
yt = v2 λ ,
System (5.9) has the trivial solution (v1 , v2 ) = (0, 0). It has a
nontrivial solution (v1 , v2 ) if and only if the two equations in (5.9)
are coincident lines, if and only if
(a − λ) b
= 0,
c (d − λ)
that is, if and only if
λ2 − (a + d) λ + (ad − bc) = 0.
This last equation is called the characteristic equation. The solutions λ1
and λ2 of the characteristic equation are the eigenvalues for the system.
These are the values of λ for which the Ansatz (5.8) is a solution;
hence, these are the exponential growth rates of the system. For each
eigenvalue, we can find an associated eigenvector from system (5.9)
by plugging in the eigenvalue and finding a relationship between v1
̸ λ2 and v = (v1 , v2 )⊤ and w = (w1 , w2 )⊤ are linearly
and v2 . If λ1 =
independent eigenvectors associated with λ1 and λ2 , respectively, then
the general solution of system (5.7) written in vector form is
xt = c1 vλt1 + c2 wλt2 ,
where xt = (xt , yt )⊤ and c1 , c2 ∈ R. In component form, the general
solution is
xt = c1 v1 λt1 + c2 w1 λ2t
yt = c1 v2 λt1 + c2 w2 λt2 .
A given particular solution is found by plugging the initial conditions
into the general solution, solving for the constants c1 , c2 , and plugging
these back into the general solution.
x (t + 1) = Mx (t) ,
where
x1 a11 a12 ··· a1n
x2 a21 a22 ··· a2n
x = and M = .
... ... ..
. ...
xn an1 an2 · · · ann
(M−λI) v = 0
1. If all the eigenvalues are inside the unit circle in the complex
plane, that is, if |λi | < 1 for all i = 1, 2, · · · n, then the extinction
equilibrium is asymptotically stable and all solutions approach
the zero vector.
2. If any one of the eigenvalues is outside the unit circle, that is, if
|λi | > 1 for some i, then the extinction equilibrium is unstable.
The strong ergodic property tells us how the age classes are
distributed in the long run: If there is a simple dominant eigenvalue
λ1 , that is, an unrepeated eigenvalue λ1 such that |λ1 | > |λi | for every
̸ 1, then from equation (5.11) we have (Exercise 4)
i=
1
lim x (t) = c1 v1 .
t→∞ λt1
5.8.1 Linearization
Consider the two-dimensional nonlinear system
xe = f (xe , ye )
ye = g (xe , ye ) .
∂f ∂f
z = f (a, b) + (a, b) (x − a) + (a, b) (y − b) ,
dx ∂y
∂f ∂f
f (x, y) ≈ f (xe , ye ) + (xe , ye ) (x − xe ) + (xe , ye ) (y − ye )
dx ∂y
∂f ∂f
= xe + (xe , ye ) (x − xe ) + (xe , ye ) (y − ye )
dx ∂y
∂g ∂g
g (x, y) ≈ g (xe , ye ) + (xe , ye ) (x − xe ) + (xe , ye ) (y − ye )
dx ∂y
∂g ∂g
= ye + (xe , ye ) (x − xe ) + (xe , ye ) (y − ye )
dx ∂y
∂f ∂f
xt+1 ≈ xe + (xe , ye ) (xt − xe ) + (xe , ye ) (yt − ye )
dx ∂y
∂g ∂g
yt+1 ≈ ye + (xe , ye ) (xt − xe ) + (xe , ye ) (yt − ye )
dx ∂y
for xt ≈ xe and yt ≈ ye .
The change of variables
ut = xt − xe (5.13)
vt = yt − ye
xt+1 = f (xt , yt )
yt+1 = g (xt , yt )
102 ■ Mathematical Modeling in Biology
5.8.2 An Example
Let’s carry out a complete equilibrium stability analysis for the
nonlinear system
xt+1 = yt (5.14)
3
yt+1 = yt (1 − xt )
2
at each of its equilibria.
First, we find the equilibria by solving the fixed point equation
x = y
3
y = y (1 − x) .
2
The equilibria are (0, 0) and (1/3, 1/3) . Then we compute the Jacobian:
!
∂f ∂f
dx ∂y
J = ∂g ∂g
dx ∂y
0 1
= .
− 32 y 3
2 (1 − x)
At the equilibrium (0, 0), the Jacobian is
0 1
J (0, 0) = ,
0 32
Higher-Dimensional Discrete-Time Models ■ 103
ut+1 = vt
3
vt+1 = vt .
2
The eigenvalues of the linearized system are λ = 0, 3/2. Since λ = 3/2
is outside the unit circle in the complex plane (that is, |λ| > 1), the
(0, 0) equilibrium of the linearized system is unstable.
At the equilibrium (1/3, 1/3) , the Jacobian is
0 1
J= ,
− 21 1
ut+1 = vt
1
vt+1 = − ut + vt .
2
1
The eigenvalues of this linear system are λ = ± 12 i, which are both
2q
1 2
2
inside the unit circle in the complex plane since |λ| = 2 + 12 =
√
2
2 < 1. Thus, the (0, 0) equilibrium of the linearized u-v system is
stable. Since ut and vt measure the displacement of the system away
from the equilibrium (1/3, 1/3) , it seems reasonable to suspect that
the (1/3, 1/3) equilibrium of the nonlinear system (5.14) is stable as
well. The following theorem states that this is so.
xt+1 = f (xt , yt )
yt+1 = g (xt , yt )
xt+1 = f (xt , yt )
yt+1 = g (xt , yt )
5.9 EXERCISES
1. Consider the discrete-time system
BIBLIOGRAPHY
Caswell, H. 2001. Matrix Population Models: Construction, Analysis, and
Interpretation, 2nd ed. Sinauer Associates, Sunderland, MA. [Caswell’s
classic book should be in the library of every ecologist and mathematical
biologist.]
habitats, but for thousands of years their preferred habitat has been
milled flour and other stored grain products. These insects are hardy
and prolific animals, traits which make them important agricultural
pests and quite resistant to eradication. These same traits, however,
make them easy to culture and manipulate in the laboratory. Flour
beetles have been used extensively as animal models in genetics and
population ecology. The details of their life cycle are well known. A
comprehensive reference for the life history of flour beetles is Alexander
Sokoloff’s three-volume book “The Biology of Tribolium” (Sokoloff
1972; Sokoloff 1975; Sokoloff 1978). A fairly comprehensive history
of the mathematics of Tribolium prior to the work presented in this
chapter can be found in Costantino and Desharnais (1991).
Flour beetles undergo complete metamorphosis, which encompasses
four life-cycle stages: egg, larva, pupa, and adult. The tiny eggs—as
many as 500 from a single female—hatch in approximately four days
under laboratory conditions and can barely be seen by the unaided
eye. The larvae feed voraciously and eventually grow to the size of rice
grains. After about 14 days, a larva encloses itself in a pupal case,
which consists of a thin outer covering, the pupal cuticle. During the
pupal stage, the individual completely reorganizes itself to become an
adult (Figure 6.1). The new adult emerges another 14 days later and
sheds its pupal case as little pieces of dried tissue called frass.
One might expect that populations of flour beetles, when cultured
under constant environmental conditions, would grow exponentially
Flour Beetle Dynamics: A Case Study ■ 113
6.3 DATA
The time series in Data Set 6.1 are the control replicates from
laboratory experiments conducted by R. A. Desharnais in 1978 at the
University of Rhode Island when he did his master of science in zoology
with R. F. Costantino (Desharnais and Costantino 1980). Populations
of the corn oil-sensitive strain of Tribolium castaneum (Herbst) were
cultured in half-pint milk bottles containing 20 g of corn oil media
(90% wheat flour, 5% dried brewer’s yeast, and 5% liquid corn oil).
The cultures were kept in an unlighted incubator at 33◦ C±1◦ C and
a relative humidity of 56% ± 11%. Every two weeks, all life-cycle
stages (except eggs) were censused, and the animals (including eggs)
were returned to the incubator in fresh media. Small (feeding) larvae
114 ■ Mathematical Modeling in Biology
6.4 ASSUMPTIONS
A major goal of modeling, often called the “art of modeling,” is
to construct a simple, mechanistic, low-dimensional (i.e., few state
variables) model that describes enough of the observed variability so
that the leftover, “higher-order” variability is relatively small and can
be described statistically as “noise.” The beetle system has four life
stages (egg, larval, pupal, and adult) and thus might require four state
variables. The egg stage duration, however, is much shorter than that
of the other three life stages. Following the KISS principle (keep it
simple stupid), here we model the beetle system with two alternative
three-dimensional models. We will select the best of these two models
and attempt to validate it (Exercises 5–8).
The Beetle Team used the following assumptions.
(A1) Given that the duration of the egg stage is much shorter than
the duration of the larval and pupal stages, we can ignore numbers
of eggs and treat egg cannibalism as a factor that dampens
recruitment into the larval stage.
Figure 6.2: Leslie diagram for T. castaneum. The per capita transition
rate is shown beside each arrow. The time step is 2 weeks.
Flour Beetle Dynamics: A Case Study ■ 117
ln (Pt+1 ) = ln ((1 − µl ) Lt ) + σP EP t
ln (At+1 ) = ln Pt e−cpa At + (1 − µa ) At + σA EAt ,
where the Eit are standard normal random variables (mean zero and
standard deviation one). This model can be rewritten as
Lt+1 = bAt e−cel Lt −cea At eσL ELt
Pt+1 = (1 − µl ) Lt eσP EP t (6.5)
−cpa At σA EAt
At+1 = Pt e + (1 − µa ) At e .
This is the “environmental noise LPA model.” The “environmental
noise LPAalt model” is similar (Exercise 3).
If the demographic stochasticity were the main source of variability
in the system, assumption (A11b), the appropriate NLAR LPA model
would be
p p
Lt+1 = bAt e−cel Lt −cea At + σL ELt
p p
Pt+1 = (1 − µl ) Lt + σP EP t
p q
At+1 = Pt e−cpa At + (1 − µa ) At + σA EAt ,
where again the Eit are standard normal random variables. This model
can be rewritten as
p 2
Lt+1 = bAt e−cel Lt −cea At + σL ELt
p 2
Pt+1 = (1 − µl ) Lt + σP EP t (6.6)
q 2
At+1 = Pt e−cpa At + (1 − µa ) At + σA EAt ,
εP t = ln (pt+1 ) − ln ((1 − µl ) lt )
εAt = ln (at+1 ) − ln pt e−cpa at + (1 − µa ) at .
εP t = ϕ (pt+1 ) − ϕ ((1 − µl ) lt )
pt e−cpa at + (1 − µa ) at
εAt = ϕ (at+1 ) − ϕ .
Note that the residuals εit themselves are realizations of the random
variables σi Eit in the stochastic models.
Because each parameter appears in only one equation and we are
assuming no covariances, the likelihood function is the product
! ! !
ε2 ε2 ε2
Y 1 − Lt
2
Y 1 − P2t 1 Y− At2
L= √ e 2σL √ e 2σP √ e 2σA ,
σL 2π σP 2π σA 2π
(6.7)
assuming the residuals are normally distributed. As in Chapter 2,
maximizing the likelihood in this case is equivalent to using the method
of CLS to parameterize the model. One nice thing to know about CLS
is that it loosens the restrictive assumptions on the residuals; CLS
parameter estimates converge to the true values even if the noise is
non-normal and autocorrelated, as long as the noise has a stationary
distribution (Cushing et al. 2003; Tong 1990).
q−1
X
RSSL = ε2Lt
t=0
q−1
X
RSSP = ε2P t
t=0
q−1
X
RSSA = ε2At .
t=0
Flour Beetle Dynamics: A Case Study ■ 121
Because each parameter appears in only one equation, the three RSS
values are minimized if and only if the sum
RSS (b, cel , cea , µl , cpa , µa ) = RSSL (b, cel , cea )+RSSP (µl )+RSSA (cpa , µa )
2 RSS
\ L RSS
\ P RSS
\ A
σ
bL = bP2 =
; σ ; σ
bA2
= ,
q q q
where RSS
d denotes the fitted value of RSS.
The parameters for the environmental noise LPA model and the
environmental noise LPAalt model, estimated from the data in Data
Set 6.1 and reported to four significant figures, are listed in Tables 6.1–
6.4. In Exercise 5, you will complete Tables 6.1–6.4 by parameterizing
the demographic noise models.
Note that the estimated values of the six parameters held in
common by the environmental noise LPA and LPAalt models are
similar; in fact, to four significant figures, they differ only in the values
TABLE 6.1 LPA Model Parameters Estimated from Data Set 6.1
LPA model b
b cbel cbea µ
bl cbpa µ
ba
Environmental
noise 10.57 0.009463 0.009649 0.5129 0.01817 0.1065
Demographic
noise
122 ■ Mathematical Modeling in Biology
TABLE 6.2 LPA Model Parameters Estimated from Data Set 6.1
2
LPA model RSS
\L RSS
\P RSS
\A RSS
d σ
bL b P2
σ σ
bA2
Environmental
noise 20.99 32.56 0.8440 54.39 0.2762 0.4284 0.01111
Demographic
noise
TABLE 6.3 LPAalt Model Parameters Estimated from Data Set 6.1
LPAalt model b
b cbel cbea µ
bl cbpl cbpa µ
ba
Environmental
noise 10.57 0.009463 0.009649 0.5129 0.0007201 0.01782 0.1025
Demographic
noise
TABLE 6.4 LPAalt Model Parameters Estimated from Data Set 6.1
2
LPAalt model RSS
\L RSS
\P RSS
\A RSS
d σ
bL b P2
σ σ
bA2
Environmental
noise 20.99 32.56 0.8401 54.39 0.2762 0.4284 0.01105
Demographic
noise
of cpa and µa . (This is because the cpl parameter affects only the third
equation.) The introduction of the parameter cpl in the LPAalt model
slightly decreases the value of cpa and also µa . This suggests that
there may be some cannibalism of pupae by larvae, but not very much
(because cpl is small compared to the other cannibalism coefficients).
The question becomes: Is cannibalism of pupae by larvae important
enough that we must include it in the model? To answer this question,
we next turn to the methods of model selection.
We will select the best of the two alternative models (LPA and LPAalt)
by using the Akaike information criterion (AIC). The AIC presupposes
that all alternative models under consideration have the same number
of state variables and that they are all parameterized on the same data
set. Both of these conditions apply for the LPA and LPAalt models.
Flour Beetle Dynamics: A Case Study ■ 123
p
X
bi2 + 2κ,
AIC = pq(ln(2π) + 1) + q ln σ (6.9)
i=1
mechanisms thought to drive the dynamics. This was the origin of the
LPA model. Using historical time series data, the Team parameterized
and validated the model (as explained in the previous part of this
chapter) and then used the fitted model to make predictions about
how the system dynamics would respond to various experimental
manipulations of the parameters. Based on the model predictions, they
designed and carried out experiments to test these predictions.
Suppose we set the LPA parameters to be the CLS estimates for
the demographic LPA model from Dennis et al. (2001): b = 10.45,
cel = 0.01731, cea = 0.01310, µl = 0.2000, cpa = 0.004619, µa =
0.007629. If the experimenter could fix the adult death rate µa at 0.96
and manipulate cpa at various values between 0 and 1 in the laboratory,
what dynamics would we predict to see in the beetle populations?
The easiest way to answer this question is to have the computer draw
a bifurcation diagram with cpa as the bifurcation parameter, using
µa = 0.96 and all other parameter values as listed directly above. The
bifurcation diagram for total population size (L + P + A) is shown in
Figure 6.3 (Exercise 10).
(a) (b)
(c) (d)
zt+1 = yt e−cpa zt + (1 − µa ) zt .
xt+1 = 0
yt+1 = 0
zt+1 = yt e−cpa zt + (1 − µa ) zt .
This ridiculous model predicts zero larvae and pupae for all t > 0, along
with a geometrically decreasing number of adults. Nevertheless, the
experimental results would have been the same as in Figure 6.4! Clearly,
“making the third equation exact” does not force the experimental
dynamics to follow the predictions of the model.
Can you think of a situation in which the experimental approach of
“making one equation exact” would not be legitimate? See Exercise 11.
6.11 EXERCISES
1. In this problem, you will carry out a stability analysis for the
extinction state of the LPA model (6.1).
6. In this problem, you will use the AIC to select the best of the two
alternatives, the LPA and LPAalt models, under the assumption
of environmental noise.
8. In this problem, you will check to see if the LPA model fits Data
Set 6.2 without re-estimating the parameters. Use the parameters
estimated from the environmental noise LPA model (Tables 6.1–
6.2). Note that the experimental manipulations began at week 12
(Data Set 6.2).
134 ■ Mathematical Modeling in Biology
a. Fill in the R2 values for the estimation data (Data Set 6.1)
in Table 6.6.
b. Without re-estimating the model parameters, compute the
goodness of fit for the data in Data Set 6.2. That is, fill in
the R2 values for the validation data in Table 6.6. Hint: This
exercise will require some careful thought and programming.
There are several issues to keep in mind. First, look at Data
Set 6.2 and note that there is a “split” in each treatment.
Weeks 0–12 did not undergo manipulation. At week 12,
the experiment was “restarted” using the week 12 observed
values as initial conditions and applying the manipulations.
This is why week 12 is listed twice in Data Set 6.2 for
each treatment. Second, you will use the estimated value of
µa = 0.1065 not only for the unmanipulated control, but also
for the initial 12 weeks of each of the other two treatments.
For the remaining weeks of the manipulated treatments, you
will set µa = 0.5 or µa = 0.96, as appropriate. Third, when
creating residuals, it is important to correctly match up
predictions with observations with these “splits” in mind.
Fourth, note that Data Set 6.2 contains some values of zero,
which will cause problems with log residuals. When comput-
ing the log of the state variables, replace values of 0 with 0.5.
c. A comparison of the R2 values in Table 6.6 suggests that the
LPA model under the assumption of environmental noise is
not well validated for the L-stage. This is not surprising,
because the collection of the estimation and validation data
sets occurred over a decade apart in different laboratories
using different culture protocols and different strains of
Tribolium castaneum. In Dennis et al. (1997) the entire data
set on which Data Set 6.2 is based was randomly divided into
estimation data and validation data. The subsequently well-
validated model documented a transition between equilibria
(control), 2-cycles (µa = 0.5), and aperiodic cycles (µa =
0.96) for the treatments in Data Set 6.2 (Exercise 9). You
can see these transitions if you look at the time series in Data
Set 6.2. In this current exercise, however, continue to use
the parameters estimated from the environmental noise LPA
Flour Beetle Dynamics: A Case Study ■ 135
10. Read Costantino et al. (1997) and Dennis et al. (2001). Reproduce
the LPA bifurcation diagram in Figure 6.3 using the parameters
shown in the figure caption.
BIBLIOGRAPHY
Costantino, R. F., Cushing, J. M., Dennis, B., and Desharnais, R. A.
1995. Experimentally induced transitions in the dynamic behavior
of insect populations. Nature 375:227–230. DOI: 10.1038/375227a0.
[“Announcement” paper with first appearance of the LPA model in
the literature. Documents model-predicted bifurcations from stable fixed
points to periodic cycles to aperiodic oscillations through experimental
manipulation of the adult mortality rate in the laboratory. Both theoretical
and empirical: models connected to data. The follow-up paper by Dennis
et al. (1997) gives the details.]
Cushing, J. M., Costantino, R. F., Dennis, B., Desharnais, R. A., and Henson,
S. M. 1998. Nonlinear population dynamics: Models, experiments, and
data. Journal of Theoretical Biology 194:1–9. DOI: 10.1006/jtbi.1998.0736.
[“Perspectives” piece on the research paradigm of the Beetle Team. Both
theoretical and empirical: models connected to data.]
Desharnais, R. A., Dennis, B., Cushing, J. M., Henson, S. M., and Costantino,
R. F. 2001. Chaos and population control of insect outbreaks. Ecology
Flour Beetle Dynamics: A Case Study ■ 139
Henson, S. M., Cushing, J. M., Costantino, R. F., Dennis, B., and Desharnais,
R. A. 1998. Phase switching in population cycles. Proceedings of the
Royal Society, London B 265:2229–2234. DOI: 10.1098/rspb.1998.0564.
[Oscillation phase switches in population cycles are explained as stochastic
jumps between basins of multiple attractors. Both theoretical and
empirical: models connected to data.]
143
CHAPTER 7
Introduction to
Differential Equations
dS
= −βSI
dt
dI
= βSI − γI
dt
dR
= γI (7.1)
dt
S (0) = S0 > 0
I (0) = I0 > 0
R (0) = R0 > 0,
Figure 7.2: Compartments and per capita flow rates for the SIR model.
Introduction to Differential Equations ■ 149
dI
= βSI − γI ≤ 0,
dt
that is, as long as
γ
S≤ .
β
Thus, there will be no outbreak if S0 ≤ γ/β, whereas there will be an
outbreak if S0 > γ/β.
What are the equilibria of the SIR model? The equilibria occur
where the derivatives are zero:
dS
= −βSI = 0
dt
dI
= βSI − γI = I (βS − γ) = 0
dt
dR
= γI = 0.
dt
150 ■ Mathematical Modeling in Biology
From the third equation, we see that the equilibrium value of I must be
zero, while S and R can be any non-negative value. So the equilibria
all have the form (Se , 0, Re ) , which includes the trivial equilibrium
(0, 0, 0). This means there is no endemic disease state (i.e., no level of
disease that can be maintained at a steady state in the host).
One of the interesting aspects of the SIR example is the amount of
information about the system we can obtain without actually solving
the differential equations. It is important for biologists to realize
that, in general, it is not necessary to actually solve a differential
equation in order to study its equilibria and stability. In Chapter
8, we will learn more techniques for analyzing differential equations
without solving them. But to finish the current chapter, we illustrate a
powerful solution method for solving a famous differential equation
from ecology. Hopefully, students who have not taken a course in
differential equations will become intrigued and be motivated to do
so.
dx
= bx − dx2 ,
dt
dx x
= rx 1 − , (7.2)
dt K
dx
= f (x) g (t) . (7.3)
dt
(In the logistic model, we can take f (x) = x(1 − x/K) and g(t) = r.)
It turns out that one can legitimately treat dx/dt as a fraction of
differentials to multiplicatively “separate the variables” as
dx
= g (t) dt.
f (x)
One can then integrate each side with respect to its variable. It is
important to note, however, that dividing by f (x) assumes f (x) = ̸ 0,
which “drops” all equilibrium solutions of equation (7.3). In our current
example, we can write
dx
= rdt
x (1 − x/K)
1 A B A (1 − x/K) + Bx
= + = .
x (1 − x/K) x (1 − x/K) x (1 − x/K)
152 ■ Mathematical Modeling in Biology
1 = A (1 − x/K) + Bx
= A + (B − A/K) x.
1 = A and B − A/K = 0,
Integration yields
ln |x| − ln |1 − x/K| = rt + C1 .
x
ln = rt + C1 .
1 − x/K
To solve for x, we exponentiate both sides and then drop the absolute
values by introducing ± on the right:
x
= ert+C1 = eC1 ert
1 − x/K
x
= ±eC1 ert = Cert .
1 − x/K
x = Cert (1 − x/K) ,
Cert
x= ̸ 0.
for C = (7.4)
1 + Cert /K
Introduction to Differential Equations ■ 153
7.3 EXERCISES
1. Consider two 100 L tanks. Tank A is initially full of pure water,
and tank B initially contains 50 L of pure water. Seawater of
concentration 35 g/L flows into tank A at a rate of 2 L/min.
The well-mixed solution overflows into tank B, and when tank
B is full, it is allowed to overflow as well. Write the differential
equation initial value problem for the amount of salt in each tank.
Hint: It is okay to use piecewise functions.
7. Show that equations (7.5) and (7.7) together yield the particular
solution (7.8). Be careful with the singular solution.
dx
= t2 x2 .
dt
Note that this equation is separable and that there is one
equilibrium: xe = 0.
dx
= t 1 − x2 .
dt
xt+1 = rxt (1 − xt ) ,
156 ■ Mathematical Modeling in Biology
dx/dt = rx (1 − x/K) .
bxt
xt+1 = ,
1 + cxt
considered in Exercise 8 of Chapter 3, is the discrete-time
analogue of the continuous-time logistic model. In this exercise
we will see why.
Kx0
xt = . (7.9)
x0 + (K − x0 ) b−t
BIBLIOGRAPHY
Kermack, W. O. and McKendrick, A. G. 1927. A contribution to the
mathematical theory of epidemics. Proceedings of the Royal Society of
London A. 115:700–721. DOI: 10.1098/rspa.1927.0118. [Historic paper
introducing the SIR model with random infectious encounters, similar to
the law of mass action in chemistry. Many models in epidemiology are
variations of the SIR model.]
Pearl, R. and Reed, L. J. 1920. On the rate of growth of the population of the
United States since 1790 and its mathematical representation. Proceedings
Introduction to Differential Equations ■ 157
Verhulst, P.-F. 1838. Notice sur la loi que la population suit dans son
accroissement. Correspondance mathematique et physique 10:113–121.
[(Note on the law of population increase.) Verhulst introduces the logistic
differential equation model of population growth, which is a modification
of the Malthusian exponential growth model by the inclusion of crowding
effects.]
Scalar Differential
Equations
where r is a real parameter. What are the equilibria of this model? The
system is at equilibrium if and only if the derivative dx/dt is zero for
all time t. Thus, the equilibrium equation (or fixed point equation) is
0 = rx.
where c is any constant (Exercise 1). Now apply the initial condition
x(0) = x0 to obtain
x0 = cer0 ,
xp (t) = x0 ert .
From this solution formula, we can see that if r > 0, then the extinction
equilibrium xe = 0 is unstable, because ert is growing over time. If
r < 0, then the extinction state is asymptotically stable, because ert
is approaching zero over time. If r = 0, then every real number x0
is an equilibrium, and these equilibria are all neutrally stable. The
bifurcation diagram in Figure 8.1 summarizes these dynamics as a
function of the bifurcation parameter r. The bifurcation at r = 0 is
called a vertical bifurcation (Figure 8.1).
For a specific example, consider the initial value problem
x′ = 2x
x (0) = 5.
x (t) = 5e2t .
Scalar Differential Equations ■ 161
dx
= bx − dx = (b − d) x (8.2)
dt
x (0) = x0 .
x (t) = x0 e(b−d)t .
Figure 8.2 gives time series graphs for the three cases b < d, b = d, and
b > d. If b < d, then all nonzero solutions are decaying exponentially
toward zero. If b = d, then the initial condition itself is an equilibrium
solution. If b > d, then all nonzero solutions are growing exponentially.
The exponential growth when b > d is called Malthusian growth,
after Thomas Malthus, an economist and English curate who wrote
the influential piece An Essay on the Principle of Population in 1798
(Malthus 1798).
Note that linear models have exponential solutions.
162 ■ Mathematical Modeling in Biology
(a)
(b)
(c)
Figure 8.2: Time series for model (8.2). (a) b < d, (b) b = d, (c) b > d.
outflow rate has the form (dx) x = dx2 . Thus, we have the nonlinear
model
dx
= bx − dx2 . (8.3)
dt
This is the famous logistic model, but it is traditionally written in a
different form. Choose two new parameters r and K defined by r = b
and K = b/d. Then we can rewrite equation (8.3) as
dx x
= rx 1 − . (8.4)
dt K
Equation (8.4) is the traditional form of the continuous-time logistic
model . What are the dynamics? First let’s compute the equilibria, that
is, the constant solutions. The solution x (t) is constant if and only if
dx/dt = 0 for all time t, so the equilibrium equation is
x
rx 1 − = 0.
K
The equilibria are therefore xe = 0 and xe = K. Figure 8.3 illustrates
the behavior of all possible solutions as a function of t. Note from
Figure 8.3 that xe = 0 is an unstable equilibrium, whereas xe = K is
an asymptotically stable equilibrium.
The parameter r is called the intrinsic growth rate. It is the
exponential rate of growth for small population sizes, when crowding
effects are negligible. The parameter K is called the carrying capacity
of the environment.
Figure 8.4: Per capita growth rate in the logistic model graphed
against population size x.
Scalar Differential Equations ■ 165
Figure 8.5: Per capita growth rate in model (8.5) graphed against
population size x.
where r, a, K > 0 and a < K. The equilibria for this model are xe =
0, a, K, and the per capita growth rate is
x
r (x − a) 1 − .
K
x (t) = x0 ert .
After a certain amount of time T, the population size will have doubled
to 2x0 . What is the doubling time T ? That is, for what value of T is
2x0 = x0 erT ?
x(40) = 2.30
x(90) = 5.30.
that is, when t = 116.7. This time corresponds to the year 1900 +
116.7 = 2016.7, or about the year 2017. A similar model published in
the journal Science in 1960, called the “Doomsday Model,” predicted
a doomsday of November 13, 2026 (von Foerster, Mora, and Amiot
1960).
The Doomsday Model and these various dates for “doomsday”
are humorous, disturbing, and, for the modeling student, enlightening.
Scalar Differential Equations ■ 169
8.4 LINEARIZATION
Consider the differential equation
dx
= x (x − 1) (x − 2) .
dt
xe = 0, 1, 2.
Figure 8.7a shows the graph of f (x) vs. x. The roots of f are
the equilibria. When the graph of f is above the x-axis, dx/dt > 0
and so x (t) is increasing. We denote this with a time arrow to the
right on the x-axis. When the graph of f is below the x-axis, we insert
an arrow to the left on the x-axis. If we extract the x-axis by itself
with the equilibria shown as circles and with the time arrows in each
interval between equilibria, we obtain the phase line portrait (Figure
8.7b). If the arrows point toward the equilibrium on each side, then
the equilibrium is a sink and is asymptotically stable. If the arrows on
each side point away from the equilibrium, then the equilibrium is a
source and is unstable. All possible time series for x vs. t are shown in
Figure 8.7c.
Note from the geometry in Figure 8.7a that if the graph of f is
increasing through the equilibrium as a function of x, then the arrows
point away from the equilibrium, and the equilibrium is unstable.
Similarly, if f is decreasing through the equilibrium as a function
of x, then the arrows point toward the equilibrium, which is then
asymptotically stable. In the current example, we have
df
(0) > 0 =⇒ xe = 0 unstable
dx
df
(1) < 0 =⇒ xe = 1 asymptotically stable
dx
df
(2) > 0 =⇒ xe = 2 unstable.
dx
(a)
(b)
(c)
Figure 8.7: (a) Graph of f (x) vs. x. The roots of f are the equilibria.
(b) Phase line portrait. (c) Time series for x(t) vs. t showing
equilibrium solutions (horizontal lines) and illustrating the behavior
of all other solutions.
dx
= f (x) .
dt
df
An equilibrium xe is hyperbolic if and only if dx (xe ) ̸= 0.
172 ■ Mathematical Modeling in Biology
df
λ= (xe ) .
dx
Then
λ > 0 =⇒ xe is unstable
λ < 0 =⇒ xe is asymptotically stable.
As you will see in the next chapter, the number λ is a very important
number called the eigenvalue. Figure 8.8 summarizes the relationships
between sinks, sources, and eigenvalues. Note that for λ = 0 (the
nonhyperbolic case) you cannot conclude anything from linearization;
the linearization theorem does not apply. See Figure 8.9.
For an example, consider the logistic model
dx x
= rx 1 − ,
dt K
where r, K > 0. The equilibria are xe = 0, K. Also, f (x) =
rx (1 − x/K). It is easiest to use the product rule to find df /dx =
dx
= x2 (x − a) ,
dt
Figure 8.11: Phase line portrait for dx/dt = x2 (x − a), shown for
a > 0. For a < 0, xe = 0 becomes a shunt to the right.
dx
= x (x − a) (10 − x) ,
dt
8.5 BIFURCATIONS
x′ = x x 2 − a .
√
The equilibria are xe = 0 and xe = ± a. In the bifurcation diagram,
these two branches cross at a = 0 in a pitchfork bifurcation (Figure
8.16). In Exercise 8, you will show that for a < 0, the equilibrium xe = 0
is unstable, and for a > 0, the equilibrium xe = 0 is asymptotically
8.5.4 Hysteresis
Finally, consider
x′ = x3 − x + a.
It is not so easy here to find the equilibria, but we note that the
bifurcation parameter a in f (x) = x3 − x + a vertically translates
the graph of f . First, graph f (x) for a = 0. The roots are −1, 0, and
1 (Figure 8.17). From the geometry we can include stability arrows
Figure 8.17: f (x) vs. x for various values of the parameter a. The
graph is shifted vertically upward when a > 0, which corresponds to
dropping the horizontal axis, etc.
Scalar Differential Equations ■ 179
8.6 EXERCISES
1. Use the method of separation of variables from Chapter 7 to
show that the general solution of dx/dt = rx is x (t) = cert for
c ∈ R. Keep track of lost equilibrium solutions and the values of
constants as we did in Chapter 7.
180 ■ Mathematical Modeling in Biology
Cert
x(t) =
1 + Cert /K
λ > 0 =⇒ ue = 0 unstable
λ < 0 =⇒ ue = 0 asymptotically stable.
10. Consider
x′ = −x3 + x + a.
11. This exercise uses the skills developed in Exercise 10. Consider
the logistic model for a fishery with an extra removal rate due to
fishing. Suppose the rate at which fish are removed due to fishing
is a constant h fish per unit time. The modified model is then
dx x
= rx 1 − −h
dt K
with r, K > 0 and h ≥ 0.
12. Draw the bifurcation diagrams for the following systems, using r
as a bifurcation parameter. Include stability arrows.
a. dx/dt = (r − 2) (x − r)
b. dx/dt = (x − 2) (x − r)
c. dx/dt = sin (r)
2
d. dx/dt = x (x − r)
e. dx/dt = x − r2 (r − x)
Scalar Differential Equations ■ 185
BIBLIOGRAPHY
Cushing, J. M. 2004. Differential Equations: An Applied Approach. Prentice-
Hall, Upper Saddle River, NJ. [A good source for more phase line portrait
and bifurcation diagram exercises, as well as many interesting applied
projects using differential equations, including the “Doomsday Model.”]
von Foerster, H., Mora, P. M., and Amiot, L. W. 1960. Doomsday: Friday,
13 November, A.D. 2026. Science 132:1291–1295. DOI: 10.1126/sci-
ence.132.3436.1291. [As the authors wrote, “At this date human
population will approach infinity if it grows as it has grown in the last
two millenia.”]
CHAPTER 9
Systems of Differential
Equations
∂f
= 2x + 0 + y 3 3x2
∂x
∂f
= 0 + 2y + x3 3y 2 .
∂y
If this is your first experience with partial derivatives, work a few
problems in a calculus book to get comfortable with them.
The main ideas in this chapter are to learn how to solve and analyze
linear systems and then to apply those techniques to nonlinear systems
by means of linearization. You should keep track of how these methods
parallel those for discrete-time systems in Chapter 5. Thus, before
beginning this chapter you should reread the sections in Chapter 5 that
deal with solving linear discrete-time systems and the linearization of
nonlinear discrete-time systems.
x′ = ax + by (9.1)
′
y = cx + dy,
0 = ax + by
0 = cx + dy.
v1 + 2v2 = 0
1
v1 + v2 = 0.
2
2
Thus, v1 = −2v2 , so an eigenvector belonging to λ = 1 is . The
−1
corresponding eigensolution is
x 2
= et .
y −1
If λ = 3, then
−v1 + 2v2 = 0
1
v1 − v2 = 0.
2
2
Thus, v1 = 2v2 , so an eigenvector belonging to λ = 3 is and the
1
corresponding eigensolution is
x 2
= e3t .
y 1
x′ = −3x − y
y ′ = 2x.
−3 − λ −1
= 0,
2 0−λ
so that
−λ (−3 − λ) + 2 = 0
λ2 + 3λ + 2 = 0
(λ + 1) (λ + 2) = 0.
Here, both manifolds are stable (because the scalars e−t and e−2t are
approaching zero). The term with e−t dominates in forward time, and
the term with e−2t dominates in backward time, as shown in Figure 9.2.
This phase plane portrait is an asymptotically stable node (Figure 9.2).
9.2.3 Saddle
Consider the system
x′ = x
y ′ = −x − 2y.
1−λ 0
= 0,
−1 −2 − λ
Systems of Differential Equations ■ 193
(1 − λ) (−2 − λ) = 0.
9.2.4 Center
Consider the harmonic oscillator
x′ = y (9.5)
′
y = −x.
194 ■ Mathematical Modeling in Biology
−λ 1
= 0,
−1 −λ
that is,
λ2 + 1 = 0.
The eigenvalues λ = ±i are complex numbers, in this case purely
imaginary numbers. For λ = i, we find the eigenvalues as before:
−iv1 + v2 = 0
−v1 − iv2 = 0.
iv1 + v2 = 0
−v1 + iv2 = 0.
From Euler’s formula eit = cos t + i sin t and the facts that cos t is
even and sin t is odd, one can obtain the complex solution (Exercise 1)
x sin t cos t
= (c2 − c1 ) + i (c1 + c2 ) . (9.7)
y cos t − sin t
A theorem from differential equations says that the real and imaginary
parts of this complex solution are two linearly independent real
solutions, in this case
sin t cos t
and .
cos t − sin t
satisfies system (9.5) and that the solutions are closed curves in the
phase plane (Exercise 3). The direction of rotation can be determined
by choosing a test point, say x = 1, y = 0, and checking the signs of the
time derivatives at that point (x′ = 0, y ′ = −1). This tells us that y
is decreasing at that point, and so the rotation is clockwise in forward
time.
When eigenvalues are purely imaginary, as in this example, the
phase plane portrait is called a center (Figure 9.4). A center is neutrally
stable.
x′ = x − y
y ′ = x + y.
x′ = −x + 2y
y ′ = −5x − 3y.
TABLE 9.1 The Six Generic Phase Plane Portraits. (See Figure 9.7)
(a) (d)
(b) (e)
(c) (f)
Figure 9.7: The six generic phase plane portraits. (a) Asymptotically
stable node. (b) Unstable node. (c) Saddle. (d) Center. (e) Asymptot-
ically stable spiral. (f) Unstable spiral. (See Table 9.1.)
x′ = f (x, y)
y ′ = g (x, y)
second equation x = 1. Thus, the two equilibria are (0, 0) and (1, 1) .
We linearize around each equilibrium in turn. The Jacobian is
1−y −x
J= .
−2y 2 − 2x
1
The eigenvalues are λ = 1 with eigenvector and λ = 2 with
0
0
eigenvector . Thus, the (0, 0) equilibrium is an unstable node
1
for the linear system, with unstable manifolds on the axes. Therefore,
as we shall see, the (0, 0) equilibrium of the nonlinear system is also an
unstable node, and the phase plane locally around (0, 0) is topologically
equivalent to that of the linear system.
At the equilibrium (1, 1) , the Jacobian is
0 −1
J (1, 1) = .
−2 0
√ √
1
√
The eigenvalues are λ = 2 with eigenvector and λ = − 2
− 2
√1
with eigenvector . Thus, the (0, 0) equilibrium of the linear
2
system is a saddle, with unstable and stable manifolds determined by
these eigenvectors. Therefore, as we shall see, the (1, 1) equilibrium
of the nonlinear system is also a saddle, and the phase plane locally
around (1, 1) is topologically equivalent to that of the linear system
around (0, 0).
Now we can piece the local information together to approximate
the phase plane portrait for the nonlinear system (Figure 9.8).
We make these ideas more precise in the next section.
Systems of Differential Equations ■ 201
9.3.1 Linearization
Definition 9.1 The linearization of a nonlinear system
x′ = f (x, y)
y ′ = g (x, y)
x′ = f (x, y)
y ′ = g (x, y)
x′ = f (x, y)
y ′ = g (x, y) ,
then
(1) if all the eigenvalues of the Jacobian J (xe , ye ) have negative real
parts, (xe , ye ) is asymptotically stable,
(2) if at least one of the eigenvalues of J (xe , ye ) has positive real part,
then (xe , ye ) is unstable.
(a)
(b)
Figure 9.9: (a) Limit cycle of the Van der Pol oscillator (equation 9.9).
(b) Cycle chain.
illustrates both limit cycles and bifurcations. Consider the Van der Pol
oscillator
x′ = y − x3 + ax (9.9)
′
y = −x,
(a) (c)
(b) (d)
(a)
(b)
different from the previous two in that it assumes the prey population
grows exponentially in the absence of predators and that the predator
population declines exponentially in the absence of prey. Neither of
these assumptions is very realistic, because one would expect that
(i) both species would have a self-regulatory density-dependent term
such as the quadratic nonlinearity in the logistic model, and (ii) the
predators would switch to other prey in the absence of species x.
The nullclines for x are the lines x = 0 and y = r1 /a12 , and the
nullclines for y are the lines y = 0 and x = r2 /a21 . It is not clear
from the nullclines (Figure 9.12) whether the coexistence equilibrium
is a spiral or a nonlinear center. It is possible to prove, however, that
208 ■ Mathematical Modeling in Biology
the orbits are closed curves and hence surround a nonlinear center.
When the periodic solutions are graphed as time series, they exhibit
the well-known predator-prey oscillations.
One might consider a more realistic version of the Lotka-Volterra
predator-prey model. For example, the Seabird Ecology Team used
x′ = rx − rx2 /K − axy
y ′ = sy − sy 2 /C + bxy
9.6 EXERCISES
You will need a computer program to quickly graph phase planes. The
free PPLANE Java version (Castellanos and Polking) is very easy to
use for this purpose.
Systems of Differential Equations ■ 209
x′ = Ax. (9.13)
x′ = x2 − 1 y
′ 2
3
y = 1−y x+ y .
10
x′ = y
y ′ = −x 1 − x2 .
a. There are three equilibria. Find them and place them on the
phase plane in a graph.
b. Find the Jacobian matrix as a function of x and y.
c. Show that two of the equilibria are hyperbolic saddles and
the third is nonhyperbolic (so the linearization theorem does
not apply to it).
d. Prove that all solutions lie on curves of the form x2 + y 2 =
1 4
2 x + C. Hint: Compute dy/dx by recalling that dy/dt =
dy/dx · dx/dt. Use the technique of “separation of variables”
to integrate dy/dx.
e. Prove that the nonhyperbolic equilibrium is (locally) a
nonlinear center. Hint: Prove that if C ∈ (0, 1/2], then the
equations x2 + y 2 = 21 x4 + C describe a family of closed
curves containing the origin for −1 ≤ x ≤ 1.
f. Prove that two heteroclinic orbits connect the two saddle
equilibria. Hint: Prove that the two saddle equilibria lie on
the closed curve associated with C = 1/2.
g. Determine whether the trajectories on the closed curves for
C ∈ (0, 1/2] are clockwise or counterclockwise in forward
time.
h. Graph the nonlinear phase plane portrait and check your
work with PPLANE.
Systems of Differential Equations ■ 213
BIBLIOGRAPHY
Castellanos, J. and Polking, J. C. PPLANE, Java version.
https://www.cs.unm.edu/˜joel/dfield/. [Freeware for graphing phase
plane portraits.]
Seabird Behavior: A
Case Study
modeling processes we used. Subsequent team papers that use the same
methodology are found in the bibliography.
dN
= (Inflow rate) − (Outflow rate).
dt
We assumed that:
After day 275 and before day 65 of the following year, the mean
maximum pier counts were zeros or ones; consequently, we set Kp (t) =
0 for those intervals. See Figure 10.1.
Figure 10.1: Maximal historical counts. The height of each bar is the
mean historical maximal count for the pier for that week, averaged over
the years 1997–1999 and 2001. The curve is the fitted function Kp (t).
(Originally published in The Auk 121:382. Used with permission of
Oxford University Press.)
Seabird Behavior: A Case Study ■ 221
RSS(θb)
R2 = 1 − P
n
2
(xi − x)
i=1
Model α
b β
b b2
σ R2
H1a 0.31 2.0 244 0.38
H1b 0.10 80 225 0.43
H1c 0.35 2.8 166 0.58
Note that for (H1b), the local minimizer for RSS occurs
on the boundary of allowed parameter space with β = 80.
Figure 10.3: Model (H1c) prediction (lower curve), hourly data from
2002 (circles), and tide height (upper curve). Each daily panel is
identified with the day of the year and has a horizontal scale of 5–
20 hours PST, which is 6–21 hours PDT. Tide height is graphed on a
vertical scale of −1 to 3 m. (Originally published in The Auk 121:385.
Used with permission of Oxford University Press.)
(a) (b)
(c)
(d)
(e)
the biweekly oscillation predicted by the model (Figure 10.4b and d).
Finally, from the first to the second biweekly oscillation period, the
average daily counts increased, which reflected the predicted increase
in counts during the spring (Figure 10.4b and d).
βKp (t)
N0 (t) = 2 . (10.4)
1 S(t)
1+ α2 T (t)
10.11 DISCUSSION
10.11.1 Importance of Scale
So, is animal behavior largely deterministic or largely stochastic? The
answer is: It depends on the scale.
Fluctuation in animal numbers over the short term indicates a
variety of competing functional needs. For example, during a single
day an individual bird may loaf, feed, and defend its territory against
intruders. To carry out all these behaviors, the bird must move
from habitat to habitat. Physiological limitations and environmental
variables are important in opening and closing opportunities for these
behaviors. It is not too surprising, then, that at the group level, some
behaviors are fairly deterministic, as we have seen in this chapter.
Nevertheless, animals such as gulls display high levels of individual
variation in behavior. An individual gull decides to move from one
habitat to another within a unique set of historical contingencies. While
it is true that a decision to change habitats may be influenced by what
other gulls do, the decision may also made without this influence.
We saw no evidence of coaction or social facilitation in arrivals and
departures from the pier, except in cases when the pier was disturbed
by human activity. Instead, gulls landed on the pier and left the
pier individually throughout the day, suggesting that the decision by
individual gulls to loaf may be more or less independent of the behavior
of the other gulls. The results in this chapter therefore suggest that
228 ■ Mathematical Modeling in Biology
10.12 EXERCISES
1. Obtain from NOAA the Port Townsend hourly tidal observations
in meters for hours 0600–2100 PDT on July 2, 1997. Correct these
values for Protection Island with a factor of 0.93 as explained in
this chapter. Do your values match those in Data Set 10.1?
Seabird Behavior: A Case Study ■ 229
BIBLIOGRAPHY
Cowles, J. D., Henson, S. M., Hayward, J. L., and Chacko, M. W. 2013. A
method for predicting harbor seal (Phoca vitulina) haulout and monitoring
long-term population trends without telemetry. Natural Resource Modeling
26:605–627. DOI: 10.1111/nrm.12015. [Applies the differential equation
approach and time scale analysis methods of this chapter to harbor seal
haul-out behavior. Both theoretical and empirical: models connected to
data.]
Henson, S. M., Dennis, B., Hayward, J. L., Cushing, J. M., and Galusha,
J. G. 2007. Predicting the dynamics of animal behaviour in field popula-
tions. Animal Behaviour 74:103–110. DOI: 10.1016/j.anbehav.2006.11.015.
[Presents a general mathematical framework for modeling animal
behaviors and habitat patch occupancies with compartmental differ-
ential equations. Both theoretical and empirical: models connected
to data.]
Henson, S. M., Weldon, L. M., Hayward, J. L., Greene, D. J., Megna, L. C.,
and Serem, M. C. 2012. Coping behaviour as an adaptation to stress: Post-
disturbance preening in colonial seabirds. Journal of Biological Dynam-
ics 6:17–37. DOI: 10.1080/17513758.2011.605913. [Differential equation
approach incorporating logistic regression and Darwinian dynamics to
investigate theoretically how a behavior with crucial physiological function
might evolve into a comfort behavior. Both theoretical and empirical:
models connected to data.]
Payne, B. G., Henson, S. M., Hayward, J. L., Megna, L. C., and Velastegui
Chavez, S. R. 2015. Environmental constraints on haul-out and foraging
Seabird Behavior: A Case Study ■ 233
235
CHAPTER 11
Introduction to
Regression
∆y = βi c.
Thus, coefficient βi is the rate of change of y with respect to factor xi
when all other factors are held constant. The sign of the coefficient
βi determines whether y is positively or negatively correlated with
factor xi .
P2 P1
ln − ln
1 − P2 1 − P1
n
X n
X
=
β0 + βi (xi + c) + − β0 +
βj xj βj xj
j=1 j=1
̸
j=i
= βi c,
where P1 and P2 are the probabilities of the event before and after the
change, respectively. Thus, by the laws of logarithms, the odds ratio,
denoted OR, is
P2 / (1 − P2 )
OR = = eβi c .
P1 / (1 − P1 )
This means that, given an increase in factor xi by c > 0 units, with all
other factors held constant, the odds of the event are eβi c times what
they were before.
If βi > 0, then the odds ratio is greater than one (OR > 1), meaning
the odds of the event have increased. If βi < 0, the odds ratio is less
than one (OR < 1), and the odds of the event have decreased. For
example, if OR = 1.25, the interpretation is that the odds of the event
increase 25% with a c-unit increase in xi . If OR = 0.85, the odds
decrease 15% with a c-unit increase in xi . The researcher chooses a
convenient value of the reference c so that the results are intuitively
clear. Note that these statements of association do not necessarily
imply causation.
242 ■ Mathematical Modeling in Biology
The transformation g is called the link function, and the model is called
a generalized linear model (GLM). Common examples of GLMs include
logistic regression for binary data (0 or 1 outcomes), Poisson regression
for count data, gamma regression for exponential response data, and
linear regression for linear response data. The link functions for these
types of regression are shown in Table 11.1.
For more information on GLMs, see the definitive book by
McCullagh and Nelder (1989).
ln (odds) = β0 + β1 x1 + β2 x2 + β12 x1 x2 .
11.6 EXERCISES
1. Prove that if factor xi increases by c units in equation (11.1), and
all other factors are held constant, then the resulting change in
y is βi c.
2. Consider the Poisson regression model
ln y = β0 + β1 x1 + β2 x2 + β3 x3 .
g (y) = β0 + β1 x1 + β2 x2 ,
244 ■ Mathematical Modeling in Biology
ln (odds) = β0 + β1 x1 + β2 x2 + β3 x3 .
ln (odds of passing) = β0 + β1 x1 + β2 x2 .
b. Fill in the missing values in the results table using the given
reference value c.
Factor bi c SE OR 95% CI
STUDY 0.5 hours
SLEEP 0.3391 2 hours 0.4960 1.970 (0.2819, 13.77)
BIBLIOGRAPHY
Burnham, K. P. and Anderson, D. R. 2002. Model Selection and Multi-Model
Inference: A Practical Information-Theoretic Approach, 2nd ed. Springer-
Verlag, New York. [Comprehensive and user friendly text on methods of
model selection.]
(a) (b)
Figure 12.1: (a) Male cannibal holding egg in bill. (b) Accumulation
of eggshell fragments on the territory of an egg cannibal. (Photos by
James Hayward.)
Climate Change and Seabird Cannibalism: A Case Study ■ 249
12.3 DATA
them back to their own territories, whereas eagles eat eggs where they
find them, leaving distinctive patterns of broken eggshell behind.
We measured the distance from the center of each sample nest to
the center of the nest of its nearest neighbor. We recorded the nest as
residing in one of four habitats: (i) short or sparse vegetation (SV),
(ii) tall dune grass (TG), (iii) beside a shrub or log (SL), or (iv) beach
(BC). In 2007–2011, we also determined the mass of each egg on the
day it was laid.
The average SST from September to May prior to each breeding
season was determined using data from the Port Townsend, Wash-
ington buoy (PTWW1), a floating National Oceanic and Atmospheric
Administration (NOAA) structure located 12 km east of Protection
Island. The interval from September to May was chosen for two
reasons: (i) Breeding success in gulls is determined in part on resource
availability before egg production, and (ii) the effects of changes in the
physical environment on seabird populations are not immediate (Smith
et al. 2017). Warmer-than-average SSTs preceded the 2007 and 2010
breeding seasons due to El Nino conditions.
The data for 2006–2011 are given in Data Set 12.1.
The fates of 2,932 eggs monitored over the five breeding seasons from
2007 to 2011 were assessed by logistic regression in terms of whether
eggs were cannibalized or not (1 or 0). Cannibalism was considered
as a function of SST, egg mass (MASS), nearest neighbor distance
(NN), number of days before or after the mean laying date for the
season (DAYS), sample area (PLOT; five values, A–E), habitat type
(HAB; four values, SV, SL, TG, and BC), egg order as laid in the nest
(ORDER), and the total number of eggs laid in the clutch (CSIZE).
The log odds of cannibalism were regressed on these eight factors and
on 17 interaction terms between PLOT and HAB (three of the 20
possible combinations did not occur) with an intercept term.
A suite of alternative models was obtained from the global model
by taking all submodels, that is, all possible linear combinations of
the eight factors, with intercepts. For models with both PLOT and
HAB variables, the interaction terms were included. We determined
Climate Change and Seabird Cannibalism: A Case Study ■ 253
12.6 OUTCOMES
The results of the analysis described above are summarized in Table
12.1, which shows only those variables found to be significant. The
parameters used to compute the ORs in Table 12.1 were not the
fitted parameters for the best model, but rather were the “model-
averaged” parameter estimates. A model-averaged parameter estimate
is the average over all models (in the suite of alternative models) that
contain that parameter, weighted by its Akaike weight. We do not
discuss Akaike weights or model-averaged parameter estimates here;
details can be found in Burnham and Anderson (2002).
The most important thing to understand in this section is how
to interpret the results in Table 12.1. Make sure you can derive the
following interpretations from Table 12.1.
254 ■ Mathematical Modeling in Biology
warming. Our data suggest this warming trend may increase the rate
of egg cannibalism.
It seems, however, that gulls have evolved a way to reduce the
impact of cannibalism on their reproductive efforts. During the years of
low SST and low egg cannibalism, egg-laying occurs during a relatively
short period, which overwhelms would-be egg and chick predators from
outside the colony with a glut of food; the chance that a given egg
is predated by bald eagles is reduced (the “Fraser Darling effect”
(Darling 1938)). By contrast, during the years of high SST and high
egg cannibalism, the egg-laying period lengthens and females nesting
close together tend to synchronize their every-other-day egg laying until
they achieve the typical three-egg clutch; by laying their eggs on the
same day as their neighbors, the chance that a given egg is predated
by a cannibal neighbor is reduced (Henson et al. 2010). In other words,
gulls switch between two breeding tactics, depending on whether the
threats to their offspring are from outside (eagles) or inside (cannibals)
the colony (Weir et al. 2020).
Under the lead of one of our colleagues, Gordon Atkins, we found
that females tended to avoid copulation on egg-laying days, but
welcomed copulation on the intervening days. The very loud, pulsating
copulation call of the males functioned as the synchronizing signal
(Atkins, Hayward, and Henson, 2021; Atkins et al. 2017).
Our studies of cannibalism raise many unanswered questions.
For example, are some gulls genetically predisposed to cannibalize
their neighbors’ eggs, or is this primarily a learned behavior? Are
eggs with certain colors and pigmentation patterns more vulnerable
to cannibalism than others? Do egg cannibals exhibit other forms
of antisocial behavior outside the breeding season? Will increasing
SSTs associated with climate change increase the incidence of egg
cannibalism on gull colonies? Hopefully, these and other questions will
be answered by future research.
Of the Seabird Team papers in the annotated bibliography below,
some are theorem-proof mathematics papers and some are empirical
papers. In terms of topics, they address various aspects of cannibalism
and egg-laying synchrony in the context of climate change. The
annotations will help the reader know how each paper relates to this
chapter.
Climate Change and Seabird Cannibalism: A Case Study ■ 257
12.8 EXERCISES
1. Fit model
2. Fit model
log (odds) = b0 + b1 SST
to Data Set 12.1 using logistic regression, where odds is the odds
an egg is cannibalized. Use the glmfit(x,y,‘binomial’) function in
MATLAB or other software for logistic regression.
3. Fit model
log (odds) = b0 + b1 DAYS
to Data Set 12.1 using logistic regression, where odds is the odds
an egg is cannibalized. Use the glmfit(x,y,‘binomial’) function in
MATLAB or other software for logistic regression.
BIBLIOGRAPHY
Atkins, G. J., Hayward, J. L., and Henson, S. M. 2021. How do gulls
synchronize every-other-day egg laying? Wilson Journal of Ornithology
133:226–235. DOI: 10.1676/20-00019. [The connection between socially-
facilitated mounting and egg-laying synchronization. Both theoretical and
empirical.]
Atkins, G. J., Sandler, A. G., McLarty, M., Henson, S. M., and Hayward, J. L.
2015. Oviposition behavior in glaucous-winged gulls (Larus glaucescens).
Wilson Journal of Ornithology 127:486–493. DOI: 10.1676/14-151.1. [First
detailed description of egg-laying behavior in gulls. Empirical.]
Polski, A. A., Osborn, K. J., Hayward, J. L., Joo, E., Mitchell, A. T., Sandler,
A. G., and Henson, S. M. 2021. Egg cannibalism as a foraging tactic
by less fit glaucous-winged gulls (Larus glaucescens). Wilson Journal of
Ornithology 133:552–567. DOI: 10.1676/20-00072. [Comprehensive study
of the behavioral ecology of egg cannibalism in glaucous-winged gulls.
Based in part on the undergraduate Honors theses of Ashley Polski and
Karen Osborn. Empirical.]
262 ■ Mathematical Modeling in Biology
Weir, S. K., Henson, S. M., Hayward, J. L., Atkins, G. J., Polski, A. A.,
Watson, W., and Sandler, A. G. 2020. Every-other-day clutch-initiation
synchrony as an adaptive response to egg cannibalism in glaucous-
winged gulls (Larus glaucescens). Wilson Journal of Ornithology 132:575–
586. DOI: 10.1676/19-82. [Demonstration that egg-laying synchrony is
adaptive in the presence of egg cannibalism in gulls. Based in part on
the undergraduate Honors thesis of Sumiko Weir. Both theoretical and
empirical: models connected to data.]
V
Appendix
263
APPENDIX A
265
266 ■ Appendix A
d
a b c e = ad + be + cf.
f
For example,
2
1 4 = 1(2) + 4(−3) = −10.
−3
This is called the dot product of the two vectors. Note that the dot
product gives a scalar, that is, a 1 × 1 matrix.
In general, two matrices can be multiplied together if the first has
dimension n × m and the second has dimension m × p. The result is
an n × p matrix in which the (i, j)th entry, meaning the entry in the
ith row and jth column, is the dot product of the ith row of the first
matrix and the jth column of the second matrix. This sounds more
difficult than it is; matrix multiplication is easy to carry out once you
Appendix A ■ 267
1 −2 2 −1 1(2) − 2(1) 1(−1) − 2(−3)
=
−1 0 1 −3 −1(2) + 0(1) −1(−1) + 0(−3)
0 5
= ;
−2 1
1 −2 2 1(2) − 2(−3) 8
= = .
−1 0 −3 −1(2) + 0(−3) −2
Note that matrix multiplication is not in general commutative. That
is, the order in which matrices are multiplied matters.
a b
= ad − bc.
c d
This textbook mostly requires computing determinants for 2 × 2
matrices. If you need to compute the determinant of a higher-
dimensional matrix, simply look up the procedure in a more
comprehensive discussion of matrices.
Work all of the following exercises, which are designed to lead
you step by step through the major concepts you will need from
linear algebra. A list of solutions follows the exercises. You will find
a summary of the concepts at the end.
A.2 EXERCISES
2 −1 1 −2
1. =
1 −3 −1 0
268 ■ Appendix A
0 2 1 1
2. =
3 −2 1 −3
1 −2 1 0
3. =
−1 0 0 1
1 0 2 −1
4. =
0 1 1 −3
1 −2 x
5. =
−1 0 y
0 2t a
6. =
3t3 −2 b
1 −2 2 −1
7. − =
−1 0 1 −3
1 −2 2 −1
8. 3 +α =
−1 0 1 −3
1 −2 x 2t
9. + =
−1 0 y −t3
1 −2
11. Compute the determinant. =
−1 0
5 −1
12. =
3 6
(2 − λ) 1
13. =
−1 (−1 − λ)
|A − λI| = 0,
5 −1
where A = . The two λ-solutions are called the
0 6
eigenvalues of the matrix A.
|A − λI| = 0,
1 2
where A = . That is, find the eigenvalues of A. Hint:
−2 1
The eigenvalues in this case are complex numbers.
−3 2
17. Find the eigenvalues of A = .
−2 2
18.
For eac
h of the eigenvalues in Problem 17, find a vector v =
v1
such that Av = λv; that is, find a vector v such that
v2
0
v satisfies the vector equation (A − λI)v = 0, where 0 =
0
is the zero vector. These vectors v are called eigenvectors. You
may wish to follow the complete solution given below as you work
through this procedure for the first time.
A.3 SOLUTIONS
Some of the following solutions omit intermediate steps.
2 −1 1 −2 3 −4
1. =
1 −3 −1 0 4 −2
0 2 1 1 2 −6
2. =
3 −2 1 −3 1 9
1 −2 1 0 1 −2
3. =
−1 0 0 1 −1 0
1 0 2 −1 2 −1
4. =
0 1 1 −3 1 −3
1 −2 x x − 2y
5. =
−1 0 y −x
0 2t a 2bt
6. =
3t3 −2 b 3at3 − 2b
1 −2 2 −1 −1 −1
7. − =
−1 0 1 −3 −2 3
1 −2 2 −1 3 + 2α −6 − α
8. 3 +α =
−1 0 1 −3 −3 + α −3α
1 −2 x 2t 2t + x − 2y
9. + =
−1 0 y −t3 −x − t3
1 −2 1 0 (1 − λ) −2
10. A − λI = −λ =
−1 0 0 1 −1 −λ
1 −2
11. = −2
−1 0
5 −1
12. = 33
3 6
(2 − λ) 1
13. = λ2 − λ − 1
−1 (−1 − λ)
Appendix A ■ 271
B.1 PRELIMINARIES
Set the defaults on computer so that file extensions are visible. It is
best to leave your computer this way. In Windows 10, right-click on
Start > File Explorer > View. Then enable the “File name extensions”
by checking the box.
Keep shortcuts for Notepad, Excel, and MATLAB on your desktop
or taskbar for easy access. You can find Notepad in Windows 10 by
left-clicking on Start.
273
274 ■ Appendix B
> x = 5
> y = 6
B.2.2 Case-Sensitivity
MATLAB is case-sensitive. This includes variables and file names.
> x = 2
> y = 3
> z = x+y
> z
> x
> z^2
>x=5
at the command line in MATLAB, you are saying:
> variable = known numerical value
That is, you are saying that x is the name of a variable and you are
assigning the value 5 to it. The right-hand side of an equal sign must be
either a number, or a combination of variables that have already been
assigned numerical values. For example, in programming, the command
> x = x+1 is perfectly legitimate if x has already been assigned a value,
whereas in algebra, the statement x = x + 1 is always a contradiction.
> x=5
> y=x
> x=x+1
> z=x+y
+ − ∗ / ˆ
The symbol ˆ means “raised to the power.”The order of operations
is the same as it is in arithmetic: compute parentheses, then exponents,
then multiplication and division, and then addition and subtraction.
When everything is at the same level of operators, the calculation
proceeds left to right.
> x=6
> y=2
> z = (x + y)ˆ2/y + x
> z = (x + y)ˆ(6/y) + x
> z = (x + y)ˆ6/(y + x)
B.2.7 Programs
Typing a long sequence of complicated commands at the prompt is
cumbersome, so we write such sequences of commands in a separate
file called a program (or script, or code). When you run the program
at the MATLAB prompt, each line within the program is executed
sequentially. Here are the general steps for writing and running a
program.
1. To write a program using the MATLAB editor, go to “File” in
MATLAB; choose “New”and then “Script.”
2. Type code (lines of commands) into the file. Do not type > in
front of your commands.
3. Save the program file to the folder where you are keeping
your MATLAB work. It should be saved as programname.m. Here,
“programname” is a placeholder for whatever name you want to call
the program. The extension must be *.m for MATLAB.
4. In MATLAB, you need to “set the path,”which means directing
MATLAB to the working folder in which you store your programs.
The exact way in which you set the path depends on the MATLAB
version you are using. You may find “Set Path” under a “File” or
“Environment” tab, and many versions have a “browse for folder”
button at the top of the Editor window with which you can choose
your working folder.
5. To run the program called programname.m, go to the MATLAB
command prompt and type the program name without the extension
(no “.m”).
> programname
Appendix B ■ 277
Example B.5 Type the following three lines in a script file, and save
the file to your working folder as hey.m. (The horizontal lines shown
here are not part of the program.) To run the program hey.m, simply
type > hey at the command prompt. The output to the screen will be
the values of x, y, and z.
x=6
y=2
z = (x + y)ˆ6/y + x
>x = 5
> y = 6;
>y
B.2.11 Loops
Loops are used to repeat sections of the code (program) a specified
number of times. The syntax is:
for countername = startvalue : increment : endvalue
(various commands)
end
Note that we indent the commands that are inside the loop. This
helps highlight the logical structure of the code.
%Program tschuss.m
%Initialize x
x = 2
%Loop
for i = 1 : 1 : 6
x = x * x + i
end
Appendix B ■ 279
%Program wiegehts.m
for i = 1 : 1 : 100000
x = i+100
end
x
%Program hola.m
%Initialize x
x = 7
Example B.10 Open a new Notepad file and type the first 10 positive
integers in a column vector. Save this input file as ciao.txt. Go to the
command prompt and type the following commands. After you load
ciao.txt, the vector of numbers from the input file is stored in a variable
named “ciao”. The second command renames the vector of numbers,
calling it “data”. The third command adds one to each entry in the
vector.
Example B.12 Create a script file for f(x) = x2 using the following
code. Save the program as “square.m”. Note that the name of the
program file should be the same as in the function declaration line.
%Define y as a function of x
y = x^2;
end
282 ■ Appendix B
After saving the above program to your working folder, type the
following commands at the prompt.
> square(5)
> square(10)
The screen output should be 25 and 100.
B.2.16 Subroutines
A subroutine is a subsidiary program that is called within a main
program. It is often easier to see the structure of the main program
when certain groups of commands are relegated to subroutines.
%Program main.m
%Calls subroutine sub.m
%Declare global variables
global x check
%Initialize x
x = 0;
%Loop
for i = 1 : 0.5 : 20
x = x + i;
%Call the subroutine sub.m
sub;
%Print out value of the variable check
check
end
Appendix B ■ 283
%Subroutine sub.m
%Called by main.m
%Declare global variables
global x check
> x = [1 -3 5 9]
> y = [2 0 3 -1]
> a = 0 : 0.2 : 3
> a = a’ (transpose operation)
> n = length(y) (finds the “length” of the vector = number of
entries)
> z = x + y (addition of vectors/matrices)
> zz = sum(y) (this is the sum of the entries of the vector y)
> x = x’
> w = [1 -3 4]’
> w(1) (returns the first entry of the vector w)
> w(3) (returns the third entry of the vector w)
> y = [1 3 5; 2 4 -3; 7 -2 0] (semicolons denote different
rows)
> y = y’
> x = [1 2 5
3 7 1
-2 0 0] (line breaks denote different rows)
284 ■ Appendix B
> z = x + y
> z = x*y (multiplication of matrices)
> z = x.*y (entry-wise multiplication of matrices)
> z = 2*x (scalar multiplication of matrices)
> z = x/2 (scalar division of matrices)
> z = x.^2 (entry-wise squaring of matrix entries)
> z = x + 1
> x = [1 2 5
3 7 1
-2 0 0]
> z = x(2,3)
> z = x(1,2)
Example B.17 Try the following commands and note the result of
each type of syntax.
> y = [1 2]
> v = [y 3]
> w = [y [3 4]]
> z = [y; [3 4]]
Appendix B ■ 285
Example B.18 There are three commands for building special vec-
tors/matrices. Try these examples at the command prompt.
%Loop
for i = 1 : 1 : 10
x(i) = 3*i;
end
x
for i = 1 : 1 : 10
x = [x; 3*i];
end
x
B.2.19 Plotting
To plot vector y against vector x, use the command
> plot(x,y)
Example B.21 Type the following commands at the prompt. Note
what each command accomplishes.
> x = 1 : 0.1 : 8
> y = sin(x)
> plot(x,y)
%Program Ricker.m
%Initialize x and set parameters b and c
x = 1;
c = 0.01;
b = 8;
%Loop
for i = 1 : 1 : 50
x = b*x*exp(-c*x);
end
%Program Ricker.m
%Initialize x and set parameters b and c
x = 1;
c = 0.01;
b = 8;
%Loop
for i = 1 : 1 : 50
xnew = b*x*exp(-c*x);
x = xnew;
end
%Program Ricker.m
%Initialize x and set parameters b and c
x = 1;
c = 0.01;
b = 8;
%Loop
for i = 1 : 1 : 50
x(i+1) = b*x(i)*exp(-c*x(i));
end
In the last program above, make sure you understand why x(51) is
x50 . Hint: In MATLAB, a vector cannot have a zeroth entry.
%Program Ricker2D.m
%Set parameters
Appendix B ■ 289
c = 0.01;
b = 8;
a = 0.2;
%Initialize x and y
x = 1;
y = 2;
%Loop
for i = 1 : 1 : 50
xnew = b*y*exp(-c*y);
ynew = x + (1-a)*y;
x = xnew;
y = ynew;
end
x = b*y*exp(-c*y);
y = x + (1-a)*y;
because the second line would use the updated value of x on its right-
hand side instead of the previous value of x. It is very important to
understand this.
Often we want to plot the whole trajectory of x and y. Here is a
better way to code the previous example.
%Program Ricker2D.m
%Set parameters
c = 0.01;
b = 8;
a = 0.2;
290 ■ Appendix B
%Initialize x and y
x = 1;
y = 2;
%Loop
for i = 1 : 1 : 50
x(i+1) = b*y(i)*exp(-c*y(i));
y(i+1) = x(i) + (1-a)*y(i);
end
%Program calcderiv.m
function Nprime = calcderiv(t,N)
Or, write a program called logistic.m that executes these same lines:
%Program logistic.m
[T pop]=ode45(’calcderiv’, [0 42], 5);
plot(T, pop)
n = length(T);
pop(n)
>n
> pop(1)
> pop(5)
> pop(n)
The last three commands above are not function evaluations. They
return the 1st, 5th, and nth entries, respectively, of the vector pop.
%Program findmin.m
%Calls fminsearch.m and gfun.m
%Program gfun.m
function y = gfun(theta)
a = theta(1);
b = theta(2);
2 2
y = (a − 2) + (b − 3) + 5;
end
Appendix B ■ 293
B.3 EXERCISES
1. Write a program that finds minimizers of f (x) = sin x. As you
know, sin x has infinitely many minima. Note how your answer
depends on your initial “guess” x0. Attach your programs and
screen output for several values of x0.
Connecting Models to
Data: A Brief Summary
with Sample Codes
C.1 PARAMETERIZATION
The main ideas are:
4. We want to find the values of a and b that make the curve “best”
fit the data. Such values b
a and bb are the parameter estimates.
There are various methods for obtaining parameter estimates.
295
296 ■ Appendix C
2. Copy the contents of the Excel file and paste them into a Notepad
file. If you keep the column headings, the headings row must be
commented out with an initial %.
to the humerus estimation data in Data Set 2.4 (see Chapter 2) using
Kb = 11.96923077. Assume environmental noise. We want to find the
best-fit parameters a and b.
%Program gompertz.m
%Parameterizes the Gompertz model
global age hum
%Load data
load estimation.txt;
data = estimation;
age = data(:,1);
hum = data(:,2);
300 ■ Appendix C
%Initialize parameters
theta = log([0.01 0.03]’);
%Program RSSgom.m
function RSS = RSSgom(theta)
global age hum
to the humerus estimation data in Data Set 2.4 (see Chapter 2) using
Kb = 11.96923077. Assume demographic noise. We want to find the
best-fit parameters a and b.
Appendix C ■ 301
%Program lin.m
%Parameterizes the linear model
global age hum
%Load data
load estimation.txt;
data = estimation;
age = data(:,1);
hum = data(:,2);
%Initialize parameters
theta = log([0.1 15]’);
%Program RSSlin.m
function RSS = RSSlin(theta)
global age hum
for i = 1 : n
if age(i) < b
pred(i) = a*(age(i)-b) + K;
else
302 ■ Appendix C
pred(i) = K;
end
end
pred = pred’;
end
to the data in Data Set C.1. That is, we want to find the best-fit
parameters a and b.
%Program ricker.m
%Parameterizes the Ricker model
global obst obsN
%load data
load RickerInput.txt;
data = RickerInput;
obst = data(:,1);
obsN = data(:,2);
%Initialize a and b
theta = log([2 0.03]’);
Appendix C ■ 303
%Function RSSfun.m
function RSS = RSSfun(theta)
global obst obsN
%Compute RSS
numobs = length(obsN);
obsNahead = obsN(2:numobs);
predNlag = predN(1:numobs-1);
residuals = obsNahead - predNlag;
squareresiduals = residuals.^2;
RSS = sum(squareresiduals);
end
%Program LPA.m
%Parameterizes the LPA model
global Ldata Pdata Adata
304 ■ Appendix C
for i = 1 : reps
Ldata = [Ldata data(:,(i-1)*3+1)];
Pdata = [Pdata data(:,(i-1)*3+2)];
Adata = [Adata data(:,(i-1)*3+3)];
end
%Initialize parameters
theta = log([
8
0.01
0.01
0.2
0.01
0.2
]);
%Program RSSlpa.m
function RSS = RSSlpa(theta)
global Ldata Pdata Adata
%Set parameters
par = exp(theta);
b = par(1);
cel = par(2);
cea = par(3);
Appendix C ■ 305
mul = par(4);
cpa = par(5);
mua = par(6);
n = length(Ldata(:,1));
Lp = Lpred(1:n-1,:);
Pp = Ppred(1:n-1,:);
Ap = Apred(1:n-1,:);
Lo = Ldata(2:n,:);
Po = Pdata(2:n,:);
Ao = Adata(2:n,:);
RSSL = sum(sum(Lres.^2));
RSSP = sum(sum(Pres.^2));
RSSA = sum(sum(Ares.^2));
end
Index
307
308 ■ Index
maximizer, 39 Janoschek, 34
maximum likelihood, 38, 296 Leslie, 86
parameters, 39 linear, 89
May’s Hypothesis, 81 logistic, 14, 24, 150, 156,
May, Robert, 81, 125, 206 163, 172, 291
mean, 19 Lotka-Volterra, 204
mechanism LPA, 23, 99, 116, 128
deterministic, 33 mathematical, 4
stochastic, 33 mechanistic, 6
metamorphosis, 86, 112 NLAR, 117
minimizer, 40 nonlinear, 89
model nonlinear Leslie, 99
fitting, 7, 8, 36, 295 regression, 237
parameterization, 119, 220 Ricker, 24, 61, 75, 82,
predictions, 8, 222 83, 135
selection, 8, 42, 122, 221 SIR, 147
validation, 8, 36, 45, 124, stage-structured, 86
222 stochastic, 34, 35
validation in logistic model-averaged parameter
regression, 253 estimates, 253
model modeling
age-structured, 86 art of, 6, 114
algebraic, 4 ecological, 10
assumptions, 6 multiple time scale
Beverton-Holt, 73, 82, 156 analysis, 226
compartmental, 56, 146, mutualism, 86
150, 218
continuous-time, 4 natural selection, 12
demographic noise Nelder-Mead algorithm, 40,
LPA, 119 300
deterministic, 33 net reproductive number, 107
difference equation, 4 inherent, 131
differential equation, 4 neutrally stable, 15, 195
discrete logistic, 82 NLAR model, 117
discrete-time, 4, 85 NOAA, 218
discrete-time logistic, 155 node
environmental noise asymptotically stable,
LPA, 118 191, 192
generalized linear, 242 unstable, 189, 191
Gompertz, 299 noise, 6, 16, 114
Index ■ 313
Improved
A streamlined A single point search and
experience for of discovery discovery of
our library for all of our content at both
customers eBook content book and
chapter level