Title: | (Precipitation) Frequency Analysis and Variability with L-Moments from 'lmom' |
---|---|
Description: | It is an extension of 'lmom' R package: 'pel...()','cdf...()',qua...()' function families are lumped and called from one function per each family respectively in order to create robust automatic tools to fit data with different probability distributions and then to estimate probability values and return periods. The implemented functions are able to manage time series with constant and/or missing values without stopping the execution with error messages. The package also contains tools to calculate several indices based on variability (e.g. 'SPI' , Standardized Precipitation Index, see <https://climatedataguide.ucar.edu/climate-data/standardized-precipitation-index-spi> and <http://spei.csic.es/>) for multiple time series or spatially gridded values. |
Authors: | Emanuele Cordano [aut, cre] |
Maintainer: | Emanuele Cordano <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.6.6 |
Built: | 2024-11-06 02:56:01 UTC |
Source: | https://github.com/ecor/lmompi |
cdf...
: probability distribution fitting with L-Moments.These functions compute value(s) of cumulated probability or SPI-like (normal standardize) index from a sample or time series of x
.
cdf( para, x, probability_distribution_attrname = "probability_distrib", indices = NULL, return.as.spi = FALSE, spi.scale = NA, distrib = NA, ... ) spi.cdf(x, para, ...) cdf.spi(x, para, ...)
cdf( para, x, probability_distribution_attrname = "probability_distrib", indices = NULL, return.as.spi = FALSE, spi.scale = NA, distrib = NA, ... ) spi.cdf(x, para, ...) cdf.spi(x, para, ...)
x , para , ...
|
L-moments and further parameters for |
probability_distribution_attrname |
attribute name for probability distribution |
indices |
vector of string working as factors or indices, e g. the month names or similar. It must be of the same length of |
return.as.spi |
logical parameter. Default is |
spi.scale |
integer value or |
distrib |
character string indicating the probability distribution, it can be used in case |
A vector of cumulated probability value(s) or SPI-like Gaussianized values. It is a list of vectors in case of several probability parametric distribution functions (i.e. para
is a list and length(para)>1
).
pel
,cdfexp
,cdfgam
,cdfgev
,cdfglo
,
cdfgpa
,cdfgno
,cdfgum
,cdfkap
,cdfln3
,cdfnor
,cdfpe3
,cdfwak
,cdfwei
# Sample L-moments of Ozone from the airquality data data(airquality) lmom <- samlmu(airquality$Ozone,nmom=6) distrib <- c("exp","gam","gev","glo","gpa","gno","gum","kap", "ln3","nor","pe3","wak","wei") para_list <- pel(distrib=distrib,lmom=lmom) cdf_list <- cdf(para=para_list,x=airquality$Ozone) cdf_gam <- cdf(para=para_list$gam,x=airquality$Ozone) cdf_gam2 <- cdf(para=para_list$gam,x=airquality$Ozone,distrib="gam") if (any(cdf_gam!=cdf_gam2,na.rm=TRUE)) stop("Any possible errors after 0.6.3 package updates!") ## Comparison with the SPI/SPEI algorithms: 'SPEI::spi' ('SPEI' package) if (requireNamespace("SPEI",quietly = TRUE)) { library(SPEI) data(wichita) distrib_wichita <- 'pe3' spi.scale <- 1 month_wichita <- sprintf("M%02d",wichita$MONTH) para_whichita <- pel(x=wichita$PRCP,indices=month_wichita,distrib=distrib_wichita, spi.scale=spi.scale) spi_wichita <- spi.cdf(x=wichita$PRCP,indices=month_wichita,para=para_whichita, spi.scale=spi.scale) spi_wichita_speipkg <- spi(data=wichita$PRCP,distrib='PearsonIII',scale=spi.scale) difference <- spi_wichita-spi_wichita_speipkg$fitted }
# Sample L-moments of Ozone from the airquality data data(airquality) lmom <- samlmu(airquality$Ozone,nmom=6) distrib <- c("exp","gam","gev","glo","gpa","gno","gum","kap", "ln3","nor","pe3","wak","wei") para_list <- pel(distrib=distrib,lmom=lmom) cdf_list <- cdf(para=para_list,x=airquality$Ozone) cdf_gam <- cdf(para=para_list$gam,x=airquality$Ozone) cdf_gam2 <- cdf(para=para_list$gam,x=airquality$Ozone,distrib="gam") if (any(cdf_gam!=cdf_gam2,na.rm=TRUE)) stop("Any possible errors after 0.6.3 package updates!") ## Comparison with the SPI/SPEI algorithms: 'SPEI::spi' ('SPEI' package) if (requireNamespace("SPEI",quietly = TRUE)) { library(SPEI) data(wichita) distrib_wichita <- 'pe3' spi.scale <- 1 month_wichita <- sprintf("M%02d",wichita$MONTH) para_whichita <- pel(x=wichita$PRCP,indices=month_wichita,distrib=distrib_wichita, spi.scale=spi.scale) spi_wichita <- spi.cdf(x=wichita$PRCP,indices=month_wichita,para=para_whichita, spi.scale=spi.scale) spi_wichita_speipkg <- spi(data=wichita$PRCP,distrib='PearsonIII',scale=spi.scale) difference <- spi_wichita-spi_wichita_speipkg$fitted }
This packages contains wrapper functions of 'lmom' packages :
cdf
: generic distribution function;
qua
: generic quantile function;
pel
: fitting of probability distribution function through L-moments.
The example functions are illustrated making use of CHIRPS rainfall meteorological data taken:
Funk, Chris, Pete Peterson, Martin Landsfeld, Diego Pedreros, James Verdin, Shraddhanand Shukla, Gregory Husak, James Rowland, Laura Harrison, Andrew Hoell and Joel Michaelsen. "The climate hazards infrared precipitation with stations - a new environmental record for monitoring extremes". Scientific Data 2, 150066. doi:10.1038/sdata.2015.66 2015 , https://chc.ucsb.edu/data/chirps.
The package-provided datasets shall be only used as example datasets.
The package also contains wrapped functions to calculate several indices based on variability (e.g. 'SPI' , Standardized
Precipitation Index, see https://climatedataguide.ucar.edu/climate-data/standardized-precipitation-index-spi and http://spei.csic.es) for multiple time series or spatio-temporal gridded values.
The function spi.cdf()
is compared against SPEI::spi()
in SPEI package (https://cran.r-project.org/package=SPEI). The differences in SPI extimation have order of magnitude averagely about 10^-8, due to the different fitting methods implemented in the two packages.
(see SPEI::spi()
and spi.cdf()
for more details).
The development of this package has been sponsored by ACEWATER2 and "Water for Growth and Poverty Reduction in the Mekrou" projects of the Joint Research Centre of the Europan Commission (https://aquaknow.jrc.ec.europa.eu).
pel...
Generic function for pel...
: probability distribution fitting with L-Moments
pel( distrib = c("exp", "gam", "gev", "glo", "gpa", "gno", "gum", "kap", "ln3", "nor", "pe3", "wak", "wei"), lmom = NULL, probability_distribution_attrname = "probability_distrib", x = NULL, nmom = 5, sort.data = TRUE, ratios = sort.data, trim = 0, indices = NULL, spi.scale = NA, correction = NULL, ... ) pel_x(x, ...) pel_lmom(lmom, ...)
pel( distrib = c("exp", "gam", "gev", "glo", "gpa", "gno", "gum", "kap", "ln3", "nor", "pe3", "wak", "wei"), lmom = NULL, probability_distribution_attrname = "probability_distrib", x = NULL, nmom = 5, sort.data = TRUE, ratios = sort.data, trim = 0, indices = NULL, spi.scale = NA, correction = NULL, ... ) pel_x(x, ...) pel_lmom(lmom, ...)
distrib |
character string indicating the probability distribution to fit |
lmom , ...
|
L-moments and further parameters for |
probability_distribution_attrname |
attribute name for probability distribution |
x |
vector containg sample. It is utiled to calculete L-moments in case |
nmom , sort.data , ratios , trim
|
arguments for |
indices |
optional index or tag character vector of the same length of |
spi.scale |
integer value or |
correction |
numeric value correction for the 3rd (and higher) L-moment estimation. Default is |
pel_x
and pel_lmom
are wrapper functions of pel
whose first argument is x
or lmom
respectively.
A numeric vector containing the parameters of the selected probability distribution. It is a list in case of selection of several probability distributions (i.e. length(distrib)>1
).
pel...
,pelexp
,pelgam
,pelgev
,pelglo
,pelgpa
,
pelgno
,pelgum
,pelkap
,pelln3
,pelnor
,
# Sample L-moments of Ozone from the airquality data data(airquality) lmom <- samlmu(airquality$Ozone,nmom=6) distrib <- "gev" # Fit a GEV distribution out_gev <- pel(distrib=distrib,lmom=lmom) distrib <- c("exp","gam","gev","glo","gpa","gno","gum","kap","ln3", "nor","pe3","wak","wei") out_list <- pel(distrib=distrib,lmom=lmom)
# Sample L-moments of Ozone from the airquality data data(airquality) lmom <- samlmu(airquality$Ozone,nmom=6) distrib <- "gev" # Fit a GEV distribution out_gev <- pel(distrib=distrib,lmom=lmom) distrib <- c("exp","gam","gev","glo","gpa","gno","gum","kap","ln3", "nor","pe3","wak","wei") out_list <- pel(distrib=distrib,lmom=lmom)
qua...
: probabilily distribution fitting with L-MomentsGeneric function for qua...
: probabilily distribution fitting with L-Moments
qua( para, f, probability_distribution_attrname = "probability_distrib", distrib = NA, ... )
qua( para, f, probability_distribution_attrname = "probability_distrib", distrib = NA, ... )
f , para , ...
|
L-moments and further parameters for |
probability_distribution_attrname |
attribute name for probability distribution |
distrib |
character string indicating the probability distribution, it can be used in case |
A vector of quantiles. It is a list of vectors of quantiles in case of several probability parametric distribution functions (i.e. para
is a list and length(para)>1
).
pel
,quaexp
,quagam
,quagev
,quaglo
,quagpa
,quagno
,quagum
,
quakap
,qualn3
,quanor
,quape3
,
quawak
,quawei
# Sample L-moments of Ozone from the airquality data data(airquality) lmom <- samlmu(airquality$Ozone,nmom=6) distrib <- c("exp","gam","gev","glo","gpa","gno","gum","kap","ln3","nor", "pe3","wak","wei") para_list <- pel(distrib=distrib,lmom=lmom) f <- (1:10)/10 qua_list <- qua(para=para_list,f=f) qua_gam <- qua(para=para_list$gam,f=f) qua_gam2 <- qua(para=as.vector(para_list$gam),f=f,distrib="gam") if (any(qua_gam!=qua_gam2,na.rm=TRUE)) stop("Any possible errors after 0.6.3 package updates!")
# Sample L-moments of Ozone from the airquality data data(airquality) lmom <- samlmu(airquality$Ozone,nmom=6) distrib <- c("exp","gam","gev","glo","gpa","gno","gum","kap","ln3","nor", "pe3","wak","wei") para_list <- pel(distrib=distrib,lmom=lmom) f <- (1:10)/10 qua_list <- qua(para=para_list,f=f) qua_gam <- qua(para=para_list$gam,f=f) qua_gam2 <- qua(para=as.vector(para_list$gam),f=f,distrib="gam") if (any(qua_gam!=qua_gam2,na.rm=TRUE)) stop("Any possible errors after 0.6.3 package updates!")