cdf: Generic function for 'cdf...': probability distribution...

View source: R/cdf.R

cdfR Documentation

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 documentation built on Aug. 15, 2023, 5:07 p.m.

Related to cdf in lmomPi...