Unless specified otherwise, homework assignments should be emailed to the instructor as knitted R Markdown documents. Print (or compile) the markdown to a pdf, and provide the
.Rmd
file as well. Links to older homework solutions are below.
This week, you’re going to do some deep dives into your movement data of choice using the fanstatstic mathemagics of likelihoods. For this assignment, pick just one individual (elephant, wolf, caribou, fisher, buffalo, whatever you can scrape up), ideally with well over 100 locations and more or less regular intervals.
Use optim() to estimate:
The likelihood for the Weibull distribution and an example for
fitting to data is in the book
chapter. For the Cauchy distribution, simply follow the template for
the Weibull, but replace the dweibull
with the
dwrpcauchy()
function from the CircStats
package.
We saw in class with the buffalo data that the Weibull distribution was absolutely lousy at capturing the (very typical) bimodality of movement data. There are lots of locations when animals simply don’t move. In this exercise, fit a bimodal Weibull model to your movement data. In this model, there will be 5 parameters \(\alpha_1\) and \(\beta_1\) are the shape and scale, respectively, in one state, \(\alpha_2\) and \(\beta_2\) are the shape and scale in the second state, and \(p\) is the proportion of time spent in the first state.
At first blush this might seem really hard. But this link does exactly this for a bimodal normal distribution. So you will need to apply an exactly analogous approach, just with a slightly different distribution.
between turning angles and step lengths in your data. This might seem
hard, but, in fact (or - in theory - ) you should be able to directly
apply the FunkyModel.Likelihood()
function described in the
book
chapter.
For this assignment, we recommend using whatever dataset(s) you hope to use for your final project. If you don’t have access to these yet, you can work with a Movebank (or via Dr. G) dataset of your choice.
The assignment is to make a pretty (static) map with your
movement data and at least one additional spatial variable of some kind
(e.g., raster of environmental data, vector data of roads or barriers or
habitat, etc.). You can make this map using any R package you want as
long as you can make a “pretty” map with it but we recommend trying one
of the packages introduced in class (e.g., ggspatial, basemaps…). Your
map should include at minimum, a background map of some kind (could just
be a polygon of land, could be a basemap (e.g., an OSM basemap from
ggspatial
or basemaps
), labeled X/Y axes, a
legend, and of course, your data (movement data, additional spatial
data). If you are feeling fancy/brave, try to add a north arrow and
scale bar!
Remember to make sure that all your layers have the same CRS, GCS or PCS, and spatial extent… don’t hesitate to email Nicki for help (barbour@esf.edu). And if you need help finding spatial data for your project, Elie likely has some layers he can send you.
On Monday we watched a very interesting lecture by Marie-Josée Fortin of the University of Toronto on modeling spatial data. The code and data from that lecture are available here: https://github.com/eco4cast/Statistical-Methods-Seminar-Series/tree/main/fortin_spatial-models. I believe the data are ovenbirds (Seiurus aurocapilla), with a nice song and the main question Prof. Fortin was exploring was whether or not their abundance is related to forest cover.
You can download the data directly in R as follows:
library(curl)
## Using libcurl 7.81.0 with OpenSSL/3.0.2
url <- curl("https://raw.githubusercontent.com/eco4cast/Statistical-Methods-Seminar-Series/main/fortin_spatial-models/bird_forest.csv")
birds <- read.csv(url)
str(birds)
## 'data.frame': 1359 obs. of 5 variables:
## $ xUTM : num 1393512 1533512 1283512 1153512 1233512 ...
## $ yUTM : num 11908203 11948203 12098203 11758203 12218203 ...
## $ Forest: int 3 4 5 6 7 14 15 18 30 35 ...
## $ Bird : num 0 0 0 0 0.08 ...
## $ Zones : int 1 1 1 1 1 1 1 1 1 1 ...
Professor Fortin plotted the data in a very straightforward way, something like this:
plot(birds$xUTM, birds$yUTM, cex = sqrt(birds$Bird), asp = 1)
You can just make out the outlines of several Great Lakes in this image. (Did Syracuse make it onto this map?)
The challenge is to come up with a way to present this information on a more informative and attractive way.
Pick a movement data set of your choice with multiple individuals (but no more than 20). Ideally, a dataset that you plan to investigate yourself. Alternatively, work with some subset of the Ya Ha Tinda elk dataset on Movebank, following the instructions in Chapter: Movement Data in R.
Create a table that reports for each individual (i) the number of locations, (ii) the start, end time and duration of the monitoring, (iii) the median, mean and standard deviation of the duty cycle (i.e. the duration between subsequent observations).
Report the following statistics:
Produce the following plots:
For each location, compute the step-length preceding that location, the time interval of that step, and the movement rate.
Produce a box-plot of the movement rate across all individuals against month of year, i.e. not just “Jan-Feb” and “July-August” like in the example, but for each month.
Can you detect any patterns? Discuss.
Extremely valuable extra credit: Fit some smoother (e.g. a GAM model or a LOESS smoother) to those movement rates across the year.
There are several amazing and underappreciated base R functions. For
example, outer
, which takes TWO vectors and ONE function
(that takes two arguments) and applies that functon to every combination
of the two vectors. For example, here’s a multiplication table (to
5’s):
a <- 1:5
b <- 1:5
outer(a,b,"*")
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 2 3 4 5
## [2,] 2 4 6 8 10
## [3,] 3 6 9 12 15
## [4,] 4 8 12 16 20
## [5,] 5 10 15 20 25
Another very useful function is apply
, which lets you
apply a function across rows or columns of a matrix. So, for example,
here’s the sum of the rows of this table:
apply(outer(a,b,"*"), 1, sum)
## [1] 15 30 45 60 75
I emailed you a file, AmericanBeech.csv
which contains
the coordinates of American beech trees (Fagus grandifola)
measured at SUNY-ESF’s Adirondack Research Station in 1985, 2000 and
2009 (data courtesy of M.
Dovciak).
Load those data, convert the coordinates to complex numbers, and plot.
Use outer
and apply
to compute the
distance from each tree to it’s nearest neighbor,
Report the mean nearest neighbor distance, the inter-quartile intervals, and plot a histogram. Describe
Note: (b) is a bit tricky, but when you get it, it’s very elegant (in my opinion). Just as a hint, you will need to create a new function that takes two locations, and computes the distance between them. Here’s a template:
getD <- function(Z1, Z1){
...
return(distance)
}
your goals for this class and - if possible - an idea for a final project.