Чтобы получить данные, которые отображаются для уровня возврата, нам нужно углубиться в функцию retlev
. По сути, я сделал все возможное, чтобы вырезать все графики и построить data.frame из необходимых точек.
getRetLevData <- function (fitted, npy) {
data <- fitted$exceed
loc <- fitted$threshold[1]
scale <- fitted$param["scale"]
shape <- fitted$param["shape"]
n <- fitted$nat
pot.fun <- function(T) {
p <- rp2prob(T, npy)[, "prob"]
return(qgpd(p, loc, scale, shape))
}
eps <- 10^(-3)
if (!is.null(fitted$noy)){
npy <- n/fitted$noy
} else if (missing(npy)) {
warning("Argument ``npy'' is missing. Setting it to 1.")
npy <- 1
}
xlimsup <- prob2rp((n - 0.35)/n, npy)[, "retper"]
fittedLine <- pot.fun(seq(1/npy + eps, xlimsup, length.out = n))
p_emp <- (1:n - 0.35)/n
xPoints <- 1/(npy * (1 - p_emp))
empPoints <- sort(data)
samp <- rgpd(1000 * n, loc, scale, shape)
samp <- matrix(samp, n, 1000)
samp <- apply(samp, 2, sort)
samp <- apply(samp, 1, sort)
ci_inf <- samp[25, ]
ci_sup <- samp[975, ]
rst <- data.frame(xPoints, fittedLine, empPoints,
ci_inf, ci_sup)
}
x <- getRetLevData(mle, npy)
head(x)
# fittedX fittedLine xPoints empPoints ci_inf ci_sup
#1 1.001000 6.003716 1.011535 6.09 6.001557 6.239971
#2 3.891288 11.678503 1.029810 6.09 6.014536 6.363070
#3 6.781577 14.402517 1.048758 6.09 6.042065 6.470195
#4 9.671865 16.282306 1.068416 6.19 6.074348 6.583290
#5 12.562153 17.740710 1.088825 6.44 6.114193 6.684118
#6 15.452441 18.942354 1.110029 6.45 6.146098 6.812058
write.csv(x, "my_pot_results.csv")
Наложение извлеченных данных против retlev
графика. CI немного отличаются из-за выборки.
![enter image description here](https://i.stack.imgur.com/q7rPo.png)