chauvenet: Trims extreme values from a vector that exceed Chauvenet's...

Description Usage Arguments Details Value Examples

View source: R/chauvenet.R

Description

To prevent overfitting of the distributional tails when constructing a distmap object, it is useful to trim very extreme values from the input datasets. This function trims values whose probability is less than 1/N (greater than 1-1/N), where N is the number of data points + 1/2, under the assumption that the data is gaussian.

Usage

1
chauvenet(x, upper = TRUE, lower = TRUE)

Arguments

x

A vector of values to trim.

upper

Logical; trim values in the upper tail. Defaults to TRUE.

lower

Logical; trim values in the lower tail. Defaults to TRUE.

Details

The probability bounds are calculated using qnorm. Instead of using the sample mean and standard deviation, this function uses the median and the MAD (median absolute deviation), which are more robust against the effects of very extreme values.

Value

A trimmed vector of values.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
x <- c(9, 10, 10, 10, 11, 50)
chauvenet(x)
chauvenet(c(x, -20), upper=FALSE)

set.seed(222)
y <- c(rnorm(100))
range(y)
range(chauvenet(y))
z <- c(y, 100, 1000)
qnorm(1-1/12, mean(z), sd(z))
range(chauvenet(z))

sethmcg/climod documentation built on Nov. 19, 2021, 11:12 p.m.