Title: | 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). 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. |
Authors: | Christian E. Galarza <[email protected]> and Victor H. Lachos <[email protected]> |
Maintainer: | Christian E. Galarza <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.3.1 |
Built: | 2025-01-29 05:38:36 UTC |
Source: | https://github.com/cran/ald |
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.
Package: | ald |
Type: | Package |
Version: | 1.0 |
Date: | 2015-01-27 |
License: | GPL (>=2) |
Christian E. Galarza <[email protected]> and Victor H. Lachos <[email protected]>
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.
## 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")
## 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")
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
.
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)
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)
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 |
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 .
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 , scale parameter
and skewness parameter
in (0,1), if its probability density function (pdf) is given by
where is the so called check (or loss) function defined by
,
with denoting the usual indicator function. This distribution is denoted by
and it's
-th quantile is equal to
.
The scale parameter sigma
must be positive and non zero. The skew parameter p
must be between zero and one (0<p
<1).
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
.
The numerical arguments other than n
are recycled to the length of the result.
Christian E. Galarza <[email protected]> and Victor H. Lachos <[email protected]>
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.
## 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)
## 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 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
.
likALD(y, mu = 0, sigma = 1, p = 0.5, loglik = TRUE)
likALD(y, mu = 0, sigma = 1, p = 0.5, loglik = TRUE)
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. |
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 .
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 , scale parameter
and skewness parameter
in (0,1), if its probability density function (pdf) is given by
where is the so called check (or loss) function defined by
,
with denoting the usual indicator function. Then the Log-likelihood function is given by
.
The scale parameter sigma
must be positive and non zero. The skew parameter p
must be between zero and one (0<p
<1).
likeALD
returns the Log-likelihood by default and just the Likelihood if loglik = FALSE
.
Christian E. Galarza <[email protected]> and Victor H. Lachos <[email protected]>
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.
## 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")}
## 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 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
.
mleALD(y, initial = NA)
mleALD(y, initial = NA)
y |
observation vector. |
initial |
optional vector of initial values c( |
The algorithm computes iteratevely the MLE's via the combination of the MLE expressions for and
, and then maximizing with rescpect to
the Log-likelihood function (
likALD
) using the well known optimize
R function. By default the tolerance is 10^-5 for all parameters.
The function returns a list with two objects
iter |
iterations to reach convergence. |
par |
vector of Maximum Likelihood Estimators. |
Christian E. Galarza <[email protected]> and Victor H. Lachos <[email protected]>
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.
## 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")
## 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")
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
.
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)
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)
k |
moment number. |
mu |
location parameter |
sigma |
scale parameter |
p |
skewness parameter |
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 .
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 , scale parameter
and skewness parameter
in (0,1), if its probability density function (pdf) is given by
where is the so called check (or loss) function defined by
,
with denoting the usual indicator function. This distribution is denoted by
and it's
th quantile is equal to
. The scale parameter
sigma
must be positive and non zero. The skew parameter p
must be between zero and one (0<p
<1).
meanALD
gives the mean, varALD
gives the variance, skewALD
gives the skewness, kurtALD
gives the kurtosis, momentALD
gives the th central moment, i.e.,
and
absALD
gives the first absolute central moment denoted by .
Christian E. Galarza <[email protected]> and Victor H. Lachos <[email protected]>
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.
## 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)
## 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)