Package 'lmomPi'

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

Help Index


Generic function for cdf...: probability distribution fitting with L-Moments.

Description

These functions compute value(s) of cumulated probability or SPI-like (normal standardize) index from a sample or time series of x.

Usage

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, ...)

Arguments

x, para, ...

L-moments and further parameters for cdf... and cdf

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 x or the length equal to 1 other NULL, if not used. If used, it computes cdf for each factor.

return.as.spi

logical parameter. Default is FALSE. If it is TRUE probability value is transformed to a normalized random variable through standard qnorm, as for Standard Precipitation Index (SPI) (https://climatedataguide.ucar.edu/climate-data/standardized-precipitation-index-spi).

spi.scale

integer value or NA. If it greater than 1 x is filtered with the sum of a generic element of x and the previous spi.scale-1 ones (e.g. SPI-3,SPI-6, etc. ). Default is NA (no filtering) which is equivalent to spi.scale=1.

distrib

character string indicating the probability distribution, it can be used in case para has no attributes. Default is NA and distribution info are all passed through para.

Value

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).

See Also

pel,cdfexp,cdfgam,cdfgev,cdfglo,

cdfgpa,cdfgno,cdfgum,cdfkap,cdfln3,cdfnor,cdfpe3,cdfwak,cdfwei

Examples

# 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
}

lmomPi: (Precipitation) Frequency Analysis and Variability with L-Moments from lmom

Description

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.

Details

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).


Generic function for pel...

Description

Generic function for pel...: probability distribution fitting with L-Moments

Usage

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, ...)

Arguments

distrib

character string indicating the probability distribution to fit

lmom, ...

L-moments and further parameters for pel...

probability_distribution_attrname

attribute name for probability distribution

x

vector containg sample. It is utiled to calculete L-moments in case lmom is set equal to NULL.

nmom, sort.data, ratios, trim

arguments for samlmu (nmom=5 by default). Thay are utilized if argument lmom is NULL.

indices

optional index or tag character vector of the same length of x used as INDEX for tapply. It is used to fit different probability distribution in one sample time series (e. g. months in an year).

spi.scale

integer value or NA. If it is greater than 1, x is filtered with the sum of a generic element of x and the previous spi.scale-1 ones (e.g. SPI-3,SPI-6, etc. ). Default is NA (no filtering) which is equivalent to spi.scale=1.

correction

numeric value correction for the 3rd (and higher) L-moment estimation. Default is NULL , generally it is not used. It is used and suggested to be 10^(-10) in case of a massive function use with lmom=NULL (e.g. raster cell or zonal statistics).

Details

pel_x and pel_lmom are wrapper functions of pel whose first argument is x or lmom respectively.

Value

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).

See Also

pel...,pelexp,pelgam,pelgev,pelglo,pelgpa,

pelgno,pelgum,pelkap,pelln3,pelnor,

pelpe3,pelwak,pelwei,

cdf,qua

Examples

# 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)

Generic function for qua...: probabilily distribution fitting with L-Moments

Description

Generic function for qua...: probabilily distribution fitting with L-Moments

Usage

qua(
  para,
  f,
  probability_distribution_attrname = "probability_distrib",
  distrib = NA,
  ...
)

Arguments

f, para, ...

L-moments and further parameters for qua...

probability_distribution_attrname

attribute name for probability distribution

distrib

character string indicating the probability distribution, it can be used in case para has no attributes. Default is NA and distribution info are all passed through para.

Value

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).

See Also

pel,quaexp,quagam,quagev,quaglo,quagpa,quagno,quagum,

quakap,qualn3,quanor,quape3, quawak,quawei

Examples

# 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!")