area.diff: Area difference

View source: R/area.diff.R

area.diffR Documentation

Area difference

Description

Measure the area difference between two ranked distribution

Usage

area.diff(x, y, rarefy, cent.tend = mean, sort = TRUE)

Arguments

x, y

the two distributions to compare.

rarefy

Optional, if the length of x is is not equal to the one of y, how many rarefaction samples to use. If left empty a default number of replicates between 100 and 1000 is used (see details).

cent.tend

Optional, if the length of x is is not equal to the one of y, which central tendency to use (defaut = mean).

sort

logical, whether to always sort the x,y values (TRUE; default) or not (FALSE).

Details

The number of replicates is chosen based on the variance of the distribution to rarefy using the Silverman's rule of thumb (Silverman 1986, pp.48, eqn 3.31) for choosing the bandwidth of a Gaussian kernel density estimator multiplied by 1000 with a result comprised between 100 and 1000. For example, for rarefying x, rarefy = round(stats::bw.nrd0(x) * 1000). With 100 <= rarefy <= 1000.

Author(s)

Thomas Guillerme

References

Silverman, B. W. (1986) Density Estimation. London: Chapman and Hall.

See Also

variation.range

Examples

set.seed(1)
## Two distributions
x <- rnorm(10)
y <- runif(10)

## The area difference
area.diff(x, y)

## Visualising the difference
plot(sort(x), type = "l", col = "orange", lwd = 2)
lines(sort(y), col = "blue", lwd = 2)
polygon(c(1:10, 10:1), c(sort(x), sort(y, TRUE)), col = "grey", border = NA)
legend("topleft", legend  = c("x", "y", "area difference"), col = c("orange", "blue", "grey"),
       lty = c(1,1,0), pch = c(NA,NA,15))


## Two unequal distributions
z <- rnorm(100)

## The area difference estimation
area.diff(x, z)

## The area difference estimation with a fixed rarefaction value using the median
area.diff(x, z, rarefy = 500, cent.tend = median)



TGuillerme/landvR documentation built on July 4, 2025, 10:16 p.m.