Exercise 3


Data

In this exercise, we will use parts of a dataset from Jensen et al. (2022), looking into body size adaptations in a wild population of Atlantic salmon (Salmo salar). The salmon resides in a river impacted by hydropower development, affecting the waterflow in the river. The phenotypic time series used here can also be downloaded (in raw version) from the PETS database. The body size is measured as weight (grams). The waterflow (climatic variable) is measured as volume/time ($\frac{m^3}{s}$) from june to september. The measurements span 77 years, from 1940 to 2016, with 8 years missing (1958-1965), a total of 69 measured years. The data include number of samples (N), trait/waterflow mean, trait/waterflow variance, and the age (year of sampling).

Note: Where the sample size is 1 for the waterflow dataset, the variance is set to $\text{mean} \times 0.05$.

Download the body size measurements and waterflow data (click the links), and place the files in your working directory.

Import and prepare data in R

Now, we are going to import the text files into R and get them into the correct format for analysis with evoTS. Make sure you have loaded the necessary packages (evoTS and tidyverse).

First, set your working directory:

setwd("PATH_TO_WORKING_DIRECTORY")

Then, import the data:

body_size <- read_delim("./body_size.txt", col_names = TRUE, delim = "\t")
waterflow <- read_delim("./waterflow_jun_sep.txt", col_names = TRUE, delim = "\t")

It is easier to work with the time series if we store them in a list like this:

data <- list()
data$body_size <- as.list(body_size)
data$waterflow <- as.list(waterflow)

And now we can transform the data into paleoTS objects:

paleoTS_data <- lapply(data, function(x) {
  paleoTS::as.paleoTS(mm = x$trait_mean, vv = x$trait_var, nn = x$N, tt = x$year, oldest = "first")
})

Next, we log-transform the data:

ln_data <- lapply(paleoTS_data, paleoTS::ln.paleoTS)

We also convert the time vector to relative time (0 to 1):

ln_data <- lapply(ln_data, function(x) {
  x$tt <- x$tt/(max(x$tt))
  x
})

The last thing to do is to convert the data into a multivariate evoTS object:

evoTS_data <- make.multivar.evoTS(ln_data$body_size, ln_data$waterflow)

Now you are ready to analyse the data!

Analyses and questions

Use what you have learned in the tutorial to explore the data. You can for example first plot the data to visualise it and then analyse it by fitting different multivariate models, both different types of unbiased random walks and OU models.

Suggestions for questions to think about:


When you feel done working with this exercise, move along to exercise 4.