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.
- The package
RCurlcan be avoided for fetching data from the web by simply using
- 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
ams_tbl <- eHYD_df %>% mutate(year = format(date, "%Y")) %>% group_by(year) %>% summarise(ams = max(precipitation)) %>% select(ams)
or even shorter using
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
fevdobjects. 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