oliver
oliver

Reputation: 147

How to fit Gumbel distribution?

I want to find a package in R to fit the extreme value distribution https://en.wikipedia.org/wiki/Generalized_extreme_value_distribution with three unknown parameters mu, sigma, xi.

I found two packages that can do the inference for these three parameters based on maximum likelihood estimation.

library(ismev)
gev.fit(data)

and

library(extRemes)
fevd(data)

the output is estimates of mu, sigma, and xi.

But if I just want to fit distribution with two parameters mu and sigma (like Gumbel distribution, the parameter xi=0). How to apply the above two packages? Or are there any other packages that can do inference for the Gumbel distribution?

Upvotes: 0

Views: 772

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226522

The evd package has 2-parameter [dpqr]gumbel functions that you can combine with any general-purpose optimization method (optim() is one such possibility, as suggested in the comments, but there are some shortcuts as suggested below).

Load packages, simulate example:

library(evd)
library(fitdistrplus)
set.seed(101)
x <- rgumbel(1000, loc = 2, scale = 2.5)

Make a more robust wrapper for dgumbel() that won't throw an error if we hand it a non-positive scale value (there are other ways to deal with this problem, but this one works):

dg <- function(x, loc, scale, log) {
   r <- try(dgumbel(x, loc, scale, log), silent = TRUE)
   if (inherits(r, "try-error")) return(NA)
   return(r)
}
fitdistr(x, dg, start = list(loc = 1, scale = 1))

Results seem reasonable:

      loc         scale   
  2.09220866   2.48122956 
 (0.08261121) (0.06102183)

If you want more flexibility I would recommend the bbmle package (for possibly obvious reasons :-) )

Upvotes: 2

Related Questions