Title: | L-Moments and Quantile Mixtures |
---|---|
Description: | Contains functions to estimate L-moments and trimmed L-moments from the data. Also contains functions to estimate the parameters of the normal polynomial quantile mixture and the Cauchy polynomial quantile mixture from L-moments and trimmed L-moments. |
Authors: | Juha Karvanen [cre, aut], Santeri Karppinen [aut] |
Maintainer: | Juha Karvanen <[email protected]> |
License: | GPL-2 |
Version: | 1.3-1 |
Built: | 2024-11-07 03:10:44 UTC |
Source: | https://github.com/cran/Lmoments |
Density, distribution function, quantile function and random generation for the Cauchy-polynomial quantile mixture.
dcauchypoly(x,param) pcauchypoly(x,param) qcauchypoly(cp,param) rcauchypoly(n,param) cauchypoly_pdf(x,param) cauchypoly_cdf(x,param) cauchypoly_inv(cp,param) cauchypoly_rnd(n,param)
dcauchypoly(x,param) pcauchypoly(x,param) qcauchypoly(cp,param) rcauchypoly(n,param) cauchypoly_pdf(x,param) cauchypoly_cdf(x,param) cauchypoly_inv(cp,param) cauchypoly_rnd(n,param)
x |
vector of quantiles |
cp |
vector of probabilities |
n |
number of observations |
param |
vector of parameters |
The length the parameter vector specifies the order of the polynomial in the quantile mixture. If k<-length(param) then param[1:(k-1)] contains the mixture coefficients of polynomials starting from the constant and param[k] is the mixture coefficient for Cauchy distribution. (Functions cauchypoly\_pdf, cauchypoly\_cdf, cauchypoly\_inv and cauchypoly\_rnd are aliases for compatibility with older versions of this package.)
'dcauchypoly' gives the density, 'pcauchypoly' gives the cumulative distribution function, 'qcauchypoly' gives the quantile function, and 'rcauchypoly' generates random deviates.
Juha Karvanen [email protected]
Karvanen, J. 2006. Estimation of quantile mixtures via L-moments and trimmed L-moments, Computational Statistics & Data Analysis 51, (2), 947–959. http://www.bsp.brain.riken.jp/publications/2006/karvanen_quantile_mixtures.pdf.
data2cauchypoly4
for the parameter estimation and
dnormpoly
for the normal-polynomial quantile mixture.
#Generates 500 random variables from the Cauchy-polynomial quantile mixture, #calculates the trimmed L-moments, #estimates parameters via trimmed L-moments and #plots the true pdf and the estimated pdf together with the histogram of the data. true_params<-t1lmom2cauchypoly4(c(0,1,0.075,0.343)); x<-rcauchypoly(500,true_params); t1lmom<-t1lmoments(x); estim_params<-t1lmom2cauchypoly4(t1lmom); plotpoints<-seq(-10,10,by=0.01); histpoints<-c(seq(min(x)-1,-20,length.out=50),seq(-10,10,by=0.5),seq(20,max(x)+1,length.out=50)); hist(x,breaks=histpoints,freq=FALSE,xlim=c(-10,10)); lines(plotpoints,dcauchypoly(plotpoints,estim_params),col='red'); lines(plotpoints,dcauchypoly(plotpoints,true_params),col='blue');
#Generates 500 random variables from the Cauchy-polynomial quantile mixture, #calculates the trimmed L-moments, #estimates parameters via trimmed L-moments and #plots the true pdf and the estimated pdf together with the histogram of the data. true_params<-t1lmom2cauchypoly4(c(0,1,0.075,0.343)); x<-rcauchypoly(500,true_params); t1lmom<-t1lmoments(x); estim_params<-t1lmom2cauchypoly4(t1lmom); plotpoints<-seq(-10,10,by=0.01); histpoints<-c(seq(min(x)-1,-20,length.out=50),seq(-10,10,by=0.5),seq(20,max(x)+1,length.out=50)); hist(x,breaks=histpoints,freq=FALSE,xlim=c(-10,10)); lines(plotpoints,dcauchypoly(plotpoints,estim_params),col='red'); lines(plotpoints,dcauchypoly(plotpoints,true_params),col='blue');
Estimates covariance matrix of the four parameters of normal-polynomial quantile mixture
covnormpoly4(data)
covnormpoly4(data)
data |
vector of observations |
covariance matrix of the four parameters of normal-polynomial quantile mixture
Juha Karvanen [email protected]
Karvanen, J. 2006. Estimation of quantile mixtures via L-moments and trimmed L-moments, Computational Statistics & Data Analysis 51, (2), 947–959. http://www.bsp.brain.riken.jp/publications/2006/karvanen_quantile_mixtures.pdf.
Lmomcov
for covariance matrix of L-moments,
dnormpoly
for the normal-polynomial quantile mixture and
data2normpoly4
for the estimation of the normal-polynomial quantile mixture.
Estimates the parameters of the Cauchy-polynomial quantile mixture from data or from trimmed L-moments
data2cauchypoly4(data) t1lmom2cauchypoly4(t1lmom)
data2cauchypoly4(data) t1lmom2cauchypoly4(t1lmom)
data |
vector |
t1lmom |
vector of trimmed L-moments |
vector containing the four parameters of the Cauchy-polynomial quantile mixture
Juha Karvanen [email protected]
Karvanen, J. 2006. Estimation of quantile mixtures via L-moments and trimmed L-moments, Computational Statistics & Data Analysis 51, (2), 947–959. http://www.bsp.brain.riken.jp/publications/2006/karvanen_quantile_mixtures.pdf.
t1lmoments
for trimmed L-moments,
dcauchypoly
for the Cauchy-polynomial quantile mixture and
data2normpoly4
for the estimation of the normal-polynomial quantile mixture.
#Generates 500 random variables from the Cauchy-polynomial quantile mixture, #calculates the trimmed L-moments, #estimates parameters via trimmed L-moments and #plots the true pdf and the estimated pdf together with the histogram of the data. true_params<-t1lmom2cauchypoly4(c(0,1,0.075,0.343)); x<-rcauchypoly(500,true_params); t1lmom<-t1lmoments(x); estim_params<-t1lmom2cauchypoly4(t1lmom); plotpoints<-seq(-10,10,by=0.01); histpoints<-c(seq(min(x)-1,-20,length.out=50),seq(-10,10,by=0.5),seq(20,max(x)+1,length.out=50)); hist(x,breaks=histpoints,freq=FALSE,xlim=c(-10,10)); lines(plotpoints,dcauchypoly(plotpoints,estim_params),col='red'); lines(plotpoints,dcauchypoly(plotpoints,true_params),col='blue');
#Generates 500 random variables from the Cauchy-polynomial quantile mixture, #calculates the trimmed L-moments, #estimates parameters via trimmed L-moments and #plots the true pdf and the estimated pdf together with the histogram of the data. true_params<-t1lmom2cauchypoly4(c(0,1,0.075,0.343)); x<-rcauchypoly(500,true_params); t1lmom<-t1lmoments(x); estim_params<-t1lmom2cauchypoly4(t1lmom); plotpoints<-seq(-10,10,by=0.01); histpoints<-c(seq(min(x)-1,-20,length.out=50),seq(-10,10,by=0.5),seq(20,max(x)+1,length.out=50)); hist(x,breaks=histpoints,freq=FALSE,xlim=c(-10,10)); lines(plotpoints,dcauchypoly(plotpoints,estim_params),col='red'); lines(plotpoints,dcauchypoly(plotpoints,true_params),col='blue');
Estimates the parameters of normal-polynomial quantile mixture from data or from L-moments
data2normpoly4(data) lmom2normpoly4(lmom) data2normpoly6(data) lmom2normpoly6(lmom)
data2normpoly4(data) lmom2normpoly4(lmom) data2normpoly6(data) lmom2normpoly6(lmom)
data |
matrix or data frame |
lmom |
vector or matrix of L-moments |
vector or matrix containing the four or six parameters of normal-polynomial quantile mixture
Juha Karvanen [email protected]
Karvanen, J. 2006. Estimation of quantile mixtures via L-moments and trimmed L-moments, Computational Statistics & Data Analysis 51, (2), 947–959. http://www.bsp.brain.riken.jp/publications/2006/karvanen_quantile_mixtures.pdf.
dnormpoly
for L-moments,
dnormpoly
for the normal-polynomial quantile mixture and
data2cauchypoly4
for the estimation of Cauchy-polynomial quantile mixture.
#Generates a sample 500 observations from the normal-polynomial quantile mixture, #calculates L-moments and their covariance matrix, #estimates parameters via L-moments and #plots the true pdf and the estimated pdf together with the histogram of the data. true_params<-lmom2normpoly4(c(0,1,0.2,0.05)); x<-rnormpoly(500,true_params); lmoments<-Lmoments(x); lmomcov<-Lmomcov(x); estim_params<-lmom2normpoly4(lmoments); hist(x,30,freq=FALSE); plotpoints<-seq(min(x)-1,max(x)+1,by=0.01); lines(plotpoints,dnormpoly(plotpoints,estim_params),col='red'); lines(plotpoints,dnormpoly(plotpoints,true_params),col='blue');
#Generates a sample 500 observations from the normal-polynomial quantile mixture, #calculates L-moments and their covariance matrix, #estimates parameters via L-moments and #plots the true pdf and the estimated pdf together with the histogram of the data. true_params<-lmom2normpoly4(c(0,1,0.2,0.05)); x<-rnormpoly(500,true_params); lmoments<-Lmoments(x); lmomcov<-Lmomcov(x); estim_params<-lmom2normpoly4(lmoments); hist(x,30,freq=FALSE); plotpoints<-seq(min(x)-1,max(x)+1,by=0.01); lines(plotpoints,dnormpoly(plotpoints,estim_params),col='red'); lines(plotpoints,dnormpoly(plotpoints,true_params),col='blue');
Calculates sample L-moments, L-coefficients and covariance matrix of L-moments.
Lmoments(data, rmax = 4, na.rm = FALSE, returnobject = FALSE, trim = c(0, 0)) Lcoefs(data, rmax = 4, na.rm = FALSE, trim = c(0, 0)) Lmomcov(data, rmax = 4, na.rm = FALSE) Lmoments_calc(data, rmax = 4) Lmomcov_calc(data, rmax = 4) shiftedlegendre(rmax)
Lmoments(data, rmax = 4, na.rm = FALSE, returnobject = FALSE, trim = c(0, 0)) Lcoefs(data, rmax = 4, na.rm = FALSE, trim = c(0, 0)) Lmomcov(data, rmax = 4, na.rm = FALSE) Lmoments_calc(data, rmax = 4) Lmomcov_calc(data, rmax = 4) shiftedlegendre(rmax)
data |
matrix or data frame. |
rmax |
maximum order of L-moments. |
na.rm |
a logical value indicating whether 'NA' values should be removed before the computation proceeds. |
returnobject |
a logical value indicating whether a list object should be returned instead of an array of L-moments. |
trim |
c(0, 0) for ordinary L-moments and c(1, 1) for trimmed (t = 1) L-moments |
Lmoments
returns an array of L-moments containing a row for each variable in data, or if returnobject=TRUE,
a list containing
lambdas |
an array of L-moments |
ratios |
an array of mean, L-scale and L-moment ratios |
trim |
the value of the parameter 'trim' |
source |
a string with value "Lmoments" or "t1lmoments". |
Lcoefs
returns an array of L-coefficients (mean, L-scale, L-skewness, L-kurtosis, ...)
containing a row for each variable in data.
Lmomcov
returns the covariance matrix of L-moments or a list of covariance matrices if the input has multiple columns.
The numerical accuracy of the results decreases with increasing rmax
.
With rmax > 5
, a warning is thrown, as the numerical accuracy of the results is likely less than sqrt(.Machine$double.eps)
.
shiftedlegendre
returns a matrix of the coefficients of the shifted Legendre polynomials up to a given order.
Functions Lmoments
and Lcoefs
calculate trimmed L-moments if you specify trim = c(1, 1)
.
Lmoments_calc
and Lmomcov_calc
are internal C++ functions called by Lmoments
and Lmomcov
.
The direct use of these functions is not recommended.
Juha Karvanen [email protected], Santeri Karppinen
Karvanen, J. 2006. Estimation of quantile mixtures via L-moments and trimmed L-moments, Computational Statistics & Data Analysis 51, (2), 947–959. http://www.bsp.brain.riken.jp/publications/2006/karvanen_quantile_mixtures.pdf.
Elamir, E. A., Seheult, A. H. 2004. Exact variance structure of sample L-moments, Journal of Statistical Planning and Inference 124 (2) 337–359.
Hosking, J. 1990. L-moments: Analysis and estimation distributions using linear combinations of order statistics, Journal of Royal Statistical Society B 52, 105–124.
t1lmoments
for trimmed L-moments,
dnormpoly
, lmom2normpoly4
and covnormpoly4
for the normal-polynomial quantile mixture
and package lmomco for additional L-moment functions
#Generates a sample 500 observations from the normal-polynomial quantile mixture, #calculates the L-moments and their covariance matrix, #estimates parameters via L-moments and #plots the true pdf and the estimated pdf together with the histogram of the data. true_params<-lmom2normpoly4(c(0,1,0.2,0.05)); x<-rnormpoly(500,true_params); lmoments<-Lmoments(x); lmomcov<-Lmomcov(x); estim_params<-lmom2normpoly4(lmoments); hist(x,30,freq=FALSE) plotpoints<-seq(min(x)-1,max(x)+1,by=0.01); lines(plotpoints,dnormpoly(plotpoints,estim_params),col='red'); lines(plotpoints,dnormpoly(plotpoints,true_params),col='blue');
#Generates a sample 500 observations from the normal-polynomial quantile mixture, #calculates the L-moments and their covariance matrix, #estimates parameters via L-moments and #plots the true pdf and the estimated pdf together with the histogram of the data. true_params<-lmom2normpoly4(c(0,1,0.2,0.05)); x<-rnormpoly(500,true_params); lmoments<-Lmoments(x); lmomcov<-Lmomcov(x); estim_params<-lmom2normpoly4(lmoments); hist(x,30,freq=FALSE) plotpoints<-seq(min(x)-1,max(x)+1,by=0.01); lines(plotpoints,dnormpoly(plotpoints,estim_params),col='red'); lines(plotpoints,dnormpoly(plotpoints,true_params),col='blue');
Density, distribution function, quantile function and random generation for the normal-polynomial quantile mixture.
dnormpoly(x,param) pnormpoly(x,param) qnormpoly(cp,param) rnormpoly(n,param) normpoly_pdf(x,param) normpoly_cdf(x,param) normpoly_inv(cp,param) normpoly_rnd(n,param)
dnormpoly(x,param) pnormpoly(x,param) qnormpoly(cp,param) rnormpoly(n,param) normpoly_pdf(x,param) normpoly_cdf(x,param) normpoly_inv(cp,param) normpoly_rnd(n,param)
x |
vector of quantiles |
cp |
vector of probabilities |
n |
number of observations |
param |
vector of parameters |
The length the parameter vector specifies the order of the polynomial in the quantile mixture. If k<-length(param) then param[1:(k-1)] contains the mixture coefficients of polynomials starting from the constant and param[k] is the mixture coefficient for normal distribution. (Functions normpoly\_pdf, normpoly\_cdf, normpoly\_inv and normpoly\_rnd are aliases for compatibility with older versions of this package.)
'dnormpoly' gives the density, 'pnormpoly' gives the cumulative distribution function, 'qnormpoly' gives the quantile function, and 'rnormpoly' generates random deviates.
Juha Karvanen [email protected]
Karvanen, J. 2006. Estimation of quantile mixtures via L-moments and trimmed L-moments, Computational Statistics & Data Analysis 51, (2), 947–959. http://www.bsp.brain.riken.jp/publications/2006/karvanen_quantile_mixtures.pdf.
data2normpoly4
for the parameter estimation and
dcauchypoly
for the Cauchy-polynomial quantile mixture.
#Generates a sample 500 observations from the normal-polynomial quantile mixture, #calculates L-moments and their covariance matrix, #estimates parameters via L-moments and #plots the true pdf and the estimated pdf together with the histogram of the data. true_params<-lmom2normpoly4(c(0,1,0.2,0.05)); x<-rnormpoly(500,true_params); lmoments<-Lmoments(x); lmomcov<-Lmomcov(x); estim_params<-lmom2normpoly4(lmoments); hist(x,30,freq=FALSE) plotpoints<-seq(min(x)-1,max(x)+1,by=0.01); lines(plotpoints,dnormpoly(plotpoints,estim_params),col='red'); lines(plotpoints,dnormpoly(plotpoints,true_params),col='blue');
#Generates a sample 500 observations from the normal-polynomial quantile mixture, #calculates L-moments and their covariance matrix, #estimates parameters via L-moments and #plots the true pdf and the estimated pdf together with the histogram of the data. true_params<-lmom2normpoly4(c(0,1,0.2,0.05)); x<-rnormpoly(500,true_params); lmoments<-Lmoments(x); lmomcov<-Lmomcov(x); estim_params<-lmom2normpoly4(lmoments); hist(x,30,freq=FALSE) plotpoints<-seq(min(x)-1,max(x)+1,by=0.01); lines(plotpoints,dnormpoly(plotpoints,estim_params),col='red'); lines(plotpoints,dnormpoly(plotpoints,true_params),col='blue');
Calculates sample trimmed L-moments with trimming parameter 1.
t1lmoments(data, rmax = 4) t1lmoments_calc(data, rmax = 4)
t1lmoments(data, rmax = 4) t1lmoments_calc(data, rmax = 4)
data |
matrix or data frame. |
rmax |
maximum order of trimmed L-moments. |
array of trimmed L-moments (trimming parameter = 1) up to order 4 containing a row for each variable in data.
Functions link{Lmoments}
and link{Lcoefs}
calculate trimmed L-moments if you specify trim = c(1, 1)
.
t1lmoments_calc
is an internal C++ function called by t1lmoments
. The direct use of this function is not recommended.
Juha Karvanen [email protected], Santeri Karppinen
Karvanen, J. 2006. Estimation of quantile mixtures via L-moments and trimmed L-moments, Computational Statistics & Data Analysis 51, (2), 947–959. http://www.bsp.brain.riken.jp/publications/2006/karvanen_quantile_mixtures.pdf.
Elamir, E. A., Seheult, A. H. 2003. Trimmed L-moments, Computational Statistics & Data Analysis 43, 299–314.
Lmoments
for L-moments, and
dcauchypoly
and t1lmom2cauchypoly4
for the Cauchy-polynomial quantile mixture
#Generates 500 random variables from the Cauchy-polynomial quantile mixture, #calculates the trimmed L-moments, #estimates parameters via trimmed L-moments and #plots the true pdf and the estimated pdf together with the histogram of the data. true_params<-t1lmom2cauchypoly4(c(0,1,0.075,0.343)); x<-rcauchypoly(500,true_params); t1lmom<-t1lmoments(x); estim_params<-t1lmom2cauchypoly4(t1lmom); plotpoints<-seq(-10,10,by=0.01); histpoints<-c(seq(min(x)-1,-20,length.out=50),seq(-10,10,by=0.5),seq(20,max(x)+1,length.out=50)); hist(x,breaks=histpoints,freq=FALSE,xlim=c(-10,10)); lines(plotpoints,dcauchypoly(plotpoints,estim_params),col='red'); lines(plotpoints,dcauchypoly(plotpoints,true_params),col='blue');
#Generates 500 random variables from the Cauchy-polynomial quantile mixture, #calculates the trimmed L-moments, #estimates parameters via trimmed L-moments and #plots the true pdf and the estimated pdf together with the histogram of the data. true_params<-t1lmom2cauchypoly4(c(0,1,0.075,0.343)); x<-rcauchypoly(500,true_params); t1lmom<-t1lmoments(x); estim_params<-t1lmom2cauchypoly4(t1lmom); plotpoints<-seq(-10,10,by=0.01); histpoints<-c(seq(min(x)-1,-20,length.out=50),seq(-10,10,by=0.5),seq(20,max(x)+1,length.out=50)); hist(x,breaks=histpoints,freq=FALSE,xlim=c(-10,10)); lines(plotpoints,dcauchypoly(plotpoints,estim_params),col='red'); lines(plotpoints,dcauchypoly(plotpoints,true_params),col='blue');