We are going to modify the dynamical rule to include a carrying capacity that will slow down the growth when the population size gets large.
Let $K$ be the carrying capacity, which we can think of being the number of mountain nyalas that their habitat can sustainably support (for example, due to a limited space or supply of food). If the current population size is $m_t$, what is the fraction of the carrying capacity that is being used? Therefore, what is the fraction of the carrying capacity that is still available?
To modify the dynamical system to include the effects of the carrying capacity, we simply multiply the growth rate $r$ by the fraction of the carrying capacity available: $_$ . The resulting model is called the logistic model , which we can write as
$$m_{t+1} = m_{t} + r m_{t} _.$$
Let's use R to explore the behavior of the logistic model. This time, we'll use a script file to make it easier to keep track and reuse our command. The first step is to create a new directory (or folder) on your computer for the scripts, for example, an “RWork” directory in your Documents directory. Then, in RStudio, set the working directory to that new directory by selecting Set Working Directory from the Session menu. Select Choose Directory and navigate to your new directory and click Open. In the R console, you will see a setwd (for set working directory) command being automatically entered. If you like, you can just type that setwd command in the future.
Next, open up a new script file. You can select New File from the File menu, then click R Script. Save the file by selecting Save from the File menu. It should automatically show your new directory, as it is the working directory. Save the script with an appropriate name (maybe one expressing your affection for mountain nyalas).
Let's start by setting the carrying capacity to 5000. First, enter a comment to remind you what is the carry capacity. In R, everything after a pound sign # is ignored. Then set K to 5000. For example, you can enter the two lines:
# carrying capacity
K = 5000
To actually run the second line in R, press Ctrl/Cmd-Enter (or click the Run icon) while your cursor is on that line. You'll see that K=5000 is automatically entered in the console. Similarly, set the growth rate $r$ to 0.04 and $t_{max}$ to 100 by typing the lines
# growth rate
r = 0.04
# simulation time
tmax = 100
To run the code, you can press Ctrl/Cmd-Enter on each line or just highlight the lines with your mouse before pressing Ctrl/Cmd-Enter .
As before, we'll use the vector ms to store the values of $m_t$. We can start by just setting it to our initial condition $m_0=900$ mountain nyalas
# initial condition
ms = 900
Be sure to run the second line. (In R, a single number like 900 is the same as a vector of one dimension, so we'll subsequently be able to add components to ms by assigning values to ms[2] , ms[3] , etc., as we did before.)
Write a for-loop to simulate the evolution of our logistic model. The only difference will be to change the dynamical rule to the new logistic model you derived above. See if you can figure out how to modify the above for-loop so that R will calculate the solution $m_t$ for $t=1, 2, \ldots, t_{max}$ and store the result in the vector ms . If you get stuck and there's no one around you who can help, you can peak at the code in the below hint.
Be sure to make a comment of what the loop is doing. Assuming you wrote the loop on more than one line, you can select the lines with the mouse before pressing Ctrl/Cmd-Enter to run all the lines together.
Once you've run these commands, the vector ms is defined. You can examine ms or one of its components by entering them in the console. (Remember, ms[17] , the 17th component of the vector ms actually stores $m_{16}$, the population in year 16.) According to the model, what will be the nyala population size in year 100?
Complete your script by adding a line to plot the results. The same plot command as before will work.
# plot the results
plot(ts, ms, xlab="time", ylab="population size", main="Mountain nyala population versus time")
What trend do you observe in the mountain nyala population size over 100 years? The population size decreases. The population size grows exponentially. The population growth speed up as the population size gets closer to the carrying capacity. The population growth slows down as the population size gets closer to the carrying capacity. The population size grows linearly.
You've done a lot work. Be sure to save your script!
Hint
The “for loop” modified for the logistic model is the following.
# simulation loop
for(t in 0:(tmax-1)) {
ms[t+2] = ms[t+1] + r*ms[t+1]*(1-ms[t+1]/K)
}
Hide help
To the nearest integer, what does the model predict for the nyala population size after 300 years?
This number is exactly one of the parameters from out model. Which one?
Hint
You can just change
tmax to a new value in your script and source the whole script by clicking on the source button about the script editor and pressing Ctrl/Cmd-Shift-S. (In RStudio, sourcing is a lot like running, except one difference is that the commands will not appear in the console when sourcing, resulting in less clutter when you want to execute a bunch code.)
Hide help
Lastly, imagine that the mountain nyala have been around for a long time, so their population size is equal to the ending population size you calculated above, i.e., _ . Let's use this as an initial condition, i.e., set
$$m_0 = _$$
Imagine that, habitat loss due to human activity has reduced the carrying capacity to $K=2000$. Using your R program, estimate the mountain nyala population size after twenty years. $m_{20} = $