Search code examples
rdistributiondata-fittinggoodness-of-fitkolmogorov-smirnov

How to do Kolmogorov-Smirnov statistic for GEV distribution in R?


I am now using the extremes package to fit a generalized extreme value (GEV) distribution, and I want to use the Kolmogorov-Smirnov test to estimate the goodness of fit, but get the following error:

library(extRemes)
library(eva)
data("PORTw", package = "extRemes")
fit1 <- fevd(TMX1, PORTw, units = "deg C")
ks.test(PORTw$TMX1,"pgev",fit1$results$par[[1]],fit1$results$par[[2]],shape=fit1$results$par[[3]])

`Warning message:
In ks.test(PORTw$TMX1, "pgev", fit1$results$par[[1]], fit1$results$par[[2]],  :
  ties should not be present for the Kolmogorov-Smirnov test`

So, my question is, how to perform a Kolmogorov-Smirnov test for the GEV fit with ties? Or, is there any other goodness of fit test for fitting a distribution available in R? Thanks a lot.


Solution

  • I recommend the "EnvStats" package. You will have more versatility for goodness of fit test:

    library(EnvStats)
    # For a data set called X
    X <- rgevd(500)
    # Generalized Extreme Value (EnvStats)
    egevd(X, method = "mle")# Maximum likelihood
    # Goodness of fit test
    gofTest(X, distribution = "gev",test = "ks")#Kolmogorov-Smirnov
    gofTest(X, distribution = "gev",test = "chisq")#Chi-Squared