# Threshold exceedance for Normal variables
quants <- seq(1, 5, by = 0.02)
penult <- penultimate(
family = "norm",
method = 'pot',
thresh = quants,
ddensF = function(x){-x*dnorm(x)}, # optional argument
)
plot(x = quants,
y = penult$shape,
type = 'l',
xlab = 'quantile',
ylab = 'Penultimate shape',
ylim = c(-0.5, 0))
# Block maxima for Gamma variables
# User must provide arguments for shape (or rate), for which there is no default
m <- seq(30, 3650, by = 30)
penult <- penultimate(family = 'gamma', method = 'bm', m = m, shape = 0.1)
plot(x = m,
y = penult$shape,
type = 'l',
xlab = 'quantile',
ylab = 'penultimate shape')
# Comparing density of GEV approximation with true density of maxima
m <- 100 # block of size 100
p <- penultimate(
family = 'norm',
ddensF = function(x){-x*dnorm(x)},
method = 'bm',
m = m)
x <- seq(1, 5, by = 0.01)
plot(
x = x,
y = m * dnorm(x) * exp((m-1) * pnorm(x, log.p = TRUE)),
type = 'l',
ylab = 'density',
main = 'Distribution of the maxima of\n 100 standard normal variates')
lines(x, mev::dgev(x, loc = p$loc, scale = p$scale, shape = 0), col = 2)
lines(x, mev::dgev(x, loc = p$loc, scale = p$scale, shape = p$shape), col = 4)
legend(
x = 'topright',
lty = c(1, 1, 1),
col = c(1, 2, 4),
legend = c('exact', 'ultimate', 'penultimate'),
bty = 'n')
Run the code above in your browser using DataLab