https://github.com/cran/laeken
Tip revision: 0212be6ca8944f359e081e9e78e5aabbf0958791 authored by Andreas Alfons on 04 June 2010, 00:00:00 UTC
version 0.1
version 0.1
Tip revision: 0212be6
meanExcessPlot.R
# ----------------------------------------
# Authors: Josef Holzer and Andreas Alfons
# Vienna University of Technology
# ----------------------------------------
meanExcessPlot <- function(x, probs, ...) {
## initializations
if(!is.numeric(x) || length(x) == 0) stop("'x' must be a numeric vector")
if(any(i <- is.na(x))) x <- x[!i]
n <- length(x)
if(n == 0) stop("no observed values")
if(missing(probs)) {
eps <- 1/n
probs <- seq.int(from=eps, to=1-eps*sqrt(n), by=eps)
}
mu <- quantile(x, probs, type=1)
meanExcess <- function(mu) {
if(max(x) <= mu) stop("threshold too high")
mean(x[x > mu] - mu)
}
me <- sapply(mu, meanExcess)
## create plot
localPlot <- function(x, y, main = "Mean excess plot",
xlab = "Threshold", ylab = "Mean excess", ...) {
plot(x, y, main=main, xlab=xlab, ylab=ylab, ...)
}
localPlot(mu, me, ...)
}