forked from UofTCoders/rcourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignment-07.Rmd
136 lines (106 loc) · 6.59 KB
/
assignment-07.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
---
title: "Assignment 7"
output:
html_document:
toc: false
---
```{r setup, echo=FALSE}
knitr::opts_chunk$set(eval = FALSE)
```
*To submit this assignment, upload the full document on Quercus,
including the original questions, your code, and the output. Submit
your assignment as a knitted `.pdf` or `.html` file.*
*For questions that ask you to plot something by hand, indicate which
assignment and question the plot is for and either include a photo or
scan of it in the markdown document, create the plot digitally,
or hand in the hard copy.*
1. Qualitatively analyzing a one-dimensional model (2 marks)
Consider the differential equation $\frac{dx}{dt} = x(1-x)$.
a. Use R to plot $\frac{dx}{dt}$ vs. $x$ for $-1 \le x \le 2$. (0.5 marks)
b. Sketch a one-dimensional phase portrait on paper (or digitally if you
prefer). Mark the direction of the derivative in each region with arrows and
label the fixed points as "stable" or "unstable". (0.5 marks)
c. Use R to numerically solve this equation and plot $x$ vs. $t$ for $0 \le
t \le 10$. Plot trajectories for several different starting values of $x$
(initial conditions) using `ggplot` and the `do` function we used in class.
Based on the long-time behaviour of the system, which fixed point(s) are
stable and which are unstable? (1 mark)
2. The Allee Effect (3 marks)
Generally, as population size increases, a population will
experience a decreased growth rate due to greater competition for
resources. This is a negative density-dependent growth rate, and one
example of this is the logistic model.
The Allee effect introduces positive density dependence, where
increases in population size result in increased growth rates over a
certain range of population sizes. One way to incorporate
the Allee effect into the logistic growth equation is as follows:
$$\frac{dN}{dt} = rN\left(1-\frac{N}{K}\right)\left(\frac{N-A}{K}\right)$$
Here $r$ represents the growth rate of the population, $K$ is the
carrying capacity, and $A$ is the critical population size above which
the total growth rate is positive.
a. Take $r=1$, $A=10$, and $K=50$. Use R to plot $\frac{dN}{dt}$ vs. $N$ for
$0 \le N \le 55$. For which values of $N$ is the growth rate
($\frac{dN}{dt}$) positive or negative? Which values of N are fixed points?
(0.5 marks)
b. Sketch a phase portrait on paper or digitally, leaving $A$ and $K$ as
variables (i.e. without choosing values for $A$ and $K$, but with $0 \le A <
K$). Mark the direction of the derivative in each region with arrows and
label the fixed points as "stable" or "unstable". (1 mark)
c. Use R to plot the **per capita** growth rate ($\frac{1}{N}\frac{dN}{dt}$)
vs. $N$ for this model of the Allee effect and for the logistic growth
model: $\frac{dN}{dt} = rN(1-\frac{N}{K})$.
- What do you notice about the density ($N$) dependence of the per
capita growth rate in each case? Hint: in the logistic model,
the growth rate **per capita** (per organism) decreases in a
straight line as $N$ increases.
- What happens to the Allee effect as $A$ decreases? Plot curves
for $A=0$ and a few values of $A>0$.
- The parameter $A$ controls the strength of the Allee effect: for
$A > 0$, the Allee effect is said to be strong, and for $A=0$,
the Allee effect is weak. What will happen to a population
experiencing a strong Allee effect if the population size falls
below $A$? What will happen to a population experiencing a weak
Allee effect if the population size falls below $A$? (1 mark)
d. Describe two biological situations in which you might expect to see an Allee
effect (either weak or strong). (0.5 marks)
3. The Canadian lynx population cycle (3 marks)
The Canadian lynx experiences large periodic changes in its population
size over a timescale of several years. This is thought to be driven by
oscillations in the population size of the snowshoe hare, the primary food
source for the lynx. Read more about the lynx population cycle on this
[Northwest Territories website](https://www.enr.gov.nt.ca/en/services/lynx/lynx-snowshoe-hare-cycle).
R has a built-in dataset called `lynx` which contains annual population
measurements for the Canadian lynx as a time series.
a. Plot `lynx` vs. time in years using either `ggplot` or `qplot`. Plot points
(`geom_point`) and a connecting line (`geom_line`). Create a time series that
starts at 0 and ends at the total number of years in the dataset (total years $=
1934-1821$). By eye, estimate the time between peaks in the population. (0.5
marks)
b. Define a function called `sine_model` that takes 5 arguments: a vector of
years for the x-axis and four parameters (amplitude, period, phase, and offset).
Recall the general formula for a sine wave:
$$y = A \text{sin}(kx - b) + c$$
where $k = 2\pi / T$, $T$ is the period or length of time between peaks, $A$
is the amplitude, $b$ is the phase, and $c$ is the offset. Using a value of
$A = c = 1700$ for both the amplitude and offset and a value of $b = 2.75$
for the phase, plot the lynx data as before and add a sine curve using your
guess of the timescale from part (a) for the period. Use a colour other than
black to plot the sine wave. Note that the x axis must start at 0 in order
for the offset of $2.75$ to match the data. (0.5 marks)
c. Use least-squares fitting to refine your estimate of the lynx cycle length.
(1.5 marks)
- Make a range of values for the period that span your guess from part (a).
- Use the `sapply` function to calculate a predicted dataset using a
sine model. Calculate the sum of the difference (*residuals*) between
the lynx data and your prediction, then return the sum of the residuals
squared.
- Plot the sum of the residuals squared vs. the range of period values.
By eye, what is the minimum of this curve? What value of the period
gives the best fit?
- Use the function `which` to extract the period value that gives the
best fit.
What is your calculated length of the lynx population cycle?
d. Plot the lynx data again and plot your best fit curve on top. Does your
estimate of the cycle length match the literature? Why or why not? (Find and
cite a resource that gives an estimate of the lynx population cycle.) (0.5
marks)