tjursR2Weighted: Weighted Tjur's R2

View source: R/tjursR2Weighted.r

tjursR2WeightedR Documentation

Weighted Tjur's R2

Description

This function calculates Tjur's R2 metric of model discrimination accuracy. Unweighted R2 is simply the difference between the mean predicted value at presence sites and the mean predicted value at absence/background sites. The weighted version allows for differing weights between presences and between absences/contrast values (i.e., the difference between the weighted mean of predictions at presences and weighted mean predictions at absences/contrast locations).

Usage

tjursR2Weighted(
  pres,
  contrast,
  presWeight = rep(1, length(pres)),
  contrastWeight = rep(1, length(contrast)),
  na.rm = FALSE,
  bg = NULL,
  bgWeight = NULL,
  ...
)

Arguments

pres

Predictions at presence sites.

contrast

Predictions at absence/background sites.

presWeight

Weights of presence cases. The default is to assign each presence case a weight of 1.

contrastWeight

Weights of absence/background cases. The default is to assign each case a weight of 1.

na.rm

Logical. If TRUE then remove any presences and associated weights and background predictions and associated weights with NAs.

bg

Same as contrast. Included for backwards compatibility. Ignored if contrast is not NULL.

bgWeight

Same as contrastWeight. Included for backwards compatibility. Ignored if contrastWeight is not NULL.

...

Other arguments (unused).

Value

Numeric value.

References

Tjur, T. 2009. Coefficients of determination in logistic regression models—A new proposal: The coefficient of discrimination. The American Statistician 63:366–372. doi: 10.1198/tast.2009.08210.

See Also

tjursR2Weighted, fpb, contBoyce, evaluate

Examples

pres <- seq(0.5, 1, by=0.1)
contrast <- seq(0, 1, by=0.01)

# unweighted
tjursR2Weighted(pres, contrast)

# weighted (weight presences with low predictions more)
presWeight <- c(1, 1, 1, 0.5, 0.5, 0.5)
tjursR2Weighted(pres, contrast, presWeight=presWeight)

# weighted (weight presences with high predictions more)
presWeight <- c(0.5, 0.5, 0.5, 1, 1, 1)
tjursR2Weighted(pres, contrast, presWeight=presWeight)

# weight presences and absences
contrastWeight <- sqrt(contrast)
tjursR2Weighted(pres, contrast, presWeight=presWeight, contrastWeight=contrastWeight)

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