Package 'mapMCDA'

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

Help Index


Harmonise projection, resolution and extent of a list of rasters

Description

Convert a list of rasters to a common projection, resolution and extent.

Usage

align_layers(x)

Arguments

x

list of SpatRaster objects

Details

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.

Value

Another list of SpatRaster objects


Compute MCDA weights

Description

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)

Usage

compute_weights(x)

Arguments

x

matrix of pair-wise assessment of relative importance of risk factors.

Value

numeric vector of weights

References

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.

Examples

compute_weights(matrix(1, 5, 5))

CRS of a geonetwork object

Description

This should be exported in the geonetwork package.

Usage

## S4 method for signature 'geonetwork'
crs(x, ...)

Arguments

x

A geonetwork object.

...

Not used.

Value

A crs object.

Examples

cmr <- mapMCDA_datasets()
crs(cmr$mobility)

Detection of separator in csv files

Description

Returns the separator that consistently separates the lines in the same number of fields, or fails.

Usage

csv_sep(x)

Arguments

x

character. File name.

Details

Tested separators are: ",", " ", "\t", "|", ";", ":"

Value

Character representation of the field separator.

Examples

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)  # ";"

Compute a distance map to spatial features

Description

Returns a distance map (in meters) to spatial features.

Usage

distance_map(x, boundaries, res = resolution(boundaries, max_ncells = 100))

Arguments

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.

Details

Distances are computed up to the given boundaries and at given resolution.

Value

A raster map with distances in meters to the closest spatial feature.

Examples

cmr <- mapMCDA_datasets()
  plot(distance_map(x = cmr$water_bodies, boundaries = cmr$cmr_admin3))

Distance to vector features

Description

Compute a raster file with the distances to the nearest vector feature, within the limits of a given mask.

Usage

distance_to_vector(x, mask)

Arguments

x

SpatVector object, or something convertible to.

mask

SpatRaster object

Details

The resolution of the mask determines that of the outcome.

Value

SpatRaster object. Distance map in meters (even for unprojected maps in geographical coordinates).

Examples

cmr <- mapMCDA_datasets()
  dist_wb <- distance_to_vector(cmr$water_bodies, cmr$animal.density)
  plot(dist_wb)

Download Country Administrative Borders from GADM

Description

Download Country Administrative Borders from GADM

Usage

download_country_admin(country_name, level = 3, path = tempdir())

Arguments

country_name

character. A valid country name.

level

integer 0:3.

path

character. Where to store the downloaded object.

Value

A sf object.

Examples

cmr <- download_country_admin("Cameroon")

Compute the Epidemic Threshold of a graph

Description

Weighted and unweighted Epidemic Threshold qq of a graph.

Usage

epidemic_threshold(x, beta = 1)

Arguments

x

an igraph object

beta

numeric, between 0 and 1. Probability of transmission.

Details

The Epidemic Threshold qq 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 R0R_0 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:

R0=βkin⋅kout‾kin‾,R_0 = \beta \frac{\overline{k_\mathrm{in}\cdot k_\mathrm{out}}}{\overline{k_\mathrm{in}}},

where β\beta is the transmission coefficient among animals, kin/outk_\mathrm{in/out} are the in/out-degrees of a node and the ⋅‾\overline{\cdot} 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, kin/outk_\mathrm{in/out} 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 β\beta implies that every infectious contact leads to transmission.

Value

a list the weighted and unweighted Potential for Transmission R0R_0 and its inverse, the Epidemic Threshold qq. 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.

References

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

Examples

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)

Type of risk factor

Description

Recognise the geographical type of an object representing a risk factor.

Usage

factor_type(x)

Arguments

x

Any object.

Value

Character. Either "vector", "raster" or "network" depending on the object class. NA for unknown formats.

Examples

factor_type(terra::rast())
  factor_type(sf::st_sf(sf::st_sfc()))

Check reciprocal matrix

Description

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.

Usage

is.reciprocal(x)

Arguments

x

square numeric matrix or number

Value

logical

Examples

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)  # TRUE

Detect type of geographic information

Description

Either "vector", "raster" or "network" depending on the file extension.

Usage

layer_type(x)

Arguments

x

string. A file name.

Value

character. Either "vector", "raster" or "network". NA for unknown formats.

Examples

layer_type("myfile.tif")
  layer_type("myfile.gpkg")

Load all layers within a directory

Description

Load all recognised vector and raster files within a given directory.

Usage

load_dir(path)

Arguments

path

String. The path to the directory where spatial layers are stored.

Value

list of layers in the form of sf or SpatRaster objects

Examples

pkg_layers <- system.file(path = "cartography/CMR/", package = "mapMCDA")
   cmr <- load_dir(pkg_layers)

Load a map layer

Description

Automatically detects whether it is a vector or raster map and uses the appropriate read function.

Usage

load_layer(x)

Arguments

x

File name with full path

Value

A sf object for vector maps and a SpatRaster object for raster maps.

Examples

(pkg_layers <- list.files(
   system.file("cartography/CMR", package = "mapMCDA"),
   full.names = TRUE
 ))
 
 epiunits <- load_layer(pkg_layers[[2]])

mapMCDA Shiny web interface

Description

Launches the graphical interface (GUI) of the package.

Usage

mapMCDA_app(bg = FALSE)

Arguments

bg

Logical. If TRUE, the GUI is launched in the background, leaving available the current session.


Load packaged Cameroon layers into memory

Description

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.

Usage

mapMCDA_datasets()

Details

Sources are the Gridded Livestock of the World database (ref?), the Global Administrative Boundaries database (gadm.org), and ???.

Value

list of spatial layers

Examples

cmr <- mapMCDA_datasets()

Plot a risk factor

Description

Plot geographical risk map of different types optionally with administrative divisions in the background.

Usage

plot_riskfactor(x, admin = NULL, pal = grDevices::hcl.colors(50))

Arguments

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). #'

Examples

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)

Rasterize a geographic network

Description

Compute a raster with the importance of the nearest network node.

Usage

## 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), ...)

Arguments

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 ?igraph::`vertex_attr<-`).

...

Other arguments passed on to rasterize.

res

numeric vector of length 2. Resolution in Lon/Lat of rasterisation.

Details

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 R0R_0 of the graph. I.e., R0k/R0R_{0k}/R_0. See epidemic_threshold.


Read and interpret network data

Description

Read a csv file with a specific format (see Details) and intepret it as network origin-destination data with possibly weighted edges.

Usage

read_network(x)

Arguments

x

character. Path of csv file

Details

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.

Value

Object of classes geonetwork and igraph.

Examples

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 suitable resolution for a map

Description

Compute a resolution in the original map units that conforms to given criteria.

Usage

resolution(x, max_ncells = 100)

Arguments

x

a SpatRaster or sf or sfc object

max_ncells

Number of cells for the largest dimension

Value

A number. The resolution that respects the desired number of cells.

Examples

r <- terra::rast(nrows = 5, ncols = 11, xmin = 0, xmax = 11, ymin = 0, ymax = 5)
  resolution(r, max_ncells = 10)

Compute risk layer

Description

Compute a raster map from the input layer and rescale with a linear relationship.

Usage

risk_layer(x, boundaries, scale_target = c(0, 100))

Arguments

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.

Details

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.

Value

A SpatRaster object in the new scale.

Examples

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)))

Produce final plot of risk

Description

Represent the value of risk by epidemiological unit categorised into n risk-levels

Usage

risk_plot(x, v, n)

Arguments

x

sf object. Epidemiological units.

v

Numeric. Risk values.

n

Number of risk levels.

Value

plot

Examples

epi_units <- mapMCDA_datasets()$cmr_admin3
  risk_plot(epi_units, seq.int(nrow(epi_units)), n = 4)

Produce final table of risk levels by epidemiological unit

Description

Represent the value of risk by epidemiological unit categorised into n risk-levels

Usage

risk_table(x, v, n)

Arguments

x

sf object. Epidemiological units.

v

Numeric. Risk values.

n

Number of risk levels.

Value

data.frame

Examples

epi_units <- mapMCDA_datasets()$cmr_admin3
  risk <- runif(nrow(epi_units), 0, 100)
  risk_table(epi_units, risk, n = 4)

Risk by epidemiological unit

Description

Compute the risk for each of the epidemiological units.

Usage

risk_unit(r, eu, fun = mean)

Arguments

r

SpatRaster object

eu

sf or sfc object of type POLYGON

fun

A summary function. By default the mean.

Details

Summarises the level of risk using a function such as the mean or median value across the epidemiological unit.

Value

numeric vector of the same length as the number of epidemiological units.

Examples

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")

Remove filename extension

Description

Removes the trailing characters after and including the last point in a string.

Usage

rmext(x)

Arguments

x

Character

Value

character.

Examples

rmext("some/long.filename.extension")

Voronoi polygons

Description

Compute a voronoi tesselation of a map for a set of points.

Usage

voronoi(x, ext, eps = 1e-09)

Arguments

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 deldir.

Value

sf POLYGON object.

Author(s)

Borrowed from function voronoi from package dismo by R. Hijmans et al., which ultimately uses the deldir function by Rolf Turner.

Examples

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)

Weighted Linear Combination of risk factors

Description

Combine a list of risk layers using a weighted linear approach:

w1x1+w2x2+⋯w_1 x_1 + w_2 x_2 + \cdots

Usage

wlc(x, w, na.rm = TRUE)

Arguments

x

list of risk factors (SpatRaster objects)

w

vector of weights

na.rm

logical.

Details

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.

Value

A SpatRaster object.