knitr::opts_chunk$set(echo = TRUE)
devtools::load_all()

In this page I'll show how to analyze TPD using the tools from this package. By analyze I am referring to the extraction of both a prediction of a thermal performance curve (TPC) and thermal performance traits (TPTs) from a data set with temperature ($T_m$) and PIT equivalent to performance ($P$). I'll first show a basic individual-level example and later I'll move on to more complex population and multipopulation level cases.

Analyze Individual TPD

a. Get TPC

To get a TPC from an individual's TPD you first have to fit a polynomial regression between $Tm$ & $P$. A polynomial regression is defined by it's degree which is "the highest of the degrees of the polynomial's monomials (individual terms) with non-zero coefficients". In other words, the highest power it has. For example, the mathematical expression for a polynomial regression of degree 3 would look like:

$$y = \alpha + \beta_{1} x + \beta_{2} x^{2} + \beta_{3} x^{3}$$ Being "3" the highest power in the expression. The key point with a polynomial regression's degree is the shape of the resulting function. The most interesting polynomial functions to fit a TPC are the quadratic (Degree 2), cubic (Degree 3) and quadratic (Degree 4) functions. A quadratic regression fits a symmetric curve, a cubic function (if the upwards bump region is considered) can fit an asymmetric curve and a quadratic function can fit an asymmetric and non-steadily declining curve.

Which curve is best for a given data? The answer lies on their AIC scores. For a given data set, the regression that achieves the lowest AIC score will be the one best representing the model (Here I would get into a technical discussion on how the AIC works and why the WAIC is better but I'll keep that for myself).

As part of this package, I have developed a function called get_tpc (get thermal performance curve) which automates the process. As arguments, it takes:

Using this information the get_tpc returns another data set with four columns:

Below I generate a mock TPD for an individual and I draw it's TPC using the get_tpc function.

# generate data
ind_tpdata <- gen_tpd( Topt = 25, CTmax = 28, CTmin = 22, Pmax = 22, Pmin = 0, Error = 2, Samples = 20, Degree = 3)

# get curve
ind_curve <- get_tpc( Tm = ind_tpdata$Tm, P = ind_tpdata$P, Degree = 3, Pmin = 0)
head(ind_curve)
ggplot( data = ind_curve, aes(x = Tm, y = P)) + 
  geom_ribbon( aes(ymin = L, ymax = U), fill = "grey92") +
  geom_line( col = "red", size = 2) +
  geom_point( data = ind_tpdata, aes(x = Tm, y = P), size = 2) +
  theme_classic() +
  labs( x = "Temperature", y = "Performance") + 
  geom_hline( aes( yintercept = 0))  
  #ylim(0, max(ind_tpdata$P))

b. Get TPTs

Complementary to the TPC another interesting piece of information to extract from TP Data are its TPTs. According to Logan & Cox 2020 a TPC is defined by 4 TPTs:

As part of this package I have also developed the get_tpts function which, from a TPC can extract all these traits for a given TP data. Let me show an example:

ind_tpts <- get_tpts(Tm = ind_tpdata$Tm, P = ind_tpdata$P, Degree = 4, Pmin = 0)
ind_tpts

Analyze Population TPD

The same process can be applied to a whole population both by drawing a curve for the entire population and by getting each individuals (or the whole populations) TPTs. As an example below, I generate some population TP data and from it I extract the TPC and the TPTs.

# generate population data 
pop_tpd <- gen_pop_tpd(N = 15, Topt = 25, CTmax = 27, CTmin = 23, Pmax = 10, Pmin = 0, Error = 2, Samples = 10, Degree = 3)

# get the TPC 
pop_tpc <- get_tpc(Tm = pop_tpd$Tm, P = pop_tpd$P, Degree = 3, Pmin = 0)

# get the TPTs 
pop_tpts <- get_pop_tpts(TPD = pop_tpd, Degree = 3, Pmin = 0)

# small sample of the TPTs data
head(pop_tpts)
ggplot( data = pop_tpc, aes(x = Tm, y = P)) + 
  geom_ribbon( aes(ymin = L, ymax = U), fill = "grey92") +
  geom_line( col = "red", size = 2) +
  geom_point( data = pop_tpd, aes(x = Tm, y = P, colour = factor(ID)), size = 2) +
  theme_classic() +
  labs( x = "Temperature", y = "Performance", colour = "Individual ID") + 
  geom_hline( aes( yintercept = 0)) +
  theme(legend.position = "right")


ggcostoya/tpcurves2 documentation built on Jan. 1, 2021, 2:19 a.m.