Extreme Value Analysis revised

Dear all,

I have slightly revised parts of the code used in my posts on Extreme Value Analysis. While they were correct with respect to the results, some parts of the code written by former me more than two years ago were plainly ugly. I have also removed some redundancies and packages unnecessary for the task at hand, and tried to improve overall workflow.

Changes include:

  • The package RCurl can be avoided for fetching data from the web by simply using read.csv(url("http://ehyd.gv.at/...")) instead.
  • The whole procedure of data import has been put into a function read_ehyd(), which is described in a separate post: Reading data from eHYD using R.
  • I have integrated the use of xts (eXtensible Time Series) objects, since they provide a lot of convenient functionality. For instance, I solved deriving the annual maxima series in the original version by using a classical do.call()¬†statement on the whole data frame:
    # derive AMS for maximum precipitation
    ams_df <- do.call("rbind", by(eHYD_df, format(df$date, "%Y"),
                      function(x) x[which.max(x$precipitation), ]))
    ams_val <- ams_df$precipitation
    

    This can be solved in a nicer way using dplyr:

    ams_tbl <- eHYD_df %>% 
      mutate(year = format(date, "%Y")) %>%
      group_by(year) %>%
      summarise(ams = max(precipitation)) %>%
      select(ams)
    

    or even shorter using xts:

    ams <- apply.yearly(precipitation_xts, max)
  • A final remark (since I have received several questions regarding this topic): I use a custom function based on plot.fevd()¬†for plotting fevd objects. To be honest, this is a somewhat hacky modification of the original code in order to make the plots more appealing. I intend to publish my modifications in the future once I have reworked the code. Right now, this is probably barely understandable to due to the inefficient programming style of extRemes (just have a look at the behemoth plot.fevd.mle).

Best regards,
Matthias

Matthias

Matthias studied Environmental and Bio-Resources Management with a specialization in Environmental Information Management at the University of Natural Resources and Life Sciences (Vienna). He is currently a PhD student working at the Austrian Institute of Technology. Having written his master's thesis about extreme weather risk identification for the Austrian road network, he currently focuses on modeling of adverse weather events as a basis for risk assessment of road infrastructure networks.

Post A Reply

*