[英]Error with “extRemes” package in R: Cannot plot return periods
我在绘制返回期时正在使用R 中的 extRemes package。 但是,我的数据集缺少值,所以我遇到了很多错误:
这是数据: https://www.dropbox.com/s/un9vghuwmptnty1/Lumbia_1979-2017.csv?dl=0
抱歉,返回期 plot 需要大量的观察点,所以这是我能发布的最小的数据集。
这是到目前为止的脚本:
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
错误
我遇到以下错误和警告:
我想要的是
(a) 任何人都可以建议一种解决方案来绘制具有缺失值的数据集的返回期吗?
(b) 例如,如果我想得到 100 毫米/天降雨量的重现期,我如何从重现期的 plot 估计这个。
对于此事,我将不胜感激。
您得到的错误来自aggregate
调用:
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
# [...]
在此调用中,您正在计算Year
Rain
的最大值。 当其中某些年份缺少数据时会发生此错误,因此无法计算最大值。 看看结果:
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
这些年来,当aggregate
返回-Inf
时,您没有 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
# [...]
因此,由您决定如何处理这些缺失的年份。 这取决于分析。 分析是否需要一些缺失年份的数据?
1)如果分析( fevd
)需要缺失年份的一些数据,您需要一些方法来插入其他年份的数据。
2)如果分析不需要丢失的年份,只需删除它们。 这是最简单的解决方案:
annmax2 <- annmax[is.finite(annmax[,2]),]
gevfit1 <- fevd(annmax2[ ,2])
现在它可以工作了:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.