Please use the MacArthur-Rosenzweig predator-prey model to create
a time series where (1) prey exist at equilibrium, (2) prey and
predators stably coexist, and (3) where prey and predators show unstable
behavior. Choose your parameters arbitrarily, but make sure that your
starting densities of predator and prey area positive (i.e., prey
existing at equilibrium should come from predators going extinct and not
because initial densities of predators were 0). Plot all three as a
three-panel figure using:
par(mfrow = c(1, 3), mar = c(4.5, 4.5, 0.5, 0.5))
(the
first argument makes one row and three columns of graphs, the second
sets the amount of white space respectively on the bottom, left, top,
and right.)
For each of the three scenarios you platted above, I would like
for you to plot (1) the nullclines and (2) add the trajectory from
above.
As a bit of guidance, remember that for the equation for the nullcline
you want to get it in a \(y = f(x)\)
form. You then plot it as such (e.g., create a sequence of \(x\) and apply the function to get \(y\)). To add lines to a plot, use the
function lines()
where the arguments are the same as
plot()
(e.g., you give it an x =
, a
y =
, col =
, etc.) Make the prey nullclines
blue and the predator nullclines red.
To add trajectories, you want to do two things. First, add a point of
what the initial population densities are using points()
(takes teh same arguments as plot()
). Second, use your
numerical solution from question 1. and plot \(x\) against \(y\).
I next want to teach you how to create a “direction field,” like
what I have shown in class (and what is in the discussion presentations)
that effectively population trajectories on grid. To do so, you need to
install a package in R called phaseR
.
Do this by, only one time ever, running the line of code in the console
(not your script because you don’t need to download and install a
package every time you run your code!):
install.packages(pkgs = "phaseR")
. Once you have done that,
at the top of your script/markdown file, load the package from your
library by writing the line: library(package = "phaseR")
.
Now, have a look at the function flowField()
in the help
section by typing into the console: ?flowField
Notice the
arguments: these are all the things you can modify! What you absoltely
need to run the function are:
deriv =
: this is where you put your functionxlim =
and ylim =
: your two-element vector
of min and max values for both axesparameters =
: your vector of parameters that you create
when you pass them to ode()
state.names =
: a vector with two character elements
identifying the names of your variablesadd = F
: add this because the default is for this
function to add arrows onto an existing plot. Setting this argument to
FALSE
means it creates a new plotJust like the others above, make 3 graphs. Plot the direction field
using flowField()
, then add on the nullclines the same way
you did for 2., and end by adding the trajectory just like you did for
2., too.