Movatterモバイル変換


[0]ホーム

URL:


Introduction to rTPC

Daniel Padfield

2023-08-16

An introduction to rTPC and how it can be used to fit thermalperformance curves using nls.multstart.


# load packageslibrary(rTPC)library(nls.multstart)library(broom)library(tidyverse)

rTPC provides a suite of functions to help fitthermal performance curves to empirical data. After searching theliterature,rTPC contains 25 different modelformulations that have been used previously. These functions can beeasily applied to methods in R that use non-linear least squaresregression to estimate thermal performance curves.

The available model formulations can be accessed usingget_model_names().

get_model_names()#>  [1] "beta_2012"             "boatman_2017"          "briere2_1999"#>  [4] "delong_2017"           "deutsch_2008"          "flinn_1991"#>  [7] "gaussian_1987"         "hinshelwood_1947"      "joehnk_2008"#> [10] "johnsonlewin_1946"     "kamykowski_1985"       "lactin2_1995"#> [13] "lrf_1991"              "modifiedgaussian_2006" "oneill_1972"#> [16] "pawar_2018"            "quadratic_2008"        "ratkowsky_1983"#> [19] "rezende_2019"          "sharpeschoolfull_1981" "sharpeschoolhigh_1981"#> [22] "sharpeschoollow_1981"  "spain_1982"            "thomas_2012"#> [25] "thomas_2017"           "weibull_1995"

They are generally named after the author of the paper (and hence thename of the model within the literature) and the year at which I foundthe model to be first used, separated by a“_”. Someoriginal model formulations have been altered so that all models taketemperature in degrees centigrade and raw rate values as input.

We can demonstrate the fitting procedure by taking a single curvefrom the example datasetrTPC - a dataset of 60 TPCs ofrespiration and photosynthesis of the aquatic algae,Chlorellavulgaris. We can plot the data usingggplot2

# load in datadata("chlorella_tpc")# keep just a single curved<-filter(chlorella_tpc, curve_id==1)# show the dataggplot(d,aes(temp, rate))+geom_point()+theme_bw(base_size =12)+labs(x ='Temperature (ºC)',y ='Metabolic rate',title ='Respiration across temperatures')

For each model,rTPC has helper functions that estimatesensible start values (get_start_vals()), lower(get_lower_lims()) and upper(get_upper_lims()) limits. To demonstrate this, weshall use the sharpe-schoolfield model for high temperature inactivationonly.

# choose modelmod='sharpschoolhigh_1981'# get start valsstart_vals<-get_start_vals(d$temp, d$rate,model_name ='sharpeschoolhigh_1981')# get limitslow_lims<-get_lower_lims(d$temp, d$rate,model_name ='sharpeschoolhigh_1981')upper_lims<-get_upper_lims(d$temp, d$rate,model_name ='sharpeschoolhigh_1981')start_vals#>     r_tref          e         eh         th#>  0.7485827  0.8681437  2.4861344 43.0000000low_lims#> r_tref      e     eh     th#>      0      0      0      1upper_lims#>    r_tref         e        eh        th#>  1.616894 10.000000 20.000000 49.000000

One problem with most methods of fitting models in R using non-linearleast squares regression is that they are sensitive to the choice ofstarting parameters. This problem also occurs in previous specialist Rpackages that help fit thermal performance curves, such asdevRate andtemperatureresponse.These methods can fail entirely or give different parameter estimatesbetween multiple runs of the same code.

To overcome this, we recommend using the R packagenls.multstart,which usesminpackLM::nlsLM(), but allows for multiplesets of starting parameters. It iterates through multiple startingvalues, attempting a fit with each set of start parameters. The bestmodel is then picked using AIC scores.

Usingnls_multstart, we will use arandom-search/shotgun approach to fit the curve. Random start parametervalues are picked from a uniform distribution betweenstart_lower andstart_upper for eachparameter. If the best model is not improved upon (in terms of AICscore) for 100 new start parameter combinations, the function willreturn that model fit. This is controlled by convergence_count, if thisis set toFALSE,nls_multstart() will tryand fit all iterations.

# fit modelfit<-nls_multstart(rate~sharpeschoolhigh_1981(temp = temp, r_tref,e,eh,th,tref =15),data = d,iter =500,start_lower = start_vals-10,start_upper = start_vals+10,lower = low_lims,upper = upper_lims,supp_errors ='Y')fit#> Nonlinear regression model#>   model: rate ~ sharpeschoolhigh_1981(temp = temp, r_tref, e, eh, th,     tref = 15)#>    data: data#>  r_tref       e      eh      th#>  0.2595  0.5826 14.2031 43.5531#>  residual sum-of-squares: 0.3144#>#> Number of iterations to convergence: 22#> Achieved convergence tolerance: 1.49e-08

To calculate additional parameters of interest, we can userTPC::calc_params(). This function uses high resolutionpredictions of the fitted model to estimate traits associated with athermal performance curve. The currently available methods can be viewedby running?calc_params. For example, we may be interestedin variation in the optimum temperature,\(T_{opt}\), given that we adapted algae todifferent temperatures.

# calculate additional traitscalc_params(fit)%>%# round for easy viewingmutate_all(round,2)#>   rmax  topt ctmin ctmax    e    eh  q10 thermal_safety_margin#> 1 1.81 41.65  2.54 45.56 0.58 11.48 2.06                  3.91#>   thermal_tolerance breadth skewness#> 1             43.02    5.37    -10.9

Finally for this introduction, we can get predictions of our modelusingbroom::augment(), which is similar topredict(). These are then plotted over our originaldata.

# predict new datanew_data<-data.frame(temp =seq(min(d$temp),max(d$temp),0.5))preds<-augment(fit,newdata = new_data)# plot data and model fitggplot(d,aes(temp, rate))+geom_point()+geom_line(aes(temp, .fitted), preds,col ='blue')+theme_bw(base_size =12)+labs(x ='Temperature (ºC)',y ='Metabolic rate',title ='Respiration across temperatures')


[8]ページ先頭

©2009-2025 Movatter.jp