This week, we’ll do a series of group exercises to get you practicing with randomizations, apply functions, and loops. For any one of these problems, there are multiple solutions. The exact codes don’t matter as much as the ability to think creatively to come up with a solution to a problem. Here are the guidelines:


Exercise 1: Logistic population growth

Quick review: Exponential growth

Last week, we spent a little bit of time modeling exponential/geometric population growth with and without stochasticity in population growth rates. Those are all cases of density-independent population growth–i.e., there is no carrying capacity for the population. Today, we will start by modeling a classic density-dependent population growth model called logistic population growth.

As review, here is the exponential population growth equation: \[N_t=N_0e^{rt}\]

The rate of change of this population is simply: \[\frac{dN}{dt}=rN\] So, if we are plotting the change in the population over discrete time steps, we can say that \[N_{t}=r_dN_{t-1}+N_{t-1}\] Here, we use the notation \(r_d\) to represent the discrete growth factor

Then, we can project the population with a growth rate of \(r=0.2\) and initial population size \(N_0=10\) over a number of time steps (let’s say 50) like this:

r=0.2
N0=10
time=50
N=vector(length=time+1)
N[1]=N0
for(t in 2:(time+1)){
  N[t]=r*N[t-1]+N[t-1]
}
plot(0:time, N, type="o", pch=19, las=1, xlab="Time")

Logistic population growth

Now, we will take the same approach to project the growth of a population that has a carrying capacity, K. In this case, the rate of change of a population at any time t is described the logistic population growth equation: \[\frac{dN}{dt}=rN\left(1-\frac{N}{K}\right)\] In this case, the population changes more (increases faster) when N is small, and stops growing when N approaches K.

To express population size at any time t, you can use this equation: \[N_t=N_{t-1}+rN_{t-1}\left(1-\frac{N}{K}\right)\] That is, the population size at time t is the population size in the previous time step (t-1) plus the change in the population.


Problem 2.1: Plot logistic population growth

Using the equation above, plot the growth of a population over 50 years given these parameters:

  • \(N_0=10\)
  • \(r=0.2\)
  • \(K=500\)

Make your plot look like this:

Problem 2.2: Different starting population sizes:

Now, build the same model but with varying initial population sizes:

  • \(N_0\) = 10, 50, 100, 200, 300 and 400
  • \(r = 0.2\)
  • \(K=200\)

and make a plot that looks like this:

Problem 2.3: Different growth rates lead to different dynamics

Now make several different plots of this model with different growth rates:

  • \(N_0=10\)
  • \(K=200\)
  • r = 1, 1.8, 2 and 3

Plot the results on 4 panels like this (the actual plots not shown):

You should see some interesting difference in the population dynamics. See footnote1 for details:


Exercise 2: Random Walk

A random walk is a stochastic process that describes a path consisting of a series of random steps on some space. It is essentially a null model of the behavior of some process, and has extremely broad applicability, including from biology, chemistry, physics, and economics. Here, we will attempt to simulate the random walk process on a single dimension.

The rules of a random walk are simple:

  1. In each iteration, the actor starts at 0
  2. At each time step, the actor can go up or go down by one unit (+1 or -1).

Your goal is to simulate a random walk process from scratch.

Problem 2.1: Single iteration

Simulate 1 iteration of a one-dimensional random walk over 1,000 time steps and plot the results.

Produce a figure that looks like this:

Problem 2.2: Multiple iterations

Now simulate the random walk 5 times and plot the results, like this:

Problem 2.3: Probability distribution of random walk

  1. Run the random walk over 100 time steps, and repeat this simulation for 1,000 iterations.
  2. Record the final position (value) each time.
  3. Plot a histogram of these values. (I’m intentionally not showing you what it looks like)
  4. Calculate the mean value.


  1. Logistic population growth undergoes different population dynamics under large population growth rates. When \(r<2\), the population converges towards K. When \(2<r<2.45\), we get a stable limit cycle. When \(r>2.6\) or so, the population begins to hope around an infinate number of unique points. This is NOT random. Rather, it is chaos–i.e., deterministic, non-repeating patterns.