Lyndz
Lyndz

Reputation: 423

Error with "extRemes" package in R: Cannot plot return periods

I am using the extRemes package in R in plotting the return periods. However, my data set has missing values so I encounter many errors:

Here's the data: https://www.dropbox.com/s/un9vghuwmptnty1/Lumbia_1979-2017.csv?dl=0

Apologies, the return period plot requires a large number of observation points, so this is the smallest data set that I can post.

Here's the script so far:

library(extRemes)
dat<-read.csv("Lumbia_1979-2017.csv",header=T)
dat[dat==-999]<-NA

#Extract annual max precip
annmax <- aggregate(dat$Rain, by = list(dat$Year),max, na.rm=TRUE,na.action=NULL)
gevfit1 <- fevd(annmax[ ,2])
gevfit1

Error

I encounter the error and warning below:

Error Message

What I want

(a) Can anyone suggest a workaround solution for plotting the return periods of data sets with missing values?

(b) If for example, I want to get the return period of 100mm/day rainfall, how do I estimate this from the plot of the return periods.

I'll appreciate any help on this matter.

Upvotes: 2

Views: 285

Answers (1)

Tomas
Tomas

Reputation: 59565

The error you are getting is from the aggregate call:

annmax <- aggregate(dat$Rain, by = list(dat$Year),max, na.rm=TRUE,na.action=NULL)
# Warning messages:
# 1: In FUN(X[[i]], ...) : no non-missing arguments to max; returning -Inf
# 2: In FUN(X[[i]], ...) : no non-missing arguments to max; returning -Inf
# [...]

In this call, you are computing the maximum of Rain for each Year. This error happens when there are data missing for some of those years, so that the maximum can't be calculated. Look at the results:

annmax
#    Group.1     x
# 1     1979   5.4
# 2     1980  27.1
# 3     1981  62.5
# [...]
# 33    2011  58.2
# 34    2012   5.7
# 35    2013  74.9
# 36    2014  -Inf
# 37    2015  -Inf
# 38    2016  -Inf
# 39    2017  -Inf

In these years, when aggregate returned -Inf, you have no data for Rain:

dat[dat$Year %in% 2014:2017,]
#      Year Month Day Rain
# 1086 2014     1   1   NA
# 1087 2014     1   2   NA
# 1088 2014     1   3   NA
# 1089 2014     1   4   NA
# 1090 2014     1   5   NA
# 1091 2014     1   6   NA
# 1092 2014     1   7   NA
# 1093 2014     1   8   NA
# 1094 2014     1   9   NA
# 1095 2014     1  10   NA
# 1096 2014     1  11   NA
# [...]

So, it's up to you to decide what to do with those missing years. It depends on the analysis. Does the analysis need some data in the missing years?

1) In the case that the analysis (fevd) needs some data in the missing years, you need some method to interpolate them from the other years.

2) If the analysis doesn't need the missing years, just delete them. This is the simplest solution:

annmax2 <- annmax[is.finite(annmax[,2]),]
gevfit1 <- fevd(annmax2[ ,2])

And now it works :-)

Upvotes: 1

Related Questions