# GEV model -----
got_evd <- requireNamespace("evd", quietly = TRUE)
if (got_evd) {
library(evd)
# An example from the evd::fgev documentation
set.seed(4082019)
uvdata <- evd::rgev(100, loc = 0.13, scale = 1.1, shape = 0.2)
M1 <- fgev(uvdata)
adj_fgev <- alogLik(M1)
# Large inc set here for speed, sacrificing accuracy
rl <- return_level(adj_fgev, inc = 0.5)
summary(rl)
rl
plot(rl)
}
got_ismev <- requireNamespace("ismev", quietly = TRUE)
if (got_ismev) {
library(ismev)
# An example from the ismev::gev.fit documentation
gev_fit <- gev.fit(revdbayes::portpirie, show = FALSE)
adj_gev_fit <- alogLik(gev_fit)
# Large inc set here for speed, sacrificing accuracy
rl <- return_level(adj_gev_fit, inc = 0.05)
summary(rl)
rl
plot(rl)
}
# Binomial-GP model -----
if (got_ismev) {
library(ismev)
data(rain)
# An example from the ismev::gpd.fit documentation
rain_fit <- gpd.fit(rain, 10, show = FALSE)
adj_rain_fit <- alogLik(rain_fit, binom = TRUE)
# Large inc set here for speed, sacrificing accuracy
rl <- return_level(adj_rain_fit, inc = 2.5)
summary(rl)
rl
plot(rl)
}
if (got_ismev) {
# Use Newlyn seas surges data from the exdex package
surges <- exdex::newlyn
u <- quantile(surges, probs = 0.9)
newlyn_fit <- gpd.fit(surges, u, show = FALSE)
# Create 5 clusters each corresponding approximately to 1 year of data
cluster <- rep(1:5, each = 579)[-1]
adj_newlyn_fit <- alogLik(newlyn_fit, cluster = cluster, binom = TRUE,
cadjust = FALSE)
rl <- return_level(adj_newlyn_fit, inc = 0.02)
rl
# Add inference about the extremal index theta, using K = 1
adj_newlyn_theta <- alogLik(newlyn_fit, cluster = cluster, binom = TRUE,
k = 1, cadjust = FALSE)
rl <- return_level(adj_newlyn_theta, inc = 0.02)
rl
}
Run the code above in your browser using DataLab