convert_cd: Fit a model to convert cost-distances into Euclidean...

View source: R/convert_cd.R

convert_cdR Documentation

Fit a model to convert cost-distances into Euclidean distances

Description

The function fits a model to convert cost-distances into Euclidean distances as implemented in Graphab software.

Usage

convert_cd(
  mat_euc,
  mat_ld,
  to_convert,
  method = "log-log",
  fig = TRUE,
  line_col = "black",
  pts_col = "#999999"
)

Arguments

mat_euc

A symmetric matrix or dist object with pairwise geographical Euclidean distances between populations or sample sites. It will be the explanatory variable, and only values from the off diagonal lower triangle will be used.

mat_ld

A symmetric matrix or dist object with pairwise landscape distances between populations or sample sites. These distances can be cost-distances or resistance distances, among others. It will be the explained variable, and only values from the off diagonal lower triangle will be used.

to_convert

A numeric value or numeric vector with Euclidean distances to convert into cost-distances.

method

A character string indicating the method used to fit the model.

  • If 'method = "log-log"' (default), then the model takes the following form : log(ld) ~ A + B * log(euc)

  • If 'method = "lm"', then the model takes the following form : ld ~ A + B * euc

fig

Logical (default = TRUE) indicating whether a figure is plotted

line_col

(if 'fig = TRUE') Character string indicating the color used to plot the line (default: "blue"). It must be a hexadecimal color code or a color used by default in R.

pts_col

(if 'fig = TRUE') Character string indicating the color used to plot the points (default: "#999999"). It must be a hexadecimal color code or a color used by default in R.

Details

IDs in 'mat_euc' and 'mat_ld' must be the same and refer to the same sampling site or populations, and both matrices must be ordered in the same way. Matrix of Euclidean distance 'mat_euc' can be computed using the function mat_geo_dist. Matrix of landscape distance 'mat_ld' can be computed using the function mat_cost_dist. Before the log calculation, 0 distance values are converted into 1, so that they are 0 after this calculation.

Value

A list of output (converted values, estimated parameters, R2) and optionally a ggplot2 object to plot

Author(s)

P. Savary

References

\insertRef

foltete2012softwaregraph4lg

Examples

data("data_tuto")
mat_ld <- data_tuto[[2]][1:10, 1:10] * 1000
mat_euc <- data_tuto[[1]][1:10, 1:10] * 50000
to_convert <- c(30000, 40000)
res <- convert_cd(mat_euc = mat_euc,
                  mat_ld = mat_ld,
                  to_convert = to_convert, fig = FALSE)

graph4lg documentation built on Feb. 16, 2023, 5:43 p.m.