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 usingread.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 classicaldo.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 plottingfevd
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 ofextRemes
(just have a look at the behemothplot.fevd.mle
).
Best regards,
Matthias
Post A Reply