| Type: | Package |
| Title: | The Asymmetric Laplace Distribution |
| Version: | 1.3.1 |
| Date: | 2021-04-04 |
| Author: | Christian E. Galarza <cgalarza88@gmail.com> and Victor H. Lachos <hlachos@ime.unicamp.br> |
| Maintainer: | Christian E. Galarza <cgalarza88@gmail.com> |
| Description: | It provides the density, distribution function, quantile function, random number generator, likelihood function, moments and Maximum Likelihood estimators for a given sample, all this for the three parameter Asymmetric Laplace Distribution defined in Koenker and Machado (1999). This is a special case of the skewed family of distributions available in Galarza et.al. (2017) <doi:10.1002/sta4.140> useful for quantile regression. |
| License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
| NeedsCompilation: | no |
| Packaged: | 2021-04-04 18:49:07 UTC; cgala |
| Repository: | CRAN |
| Date/Publication: | 2021-04-04 19:10:02 UTC |
The Asymmetric Laplace Distribution
Description
It provides the density, distribution function, quantile function, random number generator, likelihood function, moments and Maximum Likelihood estimators for a given sample, all this for the three parameter Asymmetric Laplace Distribution defined in Koenker and Machado (1999) useful for quantile regression.
Details
| Package: | ald |
| Type: | Package |
| Version: | 1.0 |
| Date: | 2015-01-27 |
| License: | GPL (>=2) |
Author(s)
Christian E. Galarza <cgalarza88@gmail.com> and Victor H. Lachos <hlachos@ime.unicamp.br>
References
Koenker, R., Machado, J. (1999). Goodness of fit and related inference processes for quantile regression. J. Amer. Statist. Assoc. 94(3):1296-1309.
Yu, K. & Moyeed, R. (2001). Bayesian quantile regression. Statistics & Probability Letters, 54(4), 437-447.
Yu, K., & Zhang, J. (2005). A three-parameter asymmetric Laplace distribution and its extension. Communications in Statistics-Theory and Methods, 34(9-10), 1867-1879.
See Also
Examples
## Let's plot an Asymmetric Laplace Distribution!
##Density
sseq = seq(-40,80,0.5)
dens = dALD(y=sseq,mu=50,sigma=3,p=0.75)
plot(sseq,dens,type="l",lwd=2,col="red",xlab="x",ylab="f(x)", main="ALD Density function")
## Distribution Function
df = pALD(q=sseq,mu=50,sigma=3,p=0.75)
plot(sseq,df,type="l",lwd=2,col="blue",xlab="x",ylab="F(x)", main="ALD Distribution function")
abline(h=1,lty=2)
##Inverse Distribution Function
prob = seq(0,1,length.out = 1000)
idf = qALD(prob=prob,mu=50,sigma=3,p=0.75)
plot(prob,idf,type="l",lwd=2,col="gray30",xlab="x",ylab=expression(F^{-1}~(x)))
title(main="ALD Inverse Distribution function")
abline(v=c(0,1),lty=2)
#Random Sample Histogram
sample = rALD(n=10000,mu=50,sigma=3,p=0.75)
hist(sample,breaks = 70,freq = FALSE,ylim=c(0,max(dens)),main="")
title(main="Histogram and True density")
lines(sseq,dens,col="red",lwd=2)
## Let's compute the MLE's
param = c(-323,40,0.9)
y = rALD(10000,mu = param[1],sigma = param[2],p = param[3]) #A random sample
res = mleALD(y)
#Comparing
cbind(param,res$par)
#Let's plot
seqq = seq(min(y),max(y),length.out = 1000)
dens = dALD(y=seqq,mu=res$par[1],sigma=res$par[2],p=res$par[3])
hist(y,breaks=50,freq = FALSE,ylim=c(0,max(dens)))
lines(seqq,dens,type="l",lwd=2,col="red",xlab="x",ylab="f(x)", main="ALD Density function")
The Asymmetric Laplace Distribution
Description
Density, distribution function, quantile function and random generation for a Three-Parameter Asymmetric Laplace Distribution defined in Koenker and Machado (1999) useful for quantile regression with location parameter equal to mu, scale parameter sigma and skewness parameter p This is a special case of the skewed family of distributions in Galarza (2016) available in lqr::SKD.
Usage
dALD(y, mu = 0, sigma = 1, p = 0.5)
pALD(q, mu = 0, sigma = 1, p = 0.5, lower.tail = TRUE)
qALD(prob, mu = 0, sigma = 1, p = 0.5, lower.tail = TRUE)
rALD(n, mu = 0, sigma = 1, p = 0.5)
Arguments
y, q |
vector of quantiles. |
prob |
vector of probabilities. |
n |
number of observations. |
mu |
location parameter. |
sigma |
scale parameter. |
p |
skewness parameter. |
lower.tail |
logical; if TRUE (default), probabilities are P[X |
Details
If mu, sigma or p are not specified they assume the default values of 0, 1 and 0.5, respectively, belonging to the Symmetric Standard Laplace Distribution denoted by ALD(0,1,0.5).
As discussed in Koenker and Machado (1999) and Yu and Moyeed (2001) we say that a random variable
Y is distributed as an ALD with location parameter \mu, scale parameter \sigma>0 and skewness parameter p in (0,1), if its probability density function (pdf) is given by
f(y|\mu,\sigma,p)=\frac{p(1-p)}{\sigma}\exp
{-\rho_{p}(\frac{y-\mu}{\sigma})}
where \rho_p(.) is the so called check (or loss) function defined by
\rho_p(u)=u(p - I_{u<0})
,
with I_{.} denoting the usual indicator function. This distribution is denoted by ALD(\mu,\sigma,p) and it's p-th quantile is equal to \mu.
The scale parameter sigma must be positive and non zero. The skew parameter p must be between zero and one (0<p<1).
Value
dALD gives the density, pALD gives the distribution function, qALD gives the quantile function, and rALD generates a random sample.
The length of the result is determined by n for rALD, and is the maximum of the lengths of the numerical arguments for the other functions dALD, pALD and qALD.
Note
The numerical arguments other than n are recycled to the length of the result.
Author(s)
Christian E. Galarza <cgalarza88@gmail.com> and Victor H. Lachos <hlachos@ime.unicamp.br>
References
Galarza Morales, C., Lachos Davila, V., Barbosa Cabral, C., and Castro Cepero, L. (2017) Robust quantile regression using a generalized class of skewed distributions. Stat,6: 113-130 doi: 10.1002/sta4.140.
Yu, K., & Zhang, J. (2005). A three-parameter asymmetric Laplace distribution and its extension. Communications in Statistics-Theory and Methods, 34(9-10), 1867-1879.
See Also
Examples
## Let's plot an Asymmetric Laplace Distribution!
##Density
library(ald)
sseq = seq(-40,80,0.5)
dens = dALD(y=sseq,mu=50,sigma=3,p=0.75)
plot(sseq,dens,type = "l",lwd=2,col="red",xlab="x",ylab="f(x)", main="ALD Density function")
#Look that is a special case of the skewed family in Galarza (2017)
# available in lqr package, dSKD(...,sigma = 2*3,dist = "laplace")
## Distribution Function
df = pALD(q=sseq,mu=50,sigma=3,p=0.75)
plot(sseq,df,type="l",lwd=2,col="blue",xlab="x",ylab="F(x)", main="ALD Distribution function")
abline(h=1,lty=2)
##Inverse Distribution Function
prob = seq(0,1,length.out = 1000)
idf = qALD(prob=prob,mu=50,sigma=3,p=0.75)
plot(prob,idf,type="l",lwd=2,col="gray30",xlab="x",ylab=expression(F^{-1}~(x)))
title(main="ALD Inverse Distribution function")
abline(v=c(0,1),lty=2)
#Random Sample Histogram
sample = rALD(n=10000,mu=50,sigma=3,p=0.75)
hist(sample,breaks = 70,freq = FALSE,ylim=c(0,max(dens)),main="")
title(main="Histogram and True density")
lines(sseq,dens,col="red",lwd=2)
Log-Likelihood function for the Asymmetric Laplace Distribution
Description
Log-Likelihood function for the Three-Parameter Asymmetric Laplace Distribution defined in Koenker and Machado (1999) useful for quantile regression with location parameter equal to mu, scale parameter sigma and skewness parameter p.
Usage
likALD(y, mu = 0, sigma = 1, p = 0.5, loglik = TRUE)
Arguments
y |
observation vector. |
mu |
location parameter |
sigma |
scale parameter |
p |
skewness parameter |
loglik |
logical; if TRUE (default), the Log-likelihood is return, if not just the Likelihood. |
Details
If mu, sigma or p are not specified they assume the default values of 0, 1 and 0.5, respectively, belonging to the Symmetric Standard Laplace Distribution denoted by ALD(0,1,0.5).
As discussed in Koenker and Machado (1999) and Yu and Moyeed (2001) we say that a random variable
Y is distributed as an ALD with location parameter \mu, scale parameter \sigma>0 and skewness parameter p in (0,1), if its probability density function (pdf) is given by
f(y|\mu,\sigma,p)=\frac{p(1-p)}{\sigma}\exp
{-\rho_{p}(\frac{y-\mu}{\sigma})}
where \rho_p(.) is the so called check (or loss) function defined by
\rho_p(u)=u(p - I_{u<0})
,
with I_{.} denoting the usual indicator function. Then the Log-likelihood function is given by
\sum_{i=1}^{n}log(\frac{p(1-p)}{\sigma}\exp
{-\rho_{p}(\frac{y_i-\mu}{\sigma})})
.
The scale parameter sigma must be positive and non zero. The skew parameter p must be between zero and one (0<p<1).
Value
likeALD returns the Log-likelihood by default and just the Likelihood if loglik = FALSE.
Author(s)
Christian E. Galarza <cgalarza88@gmail.com> and Victor H. Lachos <hlachos@ime.unicamp.br>
References
Koenker, R., Machado, J. (1999). Goodness of fit and related inference processes for quantile regression. J. Amer. Statist. Assoc. 94(3):1296-1309.
Yu, K. & Moyeed, R. (2001). Bayesian quantile regression. Statistics & Probability Letters, 54(4), 437-447.
Yu, K., & Zhang, J. (2005). A three-parameter asymmetric Laplace distribution and its extension. Communications in Statistics-Theory and Methods, 34(9-10), 1867-1879.
See Also
Examples
## Let's compute the log-likelihood for a given sample
y = rALD(n=1000)
loglik = likALD(y)
#Changing the true parameters the loglik must decrease
loglik2 = likALD(y,mu=10,sigma=2,p=0.3)
loglik;loglik2
if(loglik>loglik2){print("First parameters are Better")}
Maximum Likelihood Estimators (MLE) for the Asymmetric Laplace Distribution
Description
Maximum Likelihood Estimators (MLE) for the Three-Parameter Asymmetric Laplace Distribution defined in Koenker and Machado (1999) useful for quantile regression with location parameter equal to mu, scale parameter sigma and skewness parameter p.
Usage
mleALD(y, initial = NA)
Arguments
y |
observation vector. |
initial |
optional vector of initial values c( |
Details
The algorithm computes iteratevely the MLE's via the combination of the MLE expressions for \mu and \sigma, and then maximizing with rescpect to p the Log-likelihood function (likALD) using the well known optimize R function. By default the tolerance is 10^-5 for all parameters.
Value
The function returns a list with two objects
iter |
iterations to reach convergence. |
par |
vector of Maximum Likelihood Estimators. |
Author(s)
Christian E. Galarza <cgalarza88@gmail.com> and Victor H. Lachos <hlachos@ime.unicamp.br>
References
Yu, K., & Zhang, J. (2005). A three-parameter asymmetric Laplace distribution and its extension. Communications in Statistics-Theory and Methods, 34(9-10), 1867-1879.
See Also
Examples
## Let's try this function
param = c(-323,40,0.9)
y = rALD(10000,mu = param[1],sigma = param[2],p = param[3]) #A random sample
res = mleALD(y)
#Comparing
cbind(param,res$par)
#Let's plot
seqq = seq(min(y),max(y),length.out = 1000)
dens = dALD(y=seqq,mu=res$par[1],sigma=res$par[2],p=res$par[3])
hist(y,breaks=50,freq = FALSE,ylim=c(0,max(dens)))
lines(seqq,dens,type="l",lwd=2,col="red",xlab="x",ylab="f(x)", main="ALD Density function")
Moments for the Asymmetric Laplace Distribution
Description
Mean, variance, skewness, kurtosis, central moments w.r.t mu and first absolute central moment for the Three-Parameter Asymmetric Laplace Distribution defined in Koenker and Machado (1999) useful for quantile regression with location parameter equal to mu, scale parameter sigma and skewness parameter p.
Usage
meanALD(mu=0,sigma=1,p=0.5)
varALD(mu=0,sigma=1,p=0.5)
skewALD(mu=0,sigma=1,p=0.5)
kurtALD(mu=0,sigma=1,p=0.5)
momentALD(k=1,mu=0,sigma=1,p=0.5)
absALD(sigma=1,p=0.5)
Arguments
k |
moment number. |
mu |
location parameter |
sigma |
scale parameter |
p |
skewness parameter |
Details
If mu, sigma or p are not specified they assume the default values of 0, 1 and 0.5, respectively, belonging to the Symmetric Standard Laplace Distribution denoted by ALD(0,1,0.5).
As discussed in Koenker and Machado (1999) and Yu and Moyeed (2001) we say that a random variable
Y is distributed as an ALD with location parameter \mu, scale parameter \sigma>0 and skewness parameter p in (0,1), if its probability density function (pdf) is given by
f(y|\mu,\sigma,p)=\frac{p(1-p)}{\sigma}\exp
{-\rho_{p}(\frac{y-\mu}{\sigma})}
where \rho_p(.) is the so called check (or loss) function defined by
\rho_p(u)=u(p - I_{u<0})
,
with I_{.} denoting the usual indicator function. This distribution is denoted by ALD(\mu,\sigma,p) and it's pth quantile is equal to \mu. The scale parameter sigma must be positive and non zero. The skew parameter p must be between zero and one (0<p<1).
Value
meanALD gives the mean, varALD gives the variance, skewALD gives the skewness, kurtALD gives the kurtosis, momentALD gives the kth central moment, i.e., E(y-\mu)^k and absALD gives the first absolute central moment denoted by E|y-\mu|.
Author(s)
Christian E. Galarza <cgalarza88@gmail.com> and Victor H. Lachos <hlachos@ime.unicamp.br>
References
Koenker, R., Machado, J. (1999). Goodness of fit and related inference processes for quantile regression. J. Amer. Statist. Assoc. 94(3):1296-1309.
Yu, K. & Moyeed, R. (2001). Bayesian quantile regression. Statistics & Probability Letters, 54(4), 437-447.
Yu, K., & Zhang, J. (2005). A three-parameter asymmetric Laplace distribution and its extension. Communications in Statistics-Theory and Methods, 34(9-10), 1867-1879.
See Also
Examples
## Let's compute some moments for a Symmetric Standard Laplace Distribution.
#Third raw moment
momentALD(k=3,mu=0,sigma=1,p=0.5)
#The well known mean, variance, skewness and kurtosis
meanALD(mu=0,sigma=1,p=0.5)
varALD(mu=0,sigma=1,p=0.5)
skewALD(mu=0,sigma=1,p=0.5)
kurtALD(mu=0,sigma=1,p=0.5)
# and this guy
absALD(sigma=1,p=0.5)