| Title: | Produce an epidemiological risk map by weighting multiple risk factors |
|---|---|
| Description: | Use a Shiny interface to help users import multiple layers of risk factors, scale and combine them using a Multi-Criteria Decision Analysis approach to produce a risk map as an outcome. |
| Authors: | Facundo Muñoz [aut, cre] (Package developer, ORCID: <https://orcid.org/0000-0002-5061-4241>), Sylvain Falala [aut] (Shiny interface), Andrea Apolloni [ctb] (Animal mobility algorithm), Elena Arsevska [ctb], Françoise Chirara [ctb] (Logo designer), Jean Marc Feussom [ctb], Renaud Lancelot [ctb], Etienne Loire [ctb], Raphaëlle Metras [ctb], Oumaima Mtaallah [ctb], David Pleydell [ctb] |
| Maintainer: | Facundo Muñoz <[email protected]> |
| License: | GPL-3 + file LICENSE |
| Version: | 0.5.19 |
| Built: | 2026-10-16 07:21:00 UTC |
| Source: | https://forge.inrae.fr/umr-astre/mapMCDA |
Convert a list of rasters to a common projection, resolution and extent.
align_layers(x)align_layers(x)
x |
list of SpatRaster objects |
The final projection is the most common one, other than NA. If a raster has unknown projection, it is assumed to be equal to the most common one.
All rasters are resampled to the same extent and resolution as the first raster in the list.
Another list of SpatRaster objects
Given a square reciprocal-symmetric ratio matrix from an Analytic Hierarchy Process, calculate the vector of weights using the using the Pairwise Comparison Method (Saaty 1987, Saaty 1996, Malczewski 1999)
compute_weights(x)compute_weights(x)
x |
matrix of pair-wise assessment of relative importance of risk factors. |
numeric vector of weights
Saaty, R. W. (1987). The analytic hierarchy process–what it is and how it is used. Mathematical Modelling 9 (3-5), 161-176.
Saaty, T. L. (1996). Multicriteria decision making : the analytic hierarchy process : planning, priority setting, resource allocation. RWS Publications.
Malczewski J. GIS and multicriteria decision analysis. Inc New York: John Wiley & Sons; 1999.
compute_weights(matrix(1, 5, 5))compute_weights(matrix(1, 5, 5))
This should be exported in the geonetwork package.
## S4 method for signature 'geonetwork' crs(x, ...)## S4 method for signature 'geonetwork' crs(x, ...)
x |
A geonetwork object. |
... |
Not used. |
A crs object.
cmr <- mapMCDA_datasets() crs(cmr$mobility)cmr <- mapMCDA_datasets() crs(cmr$mobility)
Returns the separator that consistently separates the lines in the same number of fields, or fails.
csv_sep(x)csv_sep(x)
x |
character. File name. |
Tested separators are: ",", " ", "\t", "|", ";", ":"
Character representation of the field separator.
tf <- tempfile() td <- data.frame(T = LETTERS[1:10], N = 1:10) write.csv(td, tf, row.names = FALSE) csv_sep(tf) # "," write.csv2(td, tf, row.names = FALSE) csv_sep(tf) # ";"tf <- tempfile() td <- data.frame(T = LETTERS[1:10], N = 1:10) write.csv(td, tf, row.names = FALSE) csv_sep(tf) # "," write.csv2(td, tf, row.names = FALSE) csv_sep(tf) # ";"
Returns a distance map (in meters) to spatial features.
distance_map(x, boundaries, res = resolution(boundaries, max_ncells = 100))distance_map(x, boundaries, res = resolution(boundaries, max_ncells = 100))
x |
sf or sfc object with relevant spatial features. |
boundaries |
sf or sfc POLYGON object with administrative borders, or SpatRaster object from where to pick the resolution. |
res |
numeric. Resolution for the outcome distance map. The default divides the smallest dimension into 100 cells. |
Distances are computed up to the given boundaries and at given resolution.
A raster map with distances in meters to the closest spatial feature.
cmr <- mapMCDA_datasets() plot(distance_map(x = cmr$water_bodies, boundaries = cmr$cmr_admin3))cmr <- mapMCDA_datasets() plot(distance_map(x = cmr$water_bodies, boundaries = cmr$cmr_admin3))
Compute a raster file with the distances to the nearest vector feature, within the limits of a given mask.
distance_to_vector(x, mask)distance_to_vector(x, mask)
x |
SpatVector object, or something convertible to. |
mask |
SpatRaster object |
The resolution of the mask determines that of the outcome.
SpatRaster object. Distance map in meters (even for unprojected maps in geographical coordinates).
cmr <- mapMCDA_datasets() dist_wb <- distance_to_vector(cmr$water_bodies, cmr$animal.density) plot(dist_wb)cmr <- mapMCDA_datasets() dist_wb <- distance_to_vector(cmr$water_bodies, cmr$animal.density) plot(dist_wb)
Download Country Administrative Borders from GADM
download_country_admin(country_name, level = 3, path = tempdir())download_country_admin(country_name, level = 3, path = tempdir())
country_name |
character. A valid country name. |
level |
integer 0:3. |
path |
character. Where to store the downloaded object. |
A sf object.
cmr <- download_country_admin("Cameroon")cmr <- download_country_admin("Cameroon")
Weighted and unweighted Epidemic Threshold of a graph.
epidemic_threshold(x, beta = 1)epidemic_threshold(x, beta = 1)
x |
an |
beta |
numeric, between 0 and 1. Probability of transmission. |
The Epidemic Threshold quantifies the minimal expeced
transmission coefficient necessary for diffusing an epidemy in a
network. It is computed as the inverse of the Potential for
transmission of the network: a measure of the expected number of
nodes affected by an infectious node, which is a generalisation of
the Basic Reproduction Number of an epidemy to the
context of a network. It thus quantifies the potential for
transmission of an infection throughout the contact network. It is
computed in terms of the incoming-outgoing rates from the network's
nodes:
where is the transmission coefficient among animals,
are the in/out-degrees of a node
and the symbol represents the average value
across all nodes in the graph.
The unweighted value computed above is most appropriate for a highly infectious epidemy with high animal-prevalence on nodes, as it assumes that any contact is potentially infectious.
In the weighted formulation, are
the weight values for the incoming/outgoing edges in each node. It
is more appropriate for low-prevalence diseases, where the
transmission probability is assumed proportional to the number of
contacts.
The default value of 1 for the probability of transmission
implies that every infectious contact leads to
transmission.
a list the weighted and unweighted Potential for
Transmission and its inverse, the Epidemic
Threshold . As an attribute named "sna", a data.frame with
the in/out-degrees of each node and their individual contribution
to R0.
If the input graph is unweighted, the weighted component is NULL.
Volkova VV, Howey R, Savill NJ, Woolhouse MEJ (2010) Sheep Movement Networks and the Transmission of Infectious Diseases. PLoS ONE 5(6): e11185. https://doi.org/10.1371/journal.pone.0011185
g <- igraph::graph_from_literal(A --+ B --+C, A --+C, B --+D) epidemic_threshold(g) ## weighted graph igraph::E(g)$weight <- c(10, 1, 2, 5) epidemic_threshold(g)g <- igraph::graph_from_literal(A --+ B --+C, A --+C, B --+D) epidemic_threshold(g) ## weighted graph igraph::E(g)$weight <- c(10, 1, 2, 5) epidemic_threshold(g)
Recognise the geographical type of an object representing a risk factor.
factor_type(x)factor_type(x)
x |
Any object. |
Character. Either "vector", "raster" or "network" depending on the object class. NA for unknown formats.
factor_type(terra::rast()) factor_type(sf::st_sf(sf::st_sfc()))factor_type(terra::rast()) factor_type(sf::st_sf(sf::st_sfc()))
Check whether a matrix is reciprocal. This is, whether the entrywise product of itself with its transpose (Hadamard product) is 1 for all its elements.
is.reciprocal(x)is.reciprocal(x)
x |
square numeric matrix or number |
logical
Xf <- matrix(1:16, 4, 4) Xr <- Xf Xr[upper.tri(Xf)] <- 1/t(Xf)[upper.tri(Xf)] diag(Xr) <- 1 mapMCDA:::is.reciprocal(Xf) # FALSE mapMCDA:::is.reciprocal(Xr) # TRUEXf <- matrix(1:16, 4, 4) Xr <- Xf Xr[upper.tri(Xf)] <- 1/t(Xf)[upper.tri(Xf)] diag(Xr) <- 1 mapMCDA:::is.reciprocal(Xf) # FALSE mapMCDA:::is.reciprocal(Xr) # TRUE
Either "vector", "raster" or "network" depending on the file extension.
layer_type(x)layer_type(x)
x |
string. A file name. |
character. Either "vector", "raster" or "network". NA for unknown formats.
layer_type("myfile.tif") layer_type("myfile.gpkg")layer_type("myfile.tif") layer_type("myfile.gpkg")
Load all recognised vector and raster files within a given directory.
load_dir(path)load_dir(path)
path |
String. The path to the directory where spatial layers are stored. |
list of layers in the form of sf or SpatRaster objects
pkg_layers <- system.file(path = "cartography/CMR/", package = "mapMCDA") cmr <- load_dir(pkg_layers)pkg_layers <- system.file(path = "cartography/CMR/", package = "mapMCDA") cmr <- load_dir(pkg_layers)
Automatically detects whether it is a vector or raster map and uses the appropriate read function.
load_layer(x)load_layer(x)
x |
File name with full path |
A sf object for vector maps and a SpatRaster
object for raster maps.
(pkg_layers <- list.files( system.file("cartography/CMR", package = "mapMCDA"), full.names = TRUE )) epiunits <- load_layer(pkg_layers[[2]])(pkg_layers <- list.files( system.file("cartography/CMR", package = "mapMCDA"), full.names = TRUE )) epiunits <- load_layer(pkg_layers[[2]])
Launches the graphical interface (GUI) of the package.
mapMCDA_app(bg = FALSE)mapMCDA_app(bg = FALSE)
bg |
Logical. If TRUE, the GUI is launched in the background, leaving available the current session. |
Loads a list of 4 geographical layers of Cameroon. Namely: the raster of animal density, the administrative borders at the third level, the national parks and the water bodies.
mapMCDA_datasets()mapMCDA_datasets()
Sources are the Gridded Livestock of the World database (ref?), the Global Administrative Boundaries database (gadm.org), and ???.
list of spatial layers
cmr <- mapMCDA_datasets()cmr <- mapMCDA_datasets()
Plot geographical risk map of different types optionally with administrative divisions in the background.
plot_riskfactor(x, admin = NULL, pal = grDevices::hcl.colors(50))plot_riskfactor(x, admin = NULL, pal = grDevices::hcl.colors(50))
x |
An object of class 'sf', 'SpatRaster' or 'geonetwork'. |
admin |
A 'sf' POLYGONS object with administrative units. |
pal |
Character vector. Colours. The default is grDevices::hcl.colors(50). #' |
cmr <- mapMCDA_datasets() plot_riskfactor(cmr$animal.density) plot_riskfactor(cmr$mobility, admin = cmr$cmr_admin3) plot_riskfactor(cmr$water_bodies, admin = cmr$cmr_admin3)cmr <- mapMCDA_datasets() plot_riskfactor(cmr$animal.density) plot_riskfactor(cmr$mobility, admin = cmr$cmr_admin3) plot_riskfactor(cmr$water_bodies, admin = cmr$cmr_admin3)
Compute a raster with the importance of the nearest network node.
## S4 method for signature 'geonetwork,SpatRaster' rasterize(x, y, field = "importance", ...) ## S4 method for signature 'geonetwork,sf' rasterize(x, y, res = resolution(y, max_ncells = 100), ...)## S4 method for signature 'geonetwork,SpatRaster' rasterize(x, y, field = "importance", ...) ## S4 method for signature 'geonetwork,sf' rasterize(x, y, res = resolution(y, max_ncells = 100), ...)
x |
a geographic network (a geonetwork object with node attributes "Lon" and "Lat" in the WGS84 reference system) |
y |
a SpatRaster or a sf or sfc object. |
field |
character. The attribute of the network nodes to be
assigned to the voronoi polygon associated with each node. By
default it computes the importance of each node in the
network. But you can manually compute any other measure of
interest, and pass it as a vertex attribute (see
|
... |
Other arguments passed on to
|
res |
numeric vector of length 2. Resolution in Lon/Lat of rasterisation. |
This assumes that the network object has node attributes "Lon" "Lat" in the WGS84 reference system.
If the graph is weighted, the weighted importance will be computed.
If you want the unweighted importance, remove the weight attribute
from the graph with igraph::delete_edge_attr(x, "weight").
The importance of each node is computed as the relative
contribution to the Potential for Transmision of the
graph. I.e., . See epidemic_threshold.
Read a csv file with a specific format (see Details) and intepret it as network origin-destination data with possibly weighted edges.
read_network(x)read_network(x)
x |
character. Path of csv file |
The file must be plain text with comma-separated columns and variable names in the first line. Field separators other than comma are also supported. In particular, semi-colon field separators and comma decimal separator. There must be either 6 or 7 columns in the same order and of the same types as follows:
origin character
destination character
lon_orig numeric (decimal degrees, WGS84)
lat_orig numeric (decimal degrees, WGS84)
lon_dest numeric (decimal degrees, WGS84)
lat_dest numeric (decimal degrees, WGS84)
volume Optional. directed flux in some consistent unit
Variable names can be different. If strings contain spaces they must be quoted. For this reason, quotes cannot be part of node names. E.g. the name Abangminko'O is invalid and will rise an error.
Each origin-destination must be specified only once. If you have multple animal shipments between the same origin and destination spread in several lines, you need to aggregate them into a single line.
Make sure coordinates are consistent. I.e. All nodes must have the same coordinates in all the lines where it appears as either source or destination.
Object of classes geonetwork and igraph.
d <- data.frame(from = "A", to = "B", fx = 0, fy = 0, tx = 1, ty = 1) tf <- tempfile() write.csv(d, tf, row.names = FALSE) read_network(tf)d <- data.frame(from = "A", to = "B", fx = 0, fy = 0, tx = 1, ty = 1) tf <- tempfile() write.csv(d, tf, row.names = FALSE) read_network(tf)
Compute a resolution in the original map units that conforms to given criteria.
resolution(x, max_ncells = 100)resolution(x, max_ncells = 100)
x |
a SpatRaster or sf or sfc object |
max_ncells |
Number of cells for the largest dimension |
A number. The resolution that respects the desired number of cells.
r <- terra::rast(nrows = 5, ncols = 11, xmin = 0, xmax = 11, ymin = 0, ymax = 5) resolution(r, max_ncells = 10)r <- terra::rast(nrows = 5, ncols = 11, xmin = 0, xmax = 11, ymin = 0, ymax = 5) resolution(r, max_ncells = 10)
Compute a raster map from the input layer and rescale with a linear relationship.
risk_layer(x, boundaries, scale_target = c(0, 100))risk_layer(x, boundaries, scale_target = c(0, 100))
x |
a sf, sfc, SpatRaster or igraph object |
boundaries |
a sf or sfc object, used to determine the boundaries of the computed risk layer. |
scale_target |
numeric vector of length 2. New scale. |
For sf objects (geometries such as point, lines or polygons),
compute the distance_map(), which gives a SpatRaster. For
igraph objects (from network data), compute a SpatRaster
with the relative importance of the nearest node. For a SpatRaster
mask, extend or crop to the boundaries as needed.
Finally, scale the SpatRaster outcome of any of the three input types. If you need an inverse relationship, just reverse the target scale.
A SpatRaster object in the new scale.
ad <- mapMCDA_datasets()$animal.density bd <- mapMCDA_datasets()$cmr_admin3 plot(ad) plot(risk_layer(ad, bd, scale_target = c(-1, 1))) plot(risk_layer(ad, bd, scale_target = c(1, -1)))ad <- mapMCDA_datasets()$animal.density bd <- mapMCDA_datasets()$cmr_admin3 plot(ad) plot(risk_layer(ad, bd, scale_target = c(-1, 1))) plot(risk_layer(ad, bd, scale_target = c(1, -1)))
Represent the value of risk by epidemiological unit categorised into n risk-levels
risk_plot(x, v, n)risk_plot(x, v, n)
x |
sf object. Epidemiological units. |
v |
Numeric. Risk values. |
n |
Number of risk levels. |
plot
epi_units <- mapMCDA_datasets()$cmr_admin3 risk_plot(epi_units, seq.int(nrow(epi_units)), n = 4)epi_units <- mapMCDA_datasets()$cmr_admin3 risk_plot(epi_units, seq.int(nrow(epi_units)), n = 4)
Represent the value of risk by epidemiological unit categorised into n risk-levels
risk_table(x, v, n)risk_table(x, v, n)
x |
sf object. Epidemiological units. |
v |
Numeric. Risk values. |
n |
Number of risk levels. |
data.frame
epi_units <- mapMCDA_datasets()$cmr_admin3 risk <- runif(nrow(epi_units), 0, 100) risk_table(epi_units, risk, n = 4)epi_units <- mapMCDA_datasets()$cmr_admin3 risk <- runif(nrow(epi_units), 0, 100) risk_table(epi_units, risk, n = 4)
Compute the risk for each of the epidemiological units.
risk_unit(r, eu, fun = mean)risk_unit(r, eu, fun = mean)
r |
SpatRaster object |
eu |
sf or sfc object of type POLYGON |
fun |
A summary function. By default the mean. |
Summarises the level of risk using a function such as the mean or median value across the epidemiological unit.
numeric vector of the same length as the number of epidemiological units.
cmr <- mapMCDA_datasets() cmr$cmr_admin3$rv <- risk_unit(r = cmr$animal.density, eu = cmr$cmr_admin3) plot(cmr$cmr_admin3["rv"], pal = hcl.colors, nbreaks = 4, breaks = "quantile")cmr <- mapMCDA_datasets() cmr$cmr_admin3$rv <- risk_unit(r = cmr$animal.density, eu = cmr$cmr_admin3) plot(cmr$cmr_admin3["rv"], pal = hcl.colors, nbreaks = 4, breaks = "quantile")
Removes the trailing characters after and including the last point in a string.
rmext(x)rmext(x)
x |
Character |
character.
rmext("some/long.filename.extension")rmext("some/long.filename.extension")
Compute a voronoi tesselation of a map for a set of points.
voronoi(x, ext, eps = 1e-09)voronoi(x, ext, eps = 1e-09)
x |
sf POINTS or two-column matrix or data.frame with x and y coordinates. |
ext |
Extent object. |
eps |
Numerical tolerance used in triangulation. See |
sf POLYGON object.
Borrowed from function voronoi from
package dismo by R. Hijmans et al., which ultimately
uses the deldir function by Rolf Turner.
pts <- data.frame(x = c(1:2, 2), y = c(1, 1:2)) region <- terra::ext(c(0, 3, 0, 3)) plot(sf::st_geometry(voronoi(pts, region))) points(pts)pts <- data.frame(x = c(1:2, 2), y = c(1, 1:2)) region <- terra::ext(c(0, 3, 0, 3)) plot(sf::st_geometry(voronoi(pts, region))) points(pts)
Combine a list of risk layers using a weighted linear approach:
wlc(x, w, na.rm = TRUE)wlc(x, w, na.rm = TRUE)
x |
list of risk factors (SpatRaster objects) |
w |
vector of weights |
na.rm |
logical. |
Missing values are by default removed from the combination, yielding a result
that relies on the available factors in each place. If na.rm = FALSE,
then all pixels where at least one risk factor is missing get a missing value
as the result.
A SpatRaster object.