| 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] (ORCID: <https://orcid.org/0000-0002-3508-5898>) |
| Maintainer: | Emanuele Cordano <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.6.8 |
| Built: | 2026-05-25 08:16:32 UTC |
| Source: | https://github.com/ecor/lmompi |
This function checks whether a given set of L-moments satisfies theoretical and practical constraints commonly used in statistical modeling. These constraints ensure the validity of L-moment ratios and help detect potential issues in the data or its transformation (e.g., log-transformed data with non-positive values).
are.lmoms.valid( lmom, clean = TRUE, return_numeric = FALSE, condt3t4 = TRUE, condtt3 = FALSE )are.lmoms.valid( lmom, clean = TRUE, return_numeric = FALSE, condt3t4 = TRUE, condtt3 = FALSE )
lmom |
vector of L-moments |
clean |
logical if it is |
return_numeric |
logical if it is |
condt3t4 |
logical if |
condtt3 |
logical if |
logical value indicating if all of these conditions are verified:
(L-scale must be positive)
(L-skewness must lie within )
(i-th L-moment ratio must lie within for i>3)
and must be finite
is verified for theoretical consistency
is verified for theoretical consistency (only for a distribution that takes positive values, p.24 ref)
Hosking, J.R.M. and Wallis, J.R. (1997). Regional Frequency Analysis: An Approach Based on L-Moments. Cambridge University Press. doi:10.1017/CBO9780511529443
library(lmomPi) data(airquality) lmom <- samlmu(airquality$Ozone, 6) are.lmoms.valid(lmom = lmom) are.lmoms.valid(lmom = lmom,return_numeric=TRUE) lmoml <- samlmu(airquality$Ozone, 6,ratio=FALSE) are.lmoms.valid(lmom = lmoml) are.lmoms.valid(lmom = lmoml,condtt3=TRUE) are.lmoms.valid(lmom = lmoml,return_numeric=TRUE) are.lmoms.valid(lmom = lmoml,return_numeric=TRUE,condtt3=TRUE)library(lmomPi) data(airquality) lmom <- samlmu(airquality$Ozone, 6) are.lmoms.valid(lmom = lmom) are.lmoms.valid(lmom = lmom,return_numeric=TRUE) lmoml <- samlmu(airquality$Ozone, 6,ratio=FALSE) are.lmoms.valid(lmom = lmoml) are.lmoms.valid(lmom = lmoml,condtt3=TRUE) are.lmoms.valid(lmom = lmoml,return_numeric=TRUE) are.lmoms.valid(lmom = lmoml,return_numeric=TRUE,condtt3=TRUE)
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,check_lmom_validity=TRUE) 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,check_lmom_validity=TRUE) 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 }
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, check_lmom_validity = FALSE, condt3t4 = TRUE, ... ) 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, check_lmom_validity = FALSE, condt3t4 = TRUE, ... ) 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 |
check_lmom_validity |
logical. Default is |
condt3t4 |
argument for |
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!")