compareResponse: Compare two response curves along one or more predictors

View source: R/compareResponse.r

compareResponseR Documentation

Compare two response curves along one or more predictors

Description

This function calculates a suite of metrics reflecting of niche overlap for two response curves. Response curves are predicted responses of a uni- or multivariate model along a single variable. Depending on the user-specified settings the function calculates these values either at each pair of values of pred1 and pred2 or along a smoothed version of pred1 and pred2.

Usage

compareResponse(
  pred1,
  pred2,
  data,
  predictor = names(data),
  adjust = FALSE,
  gap = Inf,
  smooth = FALSE,
  smoothN = 1000,
  smoothRange = c(0, 1),
  graph = FALSE,
  ...
)

Arguments

pred1

Numeric list. Predictions from first model along data (one value per row in data).

pred2

Numeric list. Predictions from second model along data (one value per row in data).

data

Data frame or matrix corresponding to pred1 and pred2.

predictor

Character list. Name(s) of predictor(s) for which to calculate comparisons. These must appear as column names in data.

adjust

Logical. If TRUE then subtract the mean of pred1 from pred1 and the mean of pred2 from pred2 before analysis. Useful for comparing the shapes of curves while controlling for different elevations (intercepts).

gap

Numeric >0. Proportion of range of predictor variable across which to assume a gap exists. Calculation of areaAbsDiff will ignore gaps wide than this. To ensure the entire range of the data is included set this equal to Inf (default).

smooth

Logical. If TRUE then the responses are first smoothed using loess() then compared at smoothN values along each predictor. If FALSE then comparisons are conducted at the raw values pred1 and pred2.

smoothN

NULL or positive integer. Number of values along "pred" at which to calculate comparisons. Only used if smooth is TRUE. If NULL, then comparisons are calculated at each value in data. If a number, then comparisons are calculated at smoothN values of data[ , pred] that cover the range of data[ , pred].

smoothRange

2-element numeric list or NULL. If smooth is TRUE, then force loess'ed predictions < smoothRange[1] to equal smoothRange[1] and predictions > smoothRange[2] to equal smoothRange[2]. Ignored if NULL.

graph

Logical. If TRUE then plot predictions.

...

Arguments to pass to functions like sum() (for example, na.rm=TRUE) and to overlap() (for example, w for weights). Note that if smooth = TRUE then passing an argument called w will likely cause a warning and make results circumspect unless weights are pre-calculated for each of the smoothN points along a particular predictor.

Value

Either a data frame (if smooth = FALSE or a list object with the smooth model plus a data frame (if smooth = TRUE) . The data frame represents metrics comparing response curves of pred1 and pred2:

  • predictor Predictor for which comparison was made

  • n Number of values of predictor at which comparison was calculated

  • adjust adjust argument.

  • smooth smooth argument.

  • meanDiff Mean difference between predictions of pred1 and pred2 (higher ==> more different).

  • meanAbsDiff Mean absolute value of difference between predictions of pred1 and pred2 (higher ==> more different).

  • areaAbsDiff Sum of the area between curves predicted by pred1 and pred2, standardized by total potential area between the two curves (i.e., the area available between the minimum and maximum prediction along the minimum and maximum values of the predictor) (higher ==> more different).

  • d Schoener's D

  • i Hellinger's I (adjusted to have a range [0, 1])

  • esp Godsoe's ESP

  • cor Pearson correlation between predictions of pred1 and pred2.

  • rankCor Spearman rank correlation between predictions of pred1 and pred2.

References

Warren, D.L., Glor, R.E., and Turelli, M. 2008. Environmental niche equivalency versus conservatism: Quantitative approaches to niche evolution. Evolution 62:2868-2883.

Warren, D.L., Glor, R.E., and Turelli, M. 2008. Erratum. Evolution 62:2868-2883.

Godsoe, W. 2014. Inferring the similarity of species distributions using Species’ Distribution Models. Ecography 37:130-136.

See Also

compareNiches

Examples

set.seed(123)
data <- data.frame(
	x1=seq(-1, 1, length.out=100),
	x2=seq(-1, 1, length.out=100) + rnorm(100, 0, 0.3)
)

pred1 <- 1 / (1 + exp(-(0.3 + 2 * (data$x1 - 0.2) -0.3 * data$x2)))
pred2 <- 1 / (1 + exp(-(-0 + 0.1 * data$x1 - 4 * data$x1^2 + 0.4 * data$x2)))

compareResponse(pred1, pred2, data, graph=TRUE)
compareResponse(pred1, pred2, data, smooth=TRUE, graph=TRUE)
compareResponse(pred1, pred2, data, adjust=TRUE, graph=TRUE)

adamlilith/enmSdm documentation built on Jan. 6, 2023, 11 a.m.