Newer
Older
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
---
output: github_document
---
<!-- 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%"
)
```
# spreadrate
<!-- badges: start -->
<!-- badges: end -->
The goal of spreadrate is to estimate the __local velocity of
propagation__ of an epidemic event, given dates and locations of
observed cases.
The method estimates the surface of __first date of invasion__ by
interpolation of the earliest observations in a neighbourhood and
derives the __local spread rate__ as the inverse slope of the surface.
Furthermore, it helps to quantify the estimation uncertainty by a
Monte Carlo approach. Visualise and simulate the spatio-temporal
progress of epidemics.
## Installation
To install the latest version of spreadrate, copy and paste the
following in a R session.
``` r
if (!require("remotes")) {
install.packages("remotes")
}
install.packages("INLA", repos="https://inla.r-inla-download.org/R/testing")
remotes::install_gitlab("umr-astre/spreadrate", host = "forgemia.inra.fr")
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
```
## Example
Suppose that we have recorded the GPS coordinates and observation
dates for all the observed cases of some emerging disease in mainland
France into a table like this one.
```{r setup-fake-data, echo = FALSE, message=FALSE}
require(sf)
require(tidyverse)
set.seed(20190621)
fr_sf <- st_as_sf(maps::map("france", plot = FALSE)) %>%
st_transform(2154)
locs <- st_sample(fr_sf, 50)
## Assume dates progress at a constant rate from the north-east
dist_NE <- st_distance(
locs, st_sfc(st_point(st_bbox(fr_sf)[c("xmax", "ymax")]), crs = 2154)
) %>% as.numeric
velocity <- 1e4 # m/day
cases_sf <- st_sf(locs, date = as.Date("2019-01-01") + dist_NE / velocity) %>%
arrange(date)
```
```{r show-table, echo = FALSE}
(
cases <- bind_cols(
st_drop_geometry(cases_sf) %>% as_tibble(),
cases_sf %>%
st_transform(4326) %>%
st_coordinates() %>%
data.frame() %>%
setNames(c("Lon", "Lat"))
)
)
```
Here is a visual representation of these observed cases.
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
require(tmap)
tm_shape(fr_sf) +
## Country limits
tm_polygons(col = "gray95") +
## Observed cases
tm_shape(
cases_sf %>%
mutate(
day_num = as.numeric(date - min(date))
)
) +
tm_dots(
title = "Date",
col = "day_num",
size = .2,
palette = "viridis",
style = "cont",
breaks = c(0, as.numeric(diff(range(cases_sf$date)))),
labels = paste(range(cases_sf$date))
) +
tm_legend(
position = c("left", "bottom"),
bg.color = TRUE
) +
tm_compass(position = c("left", "top")) +
tm_scale_bar(position = c("right", "bottom"), size = .8)
```
First let `spreadrate` interpret the observational data appropriately
with the function `sr_obs()`. You need to specify the name of the
temporal variable. _Lon_ and _Lat_ are recognised automatically.
```{r sr-obs}
library(spreadrate)
cases_sr <- sr_obs(cases, "date")
```
However, spread-rate calculations require projected (rather than
geographic) coordinates. An appropriate projection for mainland France
is EPSG:2154. See https://epsg.io/.
```{r transform-coordinates}
cases_sr <- st_transform(cases_sr, crs = 2154)
```
Everything is now set to perform a default estimation of spread-rate.
```{r warning = FALSE, message = FALSE}
sr_est <- sr(cases_sr)
```
Done! Here is a quick plot of the estimated local spread-rate.
The estimated velocity is practically constant, between 9 and 11 km /
day.
```{r quick-plot}
```
This is consistent with the value of `r velocity` m/day used for
simulating the data.
We can also retrieve the estimated surface of first-date of invasion:
```{r}
plot(attr(sr_est, "fdoi"), col = hcl.colors(12))
## References
__Tisseuil, Clément, Aiko Gryspeirt, Renaud Lancelot, Maryline Pioz,
Andrew Liebhold, and Marius Gilbert (2016)__. Evaluating Methods to Quantify
Spatial Variation in the Velocity of Biological Invasions. _Ecography_
39, no. 5: 409–418. https://doi.org/10.1111/ecog.01393.