-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
150 lines (107 loc) · 8.9 KB
/
Copy pathREADME.Rmd
File metadata and controls
150 lines (107 loc) · 8.9 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
---
output: github_document
bibliography: references.bib
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# mappestRisk <a href="https://ecologyr.github.io/mappestRisk/"><img src="man/figures/logo.png" alt="mappestRisk website" align="right" height="139"/></a>
<!-- badges: start -->
`r badger::badge_cran_release()`

[](https://ecologyr.r-universe.dev/mappestRisk)
[](https://ecologyr.r-universe.dev/mappestRisk)
[](https://github.com/EcologyR/mappestRisk/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/EcologyR/mappestRisk)
`r badger::badge_lifecycle("stable")`
`r badger::badge_repostatus("Active")`
[](https://cran.r-project.org/package=mappestRisk)
[](https://cran.r-project.org/package=mappestRisk)
<!-- badges: end -->
## Aims of the package
The goal of `mappestRisk` package is to facilitate the transition from development data of arthropod crop-pests' thermal biology obtained in lab-controlled conditions to understandable forecasts assessing risk of pest occurrence in a given region. Closing this gap usually involves two key steps: (1) fitting and selecting nonlinear regression models and derived thermal traits under ecological criteria, and (2) projecting these traits onto interest regions for pest risk assessment by extracting climate data. However, most data producers from physiology labs have limited opportunities and time to develop their R programming skills, so addressing these two steps may not be straightforward.
For this purpose, `mappestRisk` intends to facilitate this workflow for any researcher with minimal, basic R programming skills. This package has been built upon previous efforts such as `devRate` [@rebaudo2018], `rTPC` and `nls.multstart` packages [@padfield2021] and a methodology for predicting climatic suitability based on fundamental thermal niche as estimated by thermal performance curves, as suggested in @taylor2019 . Up to date, `mappestRisk` is built for modelling developmental thermal performance curves, since this is the most commonly measured life-history trait in experimental approaches and it has major contributions to fitness dependence on temperature [@pawar2024] and it also allows to predict phenologies [@vonschmalensee2021].
Therefore, `mappestRisk` has three different modules: *(1) model fitting & selection* using a set of the most commonly used equations describing developmental responses to temperature under the `nls.multstart` framework [@nls.multstart] using equation helpers from `rTPC`[@rTPC] and `devRate` [@devRate], with visualization of model fitting to help model selection by the user; (2) *calculation of suitability thermal limits,* which consist on a temperature interval delimiting the optimal performance zone or suitability; and (3) *climatic data extraction & visualization* with either exportable rasters or static or interactive map figures.
## Installation
The stable version can be installed from CRAN:
```{r, eval=FALSE}
install.packages('mappestRisk')
```
The package latest version can be installed from the [r-universe](https://ecologyr.r-universe.dev/mappestRisk):
```{r, eval=FALSE}
install.packages('mappestRisk', repos = c('https://ecologyr.r-universe.dev', 'https://cloud.r-project.org'))
```
You can also install its latest version from the [GitHub repository](https://github.com/EcologyR/mappestRisk) after installing either `remotes` or `devtools` R packages.
```{r, eval=FALSE}
remotes::install_github("EcologyR/mappestRisk")
#alternatively -> devtools::install_github("EcologyR/mappestRisk")
```
## Example: `mappestRisk` workflow
### 1. Fit thermal performance curves (TPC) to your data and plot results and parameter uncertainty:
In this example, we'll show how to fit one to several thermal performance curves to a data set of development rate variation across temperatures[^1]. The following code provides an example as given in `fit_devmodels()` function documentation, with a data table showing the output of fitted models, and how to visualize them for selecting curves using `plot_devmodels()`.
[^1]: At least 4 unique temperatures are required. Fore more details, see documentation and vignettes.
```{r plot.devmodels, warning=FALSE, message=FALSE}
library("mappestRisk")
data("aphid")
fitted_tpcs <- fit_devmodels(temp = aphid$temperature,
dev_rate = aphid$rate_value,
model_name = c("briere2", "lactin2", "thomas"))
plot_devmodels(temp = aphid$temperature,
dev_rate = aphid$rate_value,
fitted_parameters = fitted_tpcs,
species = "Brachycaudus schwartzi",
life_stage = "Nymphs")
```
For a more complete explanation and example of model fitting and visualization, see [TPCs model fitting](https://ecologyr.github.io/mappestRisk/articles/tpcs-model-fitting.html) article.
Additionally, we recommend here to propagate uncertainty in parameter estimation of the fitted and selected TPC models using bootstrap procedures with *residual resampling*, following vignettes of `rTPC` package [@padfield2021]. This can be done with the function `predict_curves()` by setting the argument `propagate_uncertainty` to be `TRUE`. Resulting predictions can be plotted using `plot_uncertainties()`. A detailed explanation is given in the [TPCs model fitting](https://ecologyr.github.io/mappestRisk/articles/tpcs-model-fitting.html) article.
```{r plot.unc, warning=FALSE, fig.width=12, fig.height=5, dpi=300, out.width="100%", cache = TRUE}
preds_boots <- predict_curves(temp = aphid$temperature,
dev_rate = aphid$rate_value,
fitted_parameters = fitted_tpcs,
model_name_2boot = c("briere2", "lactin2", "thomas"),
propagate_uncertainty = TRUE,
n_boots_samples = 10)
plot_uncertainties(bootstrap_tpcs = preds_boots,
temp = aphid$temperature,
dev_rate = aphid$rate_value,
species = "Brachycaudus schwartzi",
life_stage = "Nymphs")
```
### 2. Calculate thermal suitability bounds:
After the previous steps, the user can calculate the thermal boundaries of the optimal zone of the TPC –i.e., those temperature values yielding the Y-th quantile of the development rate (default to $\textrm{Q}_{75}$) at both sides of the curve peak or $R_\max$. Once a model has been selected under both ecological and statistical criteria, the `thermal_suitability_bounds()` function calculates these values:
```{r, warning=FALSE}
boundaries <- therm_suit_bounds(preds_tbl = preds_boots,
model_name = "lactin2",
suitability_threshold = 80)
```
### 3. Climatic data extraction and projection
These optimal thermal boundaries are used for spatial projection of pest risk. The `map_risk()` function automatically downloads temperature data into a `SpatRaster` format from [WorldClim](https://worldclim.org/data/worldclim21.html) masked into an user-defined region or area, and then calculates the number of months per year with highly suitable temperatures for pest development.
```{r message = FALSE, eval=FALSE}
risk_rast <- map_risk(t_vals = boundaries,
region = "Réunion",
path = tempdir() # directory to download climate data
)
```
```{r map, message = FALSE, eval=TRUE, echo=FALSE}
t_rast <- terra::rast("vignettes/articles/REU_wc2.1_30s_tavg.tif")
risk_rast <- map_risk(t_vals = boundaries,
t_rast = t_rast,
path = tempdir())
```
### Citation
If using this package, please cite it:
```{r comment=NA}
citation("mappestRisk")
```
## Funding
The development of this software has been funded by Fondo Europeo de Desarrollo Regional (FEDER) and Consejería de Transformación Económica, Industria, Conocimiento y Universidades of Junta de Andalucía (proyecto US-1381388, Universidad de Sevilla).

## Code of Conduct
Please note that the mappestRisk project is released with a [Contributor Code of Conduct](https://ecologyr.github.io/mappestRisk/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.
## References: