##====================================================================
## block maxima: simulated data and comparison with the 'fgev'
## function from the 'evd' package
##====================================================================
set.seed(1234)
u <- 10
nBlocks <- 30
nSim <- 100 ## number of samples
Par <- array(NA, dim = c(nSim, 3, 2),
dimnames = list(NULL, c("loc", "scale", "shape"), c("MAX", "evd")))
LL <- array(NA, dim = c(nSim, 2),
dimnames = list(NULL, c("MAX", "evd")))
for (i in 1:nSim) {
rd <- rRendata(threshold = u,
effDuration = 1,
lambda = 12,
MAX.effDuration = rep(1, nBlocks),
MAX.r = rep(1, nBlocks),
distname.y = "exp", par.y = c(rate = 1 / 100))
MAX <- Renext:::makeMAXdata(rd)
fit.MAX <- fGEV.MAX(MAX = MAX)
fit.evd <- fgev(x = unlist(MAX$data))
Par[i, , "MAX"] <- fit.MAX$estimate
Par[i, , "evd"] <- fit.evd$estimate
LL[i, "MAX"] <- fit.MAX$loglik
LL[i, "evd"] <- logLik(fit.evd)
}
##====================================================================
## r largest: use 'ismev::rlarg.fit' on the venice data set.
## NB 'venice' is taken from the 'evd' package here.
##====================================================================
if (FALSE) {
require(ismev);
fit1 <- ismev::rlarg.fit(venice)
## transform data: each row is a block
MAX.data <- as.list(as.data.frame(t(venice)))
## remove the NA imposed by the rectangular matrix format
MAX.data <- lapply(MAX.data, function(x) x[!is.na(x)])
MAX.effDuration <- rep(1, length(MAX.data))
fit2 <- fGEV.MAX(MAX.data = MAX.data,
MAX.effDuration = MAX.effDuration)
## estimates
est <- cbind(ismev = fit1$mle, RenextLab = fit2$estimate)
print(est)
# covariance
covs <- array(dim = c(2, 3, 3),
dimnames = list(c("ismev", "RenextLab"),
colnames(fit2$cov), colnames(fit2$cov)))
covs["ismev", , ] <- fit1$cov
covs["RenextLab", , ] <- fit2$cov
print(covs)
}
Run the code above in your browser using DataLab