0

I would like help with the following. I want to fit my data to a generalized distribution of extreme values ​​(GEV) and although I have seen that there are packages for this, I would like to use the fitdistplus package because it has several functions that interest me such as goodness-of-fit calculations and graphs, however , this distribution is not defined in the package, so it has to be defined.

I had a code in Matlab where I estimated the shape (k), location (dzeta) and scale (beta) parameters using the "mle" method and then defined the probability density functions and the cumulative function using:

gev_pdf =(1./beta).((1+(k.(x-dzeta)./beta)).^(-1-(1./k))).exp(-(1+(k.(x-dzeta)./beta)).^(-1./k)) gev_cdf = exp(-((1+(k.*(x-dzeta)./beta)).^(-(1./k))))

I would like you to help me define these functions in R to use them in the fitdistplus package, I have tried this way based on a Gumbel distribution example from the following page https://rpubs.com/Skytled/stationary-analysis but it did not work for me it has come out.

x  <- c(-70.529830, -35.381401, -58.174953, -67.931427, -56.476050, -13.685694,
        -42.468175, -78.643823, -53.852342, -32.194419, -59.888380, -32.307874,
        -22.354453, -68.182858, -54.118365, -48.965637, -15.189463, -48.933622,
        -31.328549, -50.419592, -39.832141, -105.309970,-50.272139, -39.316075,
        -36.732946, -52.624589, -42.064775, -30.715608, -40.794221, -29.620083,
        -42.498430, -49.427569, -65.327426, -18.453594, -89.750756, -4.735307,
        -60.148405, -10.495953, -45.931377, -57.258707, -60.280258, -54.621055,
        -50.483208, -64.820150, -52.820797, -24.462333, -62.711868, -29.477148,
        -59.179008, -12.433426, -29.191209, -55.962932, -38.514080, -42.741562,
        -51.034787, -57.523195, -42.183774, -39.323798, -30.163555, -56.965198,
        -44.449423, -25.496660, -32.102112, -14.373200, -54.699579, -18.295453,
        -45.931853, -31.530379)

dgev <- function(x,a,b,c) (1/b)((1+(k(x-z)/b))^(-1-(1/k)))exp(-(1+(k(x-z)/b))^(-1/k)) pgev <- function(q,a,b,c) exp(-((1+(k*(x-z)/b))^(-(1/k)))) GEV <- fitdist(x,"gev",start = list(a=1,b=1,c=1))

ERROR: <simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs = data, gr = gradient, ddistnam = ddistname, hessian = TRUE, method = meth, lower = lower, upper = upper, ...): function cannot be evaluated at initial parameters> Error in fitdist(minabs$value, "gev", start = list(a = 1, b = 1, c = 1)) : the function mle failed to estimate the parameters, with the error code 100 In addition: Warning message: In fitdist(x, "gev", start = list(a = 1, b = 1, c = 1)) : The pgev function should return a zero-length vector when input has length zero

jpsmith
  • 11,023
  • 5
  • 15
  • 36
  • 1
    https://stackoverflow.com/questions/29897756/how-to-define-your-own-distribution-for-fitdistr-function-in-r-with-the-help-of/29898334#29898334 – Ben Bolker Jul 10 '23 at 12:33

0 Answers0