Title: | Mobility Oriented-Parity Metric |
---|---|
Description: | A set of tools to perform multiple versions of the Mobility Oriented-Parity metric. This multivariate analysis helps to characterize levels of dissimilarity between a set of conditions of reference and another set of conditions of interest. If predictive models are transferred to conditions different from those over which models were calibrated (trained), this metric helps to identify transfer conditions that differ substantially from those of calibration. These tools are implemented following principles proposed in Owens et al. (2013) <doi:10.1016/j.ecolmodel.2013.04.011>, and expanded to obtain more detailed results that aid in interpretation. |
Authors: | Marlon E. Cobos [aut, cre] , Hannah L. Owens [aut] , Jorge SoberĂ³n [aut] , A. Townsend Peterson [aut] |
Maintainer: | Marlon E. Cobos <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.2 |
Built: | 2024-11-03 04:35:23 UTC |
Source: | https://github.com/marlonecobos/mop |
mop
contains a set of tools to calculate the Mobility Oriented-Parity
metric, which allows a user to compare a set of conditions of reference
versus another set of of interest.
The main goals of the MOP metric are to explore conditions in the set of interest that are non-analogous to those in the reference set, and to quantify how different conditions in the set of interest are from the reference set. The tools included here help to identify conditions outside the ranges of the reference set with greater detail than in other implementations. These tools are based on the methods proposed by Owens et al. (2013; doi:10.1016/j.ecolmodel.2013.04.011).
mop
, mop_distance
, out_range
,
match_na_raster
reference_matrix
, matrix_of_interest
,
reference_layers
, layers_of_interest
Maintainer: Marlon E. Cobos [email protected] (ORCID)
Authors:
Hannah L. Owens [email protected] (ORCID)
Jorge SoberĂ³n [email protected] (ORCID)
A. Townsend Peterson [email protected] (ORCID)
Useful links:
A SpatRaster
object representing variables in a set of interest. Variables
represent future bioclimatic variables downloaded from the WorldClim database
(https://worldclim.org/).
A SpatRaster
object.
No return value. Used with function rast
to
bring raster variables to analysis.
layers_of_interest <- terra::rast(system.file("extdata", "layers_of_interest.tif", package = "mop")) terra::plot(layers_of_interest)
layers_of_interest <- terra::rast(system.file("extdata", "layers_of_interest.tif", package = "mop")) terra::plot(layers_of_interest)
Option to match cells with NA values in a SpatRaster with multiple layers.
match_na_raster(layers)
match_na_raster(layers)
layers |
a |
A SpatRaster
object with NA cells matching in all layers.
# data layers <- terra::rast(system.file("extdata", "reference_layers.tif", package = "mop")) # add NA in some places layers[20:24, 10:16][, 3] <- NA terra::plot(layers) # match NAs matched <- match_na_raster(layers) terra::plot(matched)
# data layers <- terra::rast(system.file("extdata", "reference_layers.tif", package = "mop")) # add NA in some places layers[20:24, 10:16][, 3] <- NA terra::plot(layers) # match NAs matched <- match_na_raster(layers) terra::plot(matched)
A numeric table representing variables in a set of interest.
matrix_of_interest
matrix_of_interest
A matrix with 723 rows and 6 columns.
data("matrix_of_interest", package = "mop") head(matrix_of_interest)
data("matrix_of_interest", package = "mop") head(matrix_of_interest)
Analysis to calculate the mobility-oriented parity metric and other
sub-products to represent dissimilarities and non-analogous conditions
when comparing a set of reference conditions (M; m
) against another
set of conditions of interest (G; g
).
mop(m, g, type = "basic", calculate_distance = FALSE, where_distance = "in_range", distance = "euclidean", scale = FALSE, center = FALSE, fix_NA = TRUE, percentage = 1, comp_each = 2000, tol = NULL, rescale_distance = FALSE, parallel = FALSE, n_cores = NULL, progress_bar = TRUE)
mop(m, g, type = "basic", calculate_distance = FALSE, where_distance = "in_range", distance = "euclidean", scale = FALSE, center = FALSE, fix_NA = TRUE, percentage = 1, comp_each = 2000, tol = NULL, rescale_distance = FALSE, parallel = FALSE, n_cores = NULL, progress_bar = TRUE)
m |
a |
g |
a |
type |
|
calculate_distance |
|
where_distance |
|
distance |
|
scale |
scaling options, |
center |
|
fix_NA |
|
percentage |
|
comp_each |
|
tol |
tolerance to detect linear dependencies when calculating
Mahalanobis distances. The default, NULL, uses |
rescale_distance |
|
parallel |
|
n_cores |
|
progress_bar |
|
type
options return results that differ in the detail of how non-analogous
conditions are identified.
basic - makes calculation as proposed by Owens et al. (2013) doi:10.1016/j.ecolmodel.2013.04.011.
simple - calculates how many variables in the set of interest are non-analogous to those in the reference set.
detailed - calculates five additional extrapolation metrics. See
mop_detailed
under Value
below for full details.
where_distance
options determine what values should be used to calculate
dissimilarity
in_range - only conditions inside m
ranges
out_range - only conditions outside m
ranges
all - all conditions
When the variables used to represent conditions have different units, scaling and centering are recommended. This step is only valid when Euclidean distances are used.
A object of class mop_results
containing:
summary - a list with details of the data used in the analysis:
variables - names of variables considered.
type - type of MOP analysis performed.
scale - value according to the argument scale
.
center - value according to the argument center
.
calculate_distance - value according to the argument
calculate_distance
.
distance - option regarding distance used.
percentage - percentage of m
used as reference for
distance calculation.
rescale_distance - value according to the argument
rescale_distance
.
fix_NA - value according to the argument fix_NA
.
N_m - total number of elements (cells with values or valid
rows) in m
.
N_g - total number of elements (cells with values or valid
rows) in g
.
m_ranges - matrix with ranges of variables in reference conditions
(m
).
mop_distances - if calculate_distance
= TRUE, a SpatRaster or
vector with distance values for the set of interest (g
). Higher values
represent greater dissimilarity compared to the set of reference (m
).
mop_basic - a SpatRaster or vector, for the set of interest, representing conditions in which at least one of the variables is non-analogous to the set of reference. Values should be: 1 for non-analogous conditions, and NA for conditions inside the ranges of the reference set.
mop_simple - a SpatRaster or vector, for the set of interest, representing how many variables in the set of interest are non-analogous to those in the reference set. NA is used for conditions inside the ranges of the reference set.
mop_detailed - a list containing:
interpretation_combined - a data.frame to help identify combinations
of variables in towards_low_combined and towards_high_combined that
are non-analogous to m
.
towards_low_end - a SpatRaster or matrix for all variables representing where non-analogous conditions were found towards low values of each variable.
towards_high_end - a SpatRaster or matrix for all variables representing where non-analogous conditions were found towards high values of each variable.
towards_low_combined - a SpatRaster or vector with values representing the identity of the variables found to have non-analogous conditions towards low values. If vector, interpretation requires the use of the data.frame interpretation_combined.
towards_high_combined - a SpatRaster or vector with values representing the identity of the variables found to have non-analogous conditions towards high values. If vector, interpretation requires the use of the data.frame interpretation_combined.
# data reference_layers <- terra::rast(system.file("extdata", "reference_layers.tif", package = "mop")) layers_of_interest <- terra::rast(system.file("extdata", "layers_of_interest.tif", package = "mop")) # analysis mop_res <- mop(m = reference_layers, g = layers_of_interest) summary(mop_res)
# data reference_layers <- terra::rast(system.file("extdata", "reference_layers.tif", package = "mop")) layers_of_interest <- terra::rast(system.file("extdata", "layers_of_interest.tif", package = "mop")) # analysis mop_res <- mop(m = reference_layers, g = layers_of_interest) summary(mop_res)
Calculates distances from each of the points of interest in g_matrix
to a defined percentage of the reference conditions in m_matrix
.
mop_distance(m_matrix, g_matrix, distance = "euclidean", percentage = 1, comp_each = 2000, tol = NULL, parallel = FALSE, n_cores = NULL, progress_bar = TRUE)
mop_distance(m_matrix, g_matrix, distance = "euclidean", percentage = 1, comp_each = 2000, tol = NULL, parallel = FALSE, n_cores = NULL, progress_bar = TRUE)
m_matrix |
matrix of variables representing the set of conditions to be used as reference. Each column represents a variable. |
g_matrix |
matrix of variables representing the set of conditions to be
compared against the reference conditions (where distances are to be
calculated). Each column represents a variable. Variable names must match
those in |
distance |
|
percentage |
|
comp_each |
|
tol |
tolerance to detect linear dependencies when calculating
Mahalanobis distances. The default, NULL, uses |
parallel |
|
n_cores |
|
progress_bar |
|
A numeric vector with values of distances calculated according to parameters used.
# data data("reference_matrix", package = "mop") data("matrix_of_interest", package = "mop") # analysis mop_dist <- mop_distance(m_matrix = reference_matrix, g_matrix = matrix_of_interest)
# data data("reference_matrix", package = "mop") data("matrix_of_interest", package = "mop") # analysis mop_dist <- mop_distance(m_matrix = reference_matrix, g_matrix = matrix_of_interest)
Constructor of S3 objects of class mop_results
new_mop_results(summary = new("list"), mop_distances = NULL, mop_basic = NULL, mop_simple = NULL, mop_detailed = new("list"))
new_mop_results(summary = new("list"), mop_distances = NULL, mop_basic = NULL, mop_simple = NULL, mop_detailed = new("list"))
summary |
a list with a summary of the data and parameters used in analysis. Default = empty list. |
mop_distances |
a |
mop_basic |
a |
mop_simple |
a |
mop_detailed |
a list with a detailed representation of mop results in conditions outside the range of reference. Default = empty list. |
An object of class mop_results
.
Options to identify which values in a set of conditions of interest
(g_matrix
) are outside the range of a set of conditions of
reference (m_matrix
).
out_range(m_matrix, g_matrix, type = "basic")
out_range(m_matrix, g_matrix, type = "basic")
m_matrix |
matrix of variables representing the set of conditions to be used as reference. Each column represents a variable. |
g_matrix |
matrix of variables representing the set of conditions to be
compared against the reference conditions (where conditions outside range
are to be detected). Each column represents a variable. Variable names must
match those in |
type |
|
Results are produced according to type
:
basic - helps to identify conditions outside ranges, in general, one or
variables are only counted as 1
. This is always returned.
simple - identifies the number of variables with conditions outside ranges, for each condition of interest outside ranges, the number of non-analogous variables is returned.
detailed - produces various results (including the two above):
high_all - identifies non-analogous conditions towards high values of variables, for each variable independently.
low_all - identifies non-analogous conditions towards low values of variables, for each variable independently.
high_combined - values are used to identify combinations of variables with non-analogous conditions towards high values of the variables.
low_combined - values are used to identify combinations of variables with non-analogous conditions towards low values of the variables.
interpretation - a data.frame
to help identify which variables are
considered in combined results.
A list containing the ranges in m_matrix
, results from analysis
according to type
, and table to help with interpretations. NA values
represent conditions of interest inside ranges of reference conditions.
See Details
.
# data data("reference_matrix", package = "mop") data("matrix_of_interest", package = "mop") # analysis out <- out_range(m_matrix = reference_matrix, g_matrix = matrix_of_interest)
# data data("reference_matrix", package = "mop") data("matrix_of_interest", package = "mop") # analysis out <- out_range(m_matrix = reference_matrix, g_matrix = matrix_of_interest)
Print a short version of elements in mop objects
## S3 method for class 'mop_results' print(x, ...)
## S3 method for class 'mop_results' print(x, ...)
x |
object of class mop_results. |
... |
further arguments to be passed to or from other methods. Ignored in this function. |
A short description of objects in the console.
A SpatRaster
object representing variables in a set of reference. Variables
represent current bioclimatic variables downloaded from the WorldClim
database (https://worldclim.org/).
A SpatRaster
object.
No return value. Used with function rast
to
bring raster variables to analysis.
reference_layers <- terra::rast(system.file("extdata", "reference_layers.tif", package = "mop")) terra::plot(reference_layers)
reference_layers <- terra::rast(system.file("extdata", "reference_layers.tif", package = "mop")) terra::plot(reference_layers)
A numeric table representing variables in a set of reference.
reference_matrix
reference_matrix
A matrix with 723 rows and 6 columns.
data("reference_matrix", package = "mop") head(reference_matrix)
data("reference_matrix", package = "mop") head(reference_matrix)
Summary of attributes and results
## S3 method for class 'mop_results' summary(object, ...)
## S3 method for class 'mop_results' summary(object, ...)
object |
object of class mop_results. |
... |
additional arguments affecting the summary produced. Ignored in this function. |
A printed summary.