# We need the eva package
got_eva <- requireNamespace("eva", quietly = TRUE)
if (got_eva) {
library(eva)
# An example from the eva::gpdFit documentation
set.seed(7)
x <- eva::rgpd(2000, loc = 0, scale = 2, shape = 0.2)
mle_fit <- eva::gpdFit(x, threshold = 4, method = "mle")
adj_mle_fit <- alogLik(mle_fit)
summary(adj_mle_fit)
# Another example from the eva::gpdFit documentation
# A linear trend in the scale parameter
set.seed(7)
n <- 300
x2 <- eva::rgpd(n, loc = 0, scale = 1 + 1:n / 200, shape = 0)
covs <- as.data.frame(seq(1, n, 1))
names(covs) <- c("Trend1")
result1 <- eva::gpdFit(x2, threshold = 0, scalevars = covs,
scaleform = ~ Trend1)
adj_result1 <- alogLik(result1)
summary(adj_result1)
# An example from the eva::gevrFit documentation
set.seed(7)
x1 <- eva::rgevr(500, 1, loc = 0.5, scale = 1, shape = 0.3)
result1 <- eva::gevrFit(x1, method = "mle")
adj_result1 <- alogLik(result1)
summary(adj_result1)
# Another example from the eva::gevrFit documentation
# A linear trend in the location and scale parameter
n <- 100
r <- 10
x2 <- eva::rgevr(n, r, loc = 100 + 1:n / 50, scale = 1 + 1:n / 300,
shape = 0)
covs <- as.data.frame(seq(1, n, 1))
names(covs) <- c("Trend1")
# Create some unrelated covariates
covs$Trend2 <- rnorm(n)
covs$Trend3 <- 30 * runif(n)
result2 <- eva::gevrFit(data = x2, method = "mle", locvars = covs,
locform = ~ Trend1 + Trend2*Trend3,
scalevars = covs, scaleform = ~ Trend1)
adj_result2 <- alogLik(result2)
summary(adj_result2)
}
Run the code above in your browser using DataLab